Example #1
0
        public string GenerateReportPdf(Guid rptId, Guid companyId)
        {
            var currentRptInfo = rptInformationService.GetCurrentRptInformation(rptId);
            var filePath       = Path.Combine(Report.AutoGenerate.Service.AppSettings.GetValue("xlsSaveDirectory"), currentRptInfo.RptPath);

            if (!System.IO.File.Exists(filePath))
            {
                throw new NullReferenceException("The report file does not exist");
            }
            var       startTime = GetStartTime((RptTypeEnum)currentRptInfo.RptType);
            IWorkbook workbook  = GetExportWorkBook(filePath, (int)currentRptInfo.RptType, "2", startTime, startTime, false, companyId);

            if (workbook == null)
            {
                throw new NullReferenceException("the workbook is null");
            }
            ReplaceSensitiveDataToEmpty(workbook);
            MemoryStream mStream = new MemoryStream();

            workbook.Write(mStream);
            mStream.Flush();
            workbook.Close();
            mStream.Close();
            return(CommHelper.ConvertXlsToPdf(mStream, companyId.ToString(), currentRptInfo.Name));
        }