C# 如何在StimulReport中显示从DataGridView筛选的数据?
如何将从DataGridView筛选的数据显示到StimulReport中 我测试了以下代码:C# 如何在StimulReport中显示从DataGridView筛选的数据?,c#,stimulsoft,C#,Stimulsoft,如何将从DataGridView筛选的数据显示到StimulReport中 我测试了以下代码: public void CreateStimulSoftReport() { System.Diagnostics.Debug.WriteLine("CreateStimulSoftReport ..."); StiReport stReport = new StiReport(); //If Template has already been creat
public void CreateStimulSoftReport()
{
System.Diagnostics.Debug.WriteLine("CreateStimulSoftReport ...");
StiReport stReport = new StiReport();
//If Template has already been created then load that template
stReport.Load(@"C:\Tools\Test\ReportExcel.mrt");
stReport.Compile();
#region Report Data Creation Section
DataSet dataSet = new DataSet("DS1");
System.Data.DataTable table = new System.Data.DataTable("Demo");
table.TableName = "DataBand1";
table.Columns.Add(new DataColumn("id", typeof(int)));
table.Columns.Add(new DataColumn("tel_usage_new", typeof(string)));
table.Columns.Add(new DataColumn("tel_usage_former", typeof(string)));
table.Columns.Add(new DataColumn("terminal_cable30", typeof(string)));
table.Columns.Add(new DataColumn("terminal_cable40", typeof(string)));
table.Columns.Add(new DataColumn("terminal_voip_u6", typeof(string)));
table.Columns.Add(new DataColumn("terminal_cable40_u47", typeof(string)));
table.Columns.Add(new DataColumn("description", typeof(string)));
//Fill Data in Table
//Here GRID_VIEW_DATA_ITEMS is your ObservableCollection or any collection that is bound to your DataGrid
foreach (DataGridViewRow row in dataGridView1.Rows)
{
System.Diagnostics.Debug.WriteLine("CreateStimulSoftReport ID : " + row.Cells[0].Value.ToString());
DataRow dr = table.NewRow();
dr["id"] = row.Cells[0].Value.ToString();
dr["tel_usage_new" ] = row.Cells[1].Value.ToString();
dr["tel_usage_former"] = row.Cells[2].Value.ToString();
dr["terminal_cable30"] = row.Cells[3].Value.ToString();
dr["terminal_cable40"] = row.Cells[4].Value.ToString();
dr["terminal_voip_u6"] = row.Cells[5].Value.ToString();
dr["terminal_cable40_u47"] = row.Cells[6].Value.ToString();
dr["description"] = row.Cells[7].Value.ToString();
System.Diagnostics.Debug.WriteLine("CreateStimulSoftReport tel_usage_new : " + dr["tel_usage_new"]);
table.Rows.Add(dr);
}
System.Diagnostics.Debug.WriteLine("Create StimulSoftReport table Rows : " + table.Rows.Count);
dataSet.Tables.Add(table.Copy());
System.Diagnostics.Debug.WriteLine("CreateStimulSoftReport dataSet tables : " + dataSet.Tables.Count);
#endregion
//Register Report Dataset with Stimulsoft Report
stReport.RegData("DS1", "DS1", dataSet);
stReport["date_time"] = DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss dddd");
stReport.Dictionary.Synchronize();
stReport.Render();
stReport.Show();
}
但它会显示一个空白的报告页。1-您必须在报告中使用数据带
2-数据带必须与DS1一起分配
3-在RegData之前写下:
stReport.Tables[0].TableName = "DS1";
stReport.Namespace = "DS1";
stReport.DataSources.Clear();
stReport.Dictionary.DataSources.Clear();
4-如果您需要变量“日期\时间”,请在报告中创建变量并使用设置值
stReport.Dictionary.Variables["date_time"].Value = DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss dddd");