FastReport C# 导出


Report report = new Report();
var frxfile = HttpContext.Current.Server.MapPath(StaticPathEnum.UserResRoot + filePath);
report.Load(frxfile);
report.RegisterData(ds, "Data");
var p = report.Prepare(true);

if (p)
{
    var xlsFileName = taskNo + "-" + DateTime.Now.ToString("HH-mm-ss") + ".xlsx";
     SavePrintXlsBakFile(xlsFileName, report);
}

导出Excel

        private static void SavePrintXlsBakFile(string xlsFileName, Report report)
        {
            FastReport.Export.OoXML.Excel2007Export xlsExport = new FastReport.Export.OoXML.Excel2007Export();
            xlsExport.ShowProgress = false;

            MemoryStream strm = new MemoryStream();
            report.Export(xlsExport, strm);

            strm.Position = 0;

            var xlsFilePath = HttpContext.Current.Server.MapPath(StaticPathEnum.PrintXlsBakPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd"));
            if (!Directory.Exists(xlsFilePath))
            {
                Directory.CreateDirectory(xlsFilePath);
            }
            FileStream fs = new FileStream(xlsFilePath + "\\" + xlsFileName, FileMode.Create);
            strm.WriteTo(fs);
            strm.Close();
            fs.Close();

            xlsExport.Dispose();
            strm.Dispose();
            fs.Dispose();
        }

 PDF

        private static void SavePrintPdfBakFile(string xlsFileName, Report report)
        {
            FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport();
            pdfExport.ShowProgress = false;
            pdfExport.Subject = "Subject";
            pdfExport.Title = System.IO.Path.GetFileNameWithoutExtension(xlsFileName);
            pdfExport.Compressed = true;
            pdfExport.AllowPrint = true;
            pdfExport.EmbeddingFonts = true;

            MemoryStream strm = new MemoryStream();
            report.Export(pdfExport, strm);

            strm.Position = 0;

            var xlsFilePath = HttpContext.Current.Server.MapPath(StaticPathEnum.PrintFileBakPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd"));
            if (!Directory.Exists(xlsFilePath))
            {
                Directory.CreateDirectory(xlsFilePath);
            }
            FileStream fs = new FileStream(xlsFilePath + "\\" + xlsFileName, FileMode.Create);
            strm.WriteTo(fs);
            strm.Close();
            fs.Close();

            pdfExport.Dispose();
            strm.Dispose();
            fs.Dispose();
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM