Esempio n. 1
0
        protected ActionResult ViewReport(FlexCel.Core.ExcelFile xls, string fileName, bool exportExcel = false)
        {
            try
            {
                if (exportExcel)
                {
                    if (xls == null)
                    {
                        return(ExportExcelNotData());
                    }

                    var clsResult = new Models.Excel.clsExcelResult();
                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                    {
                        xls.Save(ms);
                        ms.Position        = 0;
                        clsResult.ms       = ms;
                        clsResult.FileName = fileName;
                        clsResult.type     = "xls";
                        return(clsResult);
                    }
                }
                else
                {
                    if (xls == null)
                    {
                        xls = ExportExcelError("Không có giá trị");
                    }

                    using (FlexCel.Render.FlexCelPdfExport pdf = new FlexCel.Render.FlexCelPdfExport())
                    {
                        pdf.Workbook = xls;
                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                        {
                            pdf.BeginExport(ms);
                            pdf.ExportAllVisibleSheets(false, "PDF");
                            pdf.EndExport();
                            ms.Position = 0;
                            return(File(ms.ToArray(), "application/pdf"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"{DateTime.Now.ToString("HH:mm:ss dd/MM/yyyy")} ViewReport {ex.Message} {JsonConvert.SerializeObject(ex)}");
                return(null);
            }
        }
Esempio n. 2
0
 private void CreateFile(FlexCel.Core.ExcelFile xls, string aCaminhoTemplate)
 {
     xls.Open(aCaminhoTemplate); //Open an existing xls file for modification.
     xls.ActiveSheet = 1;        //Set the sheet we are working in.
 }