如何将过滤后的数据从DataGridView显示到刺激报告中



如何将DataGridView中的过滤数据显示到StimulReport中?

我测试了以下代码:

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:ToolsTestReportExcel.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-您必须在报表中使用DataBand
2-DataBand必须分配DS1
3-在RegData:之前写入

stReport.Tables[0].TableName = "DS1";
stReport.Namespace = "DS1";
stReport.DataSources.Clear();
stReport.Dictionary.DataSources.Clear();

4-如果您需要变量"0";date_time;在报表中创建变量并使用设置值

stReport.Dictionary.Variables["date_time"].Value = DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss dddd");

最新更新