如何直接将文件导出到Excel

2020-09-01 09:33发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)你好, 我们可以跳过查看器的显...

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


你好,

我们可以跳过查看器的显示步骤,而直接以PDF或其他格式导出报告文件吗?

非常感谢您!

谢尔顿

4条回答
哎,真难
2020-09-01 09:55

这是不使用查看器的一种导出方式:

私有无效lstExportFormatType_SelectedIndexChanged(对象发送者,EventArgs e)
 {
    //单击导出ENUM时将填充
     字符串ExportTypeSelected = lstExportFormatType.SelectedItem.ToString();

     如果(ExportTypeSelected ==" crReportExportFormatCrystalReports")
     #region RPT
     {
        //这项工作不会改变
        //这将获取报告名称,并将导出名称设置为与扩展名相同的名称
         字符串outputFileName ="";
         字符串MyRptName = rpt.FileName.ToString();
         outputFileName = MyRptName.Substring(9,rpt.FileName.Length-9);
         outputFileName = outputFileName.Substring(0,(outputFileName.Length-4))+" 1.rpt";

         尝试
         {
             如果(File.Exists(outputFileName))
             {
                 File.Delete(outputFileName);
             }

             CrystalDecisions.ReportAppServer.ReportDefModel.RPTExportFormatOptions RasRPTExpOpts = new RPTExportFormatOptions();

             尝试
             {
                 RasRPTExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatCrystalReports);
             }
             抓住(前例外)
             {
                 btnSQLStatement.Text ="错误:" + ex.Message;
                //返回;
             }

            //现在设置它们:
            //RasPDFExpOpts.CreateBookmarksFromGroupTree = false;
            //RasPDFExpOpts.EndPageNumber = 1;
            //RasPDFExpOpts.StartPageNumber = 1;

             CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 =新的CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
             exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatCrystalReports;
             exportOpts1.FormatOptions = RasRPTExpOpts;

            //和导出
             rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName,true);
             MessageBox.Show("导出到RPT已完成。注意:报告为* 1.RPT","",MessageBoxButtons.OK,MessageBoxIcon.Information);

         }
         抓住(前例外)
         {
             btnSQLStatement.Text ="错误:" + ex.Message;
             返回;
         }
        //这项工作不会改变
     }
     #endregion RPT

     如果(ExportTypeSelected ==" crReportExportFormatMSExcel")
     #region MSExcel
     {
        //这项工作不会改变
        //这将获取报告名称,并将导出名称设置为与扩展名相同的名称
         字符串outputFileName ="";
         字符串MyRptName = rpt.FileName.ToString();
         outputFileName = MyRptName.Substring(9,rpt.FileName.Length-9);
         outputFileName = outputFileName.Substring(0,(outputFileName.Length-3))+" xls";

         尝试
         {
             如果(File.Exists(outputFileName))
             {
                 File.Delete(outputFileName);
             }

             CrystalDecisions.ReportAppServer.ReportDefModel.ExcelExportFormatOptions RasXLSExpOpts = new ExcelExportFormatOptions();
             RasXLSExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatMSExcel);
            //textBox1 =" Excel-BaseAreaGroupNumber:" + RasXLSExpOpts.BaseAreaGroupNumber.ToString()+" \ n";
            //textBox1 + =" Excel-BaseAreaType:" + RasXLSExpOpts.BaseAreaType.ToString()+" \ n";
            //textBox1 + =" Excel-FormulaExportPageAreaType:" + RasXLSExpOpts.ExportPageAreaPairType.ToString()+" \ n";
            //textBox1 + =" Excel-ExportPageBreaks:" + RasXLSExpOpts.ExportPageBreaks.ToString()+" \ n";
            //textBox1 + =" Excel-ConstantColWidth:" + RasXLSExpOpts.ConstantColWidth.ToString()+" \ n";
            //textBox1 + =" Excel-ConvertDatesToStrings:" + RasXLSExpOpts.ConvertDatesToStrings.ToString()+" \ n";
            //textBox1 + =" Excel-StartPageNumber:" + RasXLSExpOpts.StartPageNumber.ToString()+" \ n";
            //textBox1 + =" Excel-EndPageNumber:" + RasXLSExpOpts.EndPageNumber.ToString()+" \ n";
            //textBox1 + =" Excel-ExportPageBreaks:" + RasXLSExpOpts.ExportPageBreaks.ToString()+" \ n";
            //textBox1 + =" Excel-MRelativeObjectPosition:" + RasXLSExpOpts.MaintainRelativeObjectPosition.ToString()+" \ n";
            //textBox1 + =" Excel-ShowGridlines:" + RasXLSExpOpts.ShowGridlines.ToString()+" \ n";
            //textBox1 + =" Excel-UseConstantColWidth:" + RasXLSExpOpts.UseConstantColWidth.ToString()+" \ n";
             btnReportObjects.Text + =" Excel-ExcelTabHasColumnHeadings:" + RasXLSExpOpts.ExcelTabHasColumnHeadings +" \ n";

            //现在设置它们:
            //RasXLSExpOpts.BaseAreaType = CrAreaSectionKindEnum.crAreaSectionKindPageHeader;
            //RasXLSExpOpts.UseConstantColWidth = false;
            //RasXLSExpOpts.ShowGridlines = false;
            //RasXLSExpOpts.StartPageNumber = 3;
            //RasXLSExpOpts.EndPageNumber = 10;
             RasXLSExpOpts.ExcelTabHasColumnHeadings = true;

            //保存修改后的信息
             rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatMSExcel,RasXLSExpOpts);

             CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 =新的CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
             exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatMSExcel;
             exportOpts1.FormatOptions = RasXLSExpOpts;

            //显示开始时间
             DateTime dtStart;
             时间跨度差异;
             dtStart = DateTime.Now;
             btnReportObjects.Text + ="报表导出已开始:" + dtStart +" \ r \ n";
            //和导出
             rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName,true);
             差异= DateTime.Now.Subtract(dtStart);
             btnReportObjects.Text + ="报告导出完成于:" + Difference.Minutes.ToString()+":" + Difference.Seconds.ToString()+" \ r \ n";
             MessageBox.Show("导出到Excel已完成","",MessageBoxButtons.OK,MessageBoxIcon.Information);

         }
         抓住(前例外)
         {
             btnSQLStatement.Text ="错误:" + ex.Message;
             返回;
         }
        //这项工作不会改变
     }
     #endregion MSExcel 

Don

一周热门 更多>