public IActionResult ReporteHTML(string NombreReporte, IList <RepParametro> parametros) { FastReport.Utils.Config.WebMode = true; var rep = new WebReport(); var savePath = System.IO.Path.Combine(Startup.entorno.WebRootPath, "Reportes"); var path = $"{savePath}\\{NombreReporte}.frx";//guarda el frm del reporte creado de fast repor rep.Report.Load(path); var str = Resources.JsonStringProvider.GetJson(CultureInfo.CurrentCulture.Name); //idioma rep.Report.Dictionary.Connections[0].ConnectionString = StringProvider.StringGE; rep.Report.Dictionary.Connections[1].ConnectionString = StringProvider.StringEmpresas;// primera conexion rep.Report.Dictionary.Connections[2].ConnectionString = str; foreach (var item in parametros) { rep.Report.SetParameterValue(item.Nombre, item.Valor);// envia por parametro el idempresa a fast report } rep.Report.Prepare(); FastReport.Export.Html.HTMLExport html = new FastReport.Export.Html.HTMLExport(); html.ShowProgress = false; html.SinglePage = true; html.Navigator = false; // Top navigation bar html.EmbedPictures = true; // Embeds images into a document MemoryStream strm = new MemoryStream(); rep.Report.Export(html, strm); rep.Report.Dispose(); html.Dispose(); strm.Position = 0; var res = Encoding.UTF8.GetString(strm.ToArray()); //File(strm.ToArray(), "text/html", $"{NombreReporte}.html"); return(Ok(res)); //using (HTMLExport html = new HTMLExport()) //{ // MemoryStream strm = new MemoryStream(); // rep.Report.Export(html, strm); // return File(strm, "text/html", $"{NombreReporte}.html"); //} }
public static string GetReportString(string reportFilePath, string dataSetName, IEnumerable <object> data, string exportFormat) { FastReport.Report report = new FastReport.Report(); string result = string.Empty; if (FileHelper.IsExistFile(reportFilePath)) { try { report.Load(reportFilePath); // Download the report report.RegisterData(data, dataSetName); // Register data in the report } catch { //var log = LogFactory.GetLogger("FastReportHelper"); //log.Error(ex.Message); return(result); } using (MemoryStream stream = new MemoryStream()) { if (exportFormat.Equals("pdf", StringComparison.InvariantCultureIgnoreCase)) { //FastReport.Export.Pdf.PDFExport pdf = new FastReport.Export.Pdf.PDFExport { // Producer = "", // AllowPrint=true, // AllowModify=true, // PrintScaling=true, // RichTextQuality=100, // Compressed=false //}; //report.Export(pdf, stream); //FileHelper.CreateFile("\\log\\PDF" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg", stream.ToArray()); } else if (exportFormat.Equals("Jpeg", StringComparison.InvariantCultureIgnoreCase)) { FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport { ImageFormat = FastReport.Export.Image.ImageExportFormat.Jpeg, SeparateFiles = false, JpegQuality = 100 }; report.Prepare(); report.Export(image, stream); FileHelper.CreateFile("\\log\\JPG" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg", stream.ToArray()); //foreach (var item in image.GeneratedFiles) //{ // var temp = item; // var log = LogFactory.GetLogger("FastReportHelper"); // log.Info(temp); //} //return report.SaveToStringBase64(); } else if (exportFormat.Equals("Bmp", StringComparison.InvariantCultureIgnoreCase)) { FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport { ImageFormat = FastReport.Export.Image.ImageExportFormat.Bmp }; report.Prepare(); report.Export(image, stream); } else if (exportFormat.Equals("Gif", StringComparison.InvariantCultureIgnoreCase)) { FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport { ImageFormat = FastReport.Export.Image.ImageExportFormat.Gif }; report.Prepare(); report.Export(image, stream); } else if (exportFormat.Equals("Png", StringComparison.InvariantCultureIgnoreCase)) { FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport { ImageFormat = FastReport.Export.Image.ImageExportFormat.Png, SeparateFiles = false }; report.Prepare(); report.Export(image, stream); } else if (exportFormat.Equals("Tiff", StringComparison.InvariantCultureIgnoreCase)) { FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport { ImageFormat = FastReport.Export.Image.ImageExportFormat.Tiff }; report.Prepare(); report.Export(image, stream); } else if (exportFormat.Equals("html", StringComparison.InvariantCultureIgnoreCase)) { FastReport.Export.Html.HTMLExport image = new FastReport.Export.Html.HTMLExport { EnableMargins = false, Pictures = true, EmbedPictures = true, ImageFormat = ImageFormat.Png }; report.Prepare(); report.Export(image, stream); return(System.Text.Encoding.UTF8.GetString(stream.ToArray())); } result = Convert.ToBase64String(stream.ToArray()); } } else { //var log = LogFactory.GetLogger("FastReportHelper"); //log.Error(reportFilePath + ",目录不存在!"); } return(result); }