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();
            }
  • 相关阅读:
    nginx 配置文件简介
    nginx 二进制安装
    nginx 简介  http://nginx.org
    全栈https
    运维工程师如果将web服务http专变为https
    12个JQuery小贴士
    AccessHelper 需修改
    MysqlHelper 需要重写
    Func<T,TResult>泛型委托
    DataConvertJson
  • 原文地址:https://www.cnblogs.com/sky-gfan/p/12034144.html
Copyright © 2011-2022 走看看