【问题标题】:How to use Stimulsoft Report for C# and Excel file importing in gridview?如何使用 Stimulsoft Report 在 gridview 中导入 C# 和 Excel 文件?
【发布时间】:2018-04-17 16:57:58
【问题描述】:

我创建了一个应用程序,它加载一张 Excel 文件并在 gridview 中显示其内容。我只想使用 Stimulsoft Report 为所有记录创建报告并将其导出为 PDF 文件。我该怎么做?

【问题讨论】:

    标签: c# report stimulsoft


    【解决方案1】:

    如果您已经创建了 StimulSoft 报告模板,那么您可以参考下面的代码来填充和注册您的数据并显示/导出。

    public void CreateStimulSoftReport()
        {
            StiReport stReport = new StiReport();
    
            //If Template has already been created then load that template
            stReport.Load("REPORT_MRT_FILE_PATH");
    
            #region Report Data Creation Section
    
            DataSet reportDataSet = new DataSet("ReportDataSet");
    
            DataTable table = new System.Data.DataTable();
            table.TableName = "TABLE_NAME";
            table.Columns.Add(new DataColumn("Col1", typeof(int)));
            table.Columns.Add(new DataColumn("Col2", typeof(string)));
            table.Columns.Add(new DataColumn("Col3", typeof(string)));
            table.Columns.Add(new DataColumn("Col4", typeof(string)));
    
            //Fill Data in Table
            //Here GRID_VIEW_DATA_ITEMS is your ObservableCollection or any collection that is bound to your DataGrid
            foreach (GRID_VIEW_DATA_ITEM item in GRID_VIEW_DATA_ITEMS)
            {
                DataRow dr = table.NewRow();
                dr["Col1"] = item.VAL1;
                dr["Col2"] = item.VAL2;
                dr["Col3"] = item.VAL3;
                dr["Col4"] = item.VAL4;
                table.Rows.Add(dr);
            }
    
            reportDataSet.Tables.Add(table.Copy());
    
            #endregion
    
            //Register Report Dataset with Stimulsoft Report
            stReport.RegData(reportDataSet);
            stReport.Dictionary.Synchronize();
    
            //Display the Report and Save to any format from the Stimulsoft Report Viewer Window
            stReport.ShowWithWpf(); //For WPF application. Use customReport.Show() method for WinForms
    
            //If want to directly export to pdf file without displaying, then use below code.
            string exportFilename = "SOME_FILE_NAME_WITH_PATH";
            Stimulsoft.Report.Export.StiExportSettings exportSettings;
            exportSettings = new Stimulsoft.Report.Export.StiPdfExportSettings();
            ((Stimulsoft.Report.Export.StiPdfExportSettings)exportSettings).ImageQuality = 100;
            ((Stimulsoft.Report.Export.StiPdfExportSettings)exportSettings).ImageResolution = 500;
            ((Stimulsoft.Report.Export.StiPdfExportSettings)exportSettings).Compressed = false;
            stReport.ExportDocument(StiExportFormat.Pdf, exportFilename, exportSettings);
        }
    

    【讨论】:

      猜你喜欢
      • 2011-05-19
      • 2011-07-30
      • 1970-01-01
      • 2019-02-18
      • 1970-01-01
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多