Stimulsoft Reports.Net示例演示:WinForms 类别中在运行时使用表创建新报告

发布时间 : 2021-09-16 10:29:31.057|阅读 108 次

概述:此示例显示如何在运行系统中创建带有表格的简单报告。在这个示例项目中,您可以为表设置一些属性。

相关链接:

Stimulsoft Ultimate是用于创建报表和仪表板的通用工具集。该产品包括用于WinForms、ASP.NET、.NET Core、JavaScript、WPF、PHP、Java和其他环境的完整工具集。

Stimulsoft Reports不仅拥有强大的报表导出系统,而且还支持多种报表导出格式,拥有简单且强大的报表引擎。Stimulsoft Reports基本原则是,用简单常规的方法创建报表,将不同的技术应用于应用程序。Stimulsoft Reports ..NET一个基于.NET框架的报表生成器,能够帮助你创建结构、功能丰富的报表。不仅界面友好,而且使用便捷,能够让你轻松创建所有报表。

点击下载Stimulsoft Reports .NET v2021.3.1最新版

此示例显示如何在运行系统中创建带有表格的简单报告。在这个示例项目中,您可以为表设置一些属性。使用表格组件,您可以创建一个带有标题和总计而没有其他波段的报告。在这种情况下,某些表格行将成为数据的页眉和页脚。首先,创建一个新报告并连接到数据:

private void PrintDataGrid(DataGrid sender)
{
	DataView dataView = (DataView)sender.DataSource;
	StiReport report = new StiReport();
	report.ScriptLanguage = StiReportLanguageType.CSharp;
	
	// Add data to datastore
	report.RegData("view", dataView);
	
	// Fill dictionary
	report.Dictionary.Synchronize();

...

接下来,在报表页面添加 Table 组件:

...

	StiPage page = report.Pages.Items[0];
	
	// Create Table
	StiTable table = new StiTable();
	table.Name = "Table1";
	if (rbAWNone.Checked)
		table.AutoWidth = StiTableAutoWidth.None;
	else if (rbAWPage.Checked)
		table.AutoWidth = StiTableAutoWidth.Page;
	else
	table.AutoWidth = StiTableAutoWidth.Table;
	
	if (rbAWTNone.Checked)
		table.AutoWidthType = StiTableAutoWidthType.None;
	else if (rbAWTFullTable.Checked)
		table.AutoWidthType = StiTableAutoWidthType.FullTable;
	else table.AutoWidthType = StiTableAutoWidthType.LastColumns;

...

接下来,在表中定义一些列和行:

...

	table.ColumnCount = 3;
	table.RowCount = 3;

...

接下来,定义表中Header的行数和Footer的行数:

...

	table.HeaderRowsCount = 1;
	table.FooterRowsCount = 1;

...

接下来,定义 Table 组件的其他选项:

...

	table.Width = page.Width;
	table.Height = page.GridSize * 12;
	table.DataSourceName = "view" + dataView.Table.TableName;
	page.Components.Add(table);
	table.CreateCell();
	table.TableStyleFX = new StiTable27StyleFX();
	table.TableStyle = Stimulsoft.Report.Components.Table.StiTableStyle.Style59;
	
	int indexHeaderCell = 0;
	int indexDataCell = 3;

...

接下来,添加标题文本和对单元格中数据字段的引用:

...

	foreach (DataColumn column in dataView.Table.Columns)
	{
		// Set text on header
		StiTableCell headerCell = table.Components[indexHeaderCell] as StiTableCell;
		headerCell.Text.Value = column.Caption;
		headerCell.HorAlignment = StiTextHorAlignment.Center;
		headerCell.VertAlignment = StiVertAlignment.Center;
		
		StiTableCell dataCell = table.Components[indexDataCell] as StiTableCell;
		dataCell.Text.Value = "{view" + dataView.Table.TableName + "." +
			Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(column.ColumnName) + "}";
		dataCell.Border = new StiBorder(StiBorderSides.All, Color.FromArgb(32, 178, 170), 1, StiPenStyle.Dash);
		
		indexHeaderCell++;
		indexDataCell++;
	}
	
	StiTableCell dataCheckBoxCell = table.Components[indexDataCell - 1] as StiTableCell;
	dataCheckBoxCell.CellType = StiTablceCellType.CheckBox;

...

接下来,在单元格中添加一个 total 函数:

...

	// Set text on footer
	StiTableCell footerCell = table.Components[table.Components.Count - 1] as StiTableCell;
	footerCell.Text.Value = "Count - {Count()}";
	footerCell.Font = new Font("Arial", 15, FontStyle.Bold);
	footerCell.VertAlignment = StiVertAlignment.Center;
	footerCell.HorAlignment = StiTextHorAlignment.Center;

...

最后,渲染报告并在查看器中显示:

...

	// Render without progress bar
	report.Render(false);
	report.Show();
}

在下面的屏幕截图中,您可以看到示例代码的结果:

Stimulsoft Reports.Net示例演示:在WinForms 类别中在运行系统中创建一个简单的报告

Aspose、E-iceblue、FastReport、Stimulsoft等文档/报表图表类开发工具享超低折扣,如有需要可直接联系在线客服


在线
客服
微信
QQ 电话
023-68661681
返回
顶部