報表生成器FastReport.Net常見問題解答

FastReport .Net是適用於Windows Forms,ASP.NET,MVC和.NET Core的全功能報表解決方案。它能夠在Microsoft Visual Studio 2005-2019中使用。支持.Net Framework 2.0-4.x,.NET Core 3.0及以上版本。html

在FastReport .NET 2021.1的新版本中,咱們實現了對.NET 5的支持。添加了新條形碼-Deutsce Post Leitcode。將RTF轉換爲報告對象的算法已獲得顯着改進。而且還添加了用於轉換數字的新功能。歡迎下載體驗。(點擊下方按鈕下載)git

當即點擊下載FastReport.NET v2021.1最新版算法

Fastreport.NET在線購買價更低,專享85折起!趕忙加入購物清單吧!express

1.如何在WPF應用程序中使用FastReport.Net控件?編程

您應該爲此使用WindowsFormsHost控件:url

0)在FastReport.dll上添加引用;spa

1)若是要使用PreviewControl,則將屬性添加到Window(Page)標記中:xmlns:fr =「 clr-namespace:FastReport.Preview; assembly = FastReport」,xmlns:fr1 =「 clr-namespace:FastReport.Design; assembly = FastReport」-if DesignerControl;.net

2)將WindowsFormsHost標記添加到您的XAML標記中:code

<WindowsFormsHost HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" Grid.ColumnSpan="3">
</WindowsFormsHost>

 3)將子級添加到WindowsFormsHost中:<fr:PreviewControl> </ fr:PreviewControl>或<fr1:Designer> </ fr1:Designer>。orm

完整的標記應以下所示:

<Window
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 x:Class="WpfApplication1.MainWindow"
 Title="MainWindow" Height="375.977" Width="939.258"
 xmlns:fr="clr-namespace:FastReport.Preview;assembly=FastReport">
 <Grid>
 <Grid.ColumnDefinitions>
 <ColumnDefinition Width="*"/>
 <ColumnDefinition Width="*"/>
 <ColumnDefinition Width="*"/>
 </Grid.ColumnDefinitions>
 <WindowsFormsHost HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" Grid.ColumnSpan="3">
 <fr:PreviewControl></fr:PreviewControl>
 </WindowsFormsHost>
 </Grid>
</Window>

2.如何以編程方式設置Format的值?

您能夠使用如下代碼在腳本或項目中執行此操做:

FastReport.Format.NumberFormat format = new FastReport.Format.NumberFormat();
format.UseLocale = false;
format.DecimalDigits = 2;
format.DecimalSeparator = ".";
format.GroupSeparator = ",";

而後:

textObject.Formats.Clear();
textObject.Formats.Add(format);

3.如何在MSChartObject中建立帶有間隙的行?

您應該建立基本的System.Windows.Forms.DataVisualization.Charting.Series對象,並在此處建立行。以後,應爲MSChartObject基本圖表分配建立的系列(MSChart1.Chart.Series.Add(series);)不要忘記在「報表」->「腳本」菜單和命名空間System.Windows.Forms中添加 System.Windows.Forms.DataVisualization.dll。 .DataVisualization.Charting。

帶有間隙的線的示例:

.
.
using System.Windows.Forms.DataVisualization.Charting;
 
namespace FastReport
{
 public class ReportScript
 {
 private void MSChart1_BeforePrint(object sender, EventArgs e)
 { 
 Series series = new Series("sample");
 series.ChartType = SeriesChartType.Line;
 series.BorderWidth = 2;
 series.MarkerSize = 5;
 
 series.Points.Add(new DataPoint(0, 1));
 series.Points.Add(new DataPoint(1, 2));
 DataPoint dp = new DataPoint(2, double.NaN);
 dp.IsEmpty = true;
 series.Points.Add(dp);
 series.Points.Add(new DataPoint(3, 5));
 series.Points.Add(new DataPoint(4, 8)); 
 
 MSChart1.Chart.Series.Add(series);
 
 }
 }
}

結果:

差距线

4.如何從代碼建立MSChartObject?

1.建立新的MSChart對象,設置寬度,高度和圖例:

MSChartObject MSChart1 = new MSChartObject();
 MSChart1.Width = 300;
 MSChart1.Height = 300;
 MSChart1.Chart.Legends.Add(new Legend() { Name = "Legend1", Title="Legend title"});

 2.建立ChartArea對象,設置名稱,軸標題,並將建立的ChartArea分配給MSChart:

ChartArea chartArea1 = new ChartArea();
 chartArea1.Name = "ChartArea1";
 chartArea1.Axes[0].Title = "X name";
 chartArea1.Axes[1].Title = "Y name";
 MSChart1.Chart.ChartAreas.Add(chartArea1);

3.建立系列對象,設置圖表類型,邊框寬度,添加點並將系列分配給圖表:

Series series = new Series("sample");
 series.ChartType = SeriesChartType.Line;
 series.BorderWidth = 2;
 series.Points.Add(new DataPoint(0, 1));
 series.Points.Add(new DataPoint(1, 2));
 series.Points.Add(new DataPoint(3, 5));
 series.Points.Add(new DataPoint(4, 8));
 
 MSChart1.Chart.Series.Add(series);

 4.將建立的MSChart分配給DataBand:

Report report = new Report();
report.Load("ok.frx");
DataBand db = report.FindObject("Data1") as DataBand;
 
MSChart1.Parent = db;

完整的代碼段:

MSChartObject MSChart1 = new MSChartObject();
 MSChart1.Width = 300;
 MSChart1.Height = 300;
 MSChart1.Chart.Legends.Add(new Legend() { Name = "Legend1", Title="Legend title"});
 
 ChartArea chartArea1 = new ChartArea();
 chartArea1.Name = "ChartArea1";
 chartArea1.Axes[0].Title = "X name";
 chartArea1.Axes[1].Title = "Y name";
 MSChart1.Chart.ChartAreas.Add(chartArea1); 
 
 Series series = new Series("sample");
 series.ChartType = SeriesChartType.Line;
 series.BorderWidth = 2;
 series.Points.Add(new DataPoint(0, 1));
 series.Points.Add(new DataPoint(1, 2));
 series.Points.Add(new DataPoint(3, 5));
 series.Points.Add(new DataPoint(4, 8));
 
 MSChart1.Chart.Series.Add(series);
 
 Report report = new Report();
 report.Load("ok.frx");
 DataBand db = report.FindObject("Data1") as DataBand;
 MSChart1.Parent = db;

 結果:

图表

還想要更多嗎?您能夠點擊閱讀【FastReport 報表2020最新資源盤點】查找須要的教程資源。讓人興奮的是FastReport .NET正在慧都網火熱銷售中!慧都17週年慶惠享超低折扣,低至3701元起!>>查看價格詳情

相關文章
相關標籤/搜索