zoukankan      html  css  js  c++  java
  • 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();
            }
  • 相关阅读:
    求一个数字各个位的数字之和
    二进制和十进制的转换 分别用python和js实现
    pymysql 获取插入数据的主键id
    js03.事件
    02.js运算符
    jsonpath
    01.js控制台
    2.命令补充
    hashmap
    正则表达式的补充
  • 原文地址:https://www.cnblogs.com/sky-gfan/p/12034144.html
Copyright © 2011-2022 走看看