如何在SGrid中将Stimulsoft Report用于C#和Excel文件导入? [英] How to use Stimulsoft Report for C# and Excel file importing in gridview?

查看:241
本文介绍了如何在SGrid中将Stimulsoft Report用于C#和Excel文件导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created an app which load a sheet of Excel file and shows its content in gridview. I just want to use Stimulsoft Report to create a report for all records and export it in PDF file. How can I do that ?

推荐答案

如果您已经创建了StimulSoft Report模板,则可以引用以下代码来填充并注册数据并显示/导出.

If you already have the StimulSoft Report template created then you can refer the below code to fill and register your data with it and display/Export.

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);
    }

这篇关于如何在SGrid中将Stimulsoft Report用于C#和Excel文件导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆