翻譯|使用教程|編輯:李顯亮|2021-09-16 10:29:31.057|閱讀 212 次
概述:此示例顯示如何在運行系統中創建帶有表格的簡單報告。在這個示例項目中,您可以為表設置一些屬性。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
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(); }
在下面的屏幕截圖中,您可以看到示例代碼的結果:
 
 
Aspose、E-iceblue、FastReport、Stimulsoft等文檔/報表圖表類開發工具享超低折扣,如有需要可直接。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn