Aspose.Cells: excel 转 pdf
引用:Aspose.Cells
using System; using System.IO; namespace WIMI.BTL.ExcelToPdf { public class ExcelToPdfUtil { private const string QualityReportPath = @"D:\a\"; public static void QualityReportExcelToPdf(FileDto file) { var excelPath = QualityReportPath + file.FileName; if (!File.Exists(excelPath)) { throw new Exception($"未能找到文件"); } var pdfDirectory = QualityReportPath; if (!Directory.Exists(pdfDirectory)) { Directory.CreateDirectory(pdfDirectory); } var pdfPath = QualityReportPath + file.FileName.Split('.')[0] + ".pdf"; if (File.Exists(pdfPath)) { File.Delete(pdfPath); } Aspose.Cells.Workbook excel = new Aspose.Cells.Workbook(excelPath); excel.Settings.MemorySetting = Aspose.Cells.MemorySetting.MemoryPreference; excel.Settings.AutoCompressPictures = true; excel.Settings.EnableMacros = false; Aspose.Cells.PdfSaveOptions saveOptions = new Aspose.Cells.PdfSaveOptions(Aspose.Cells.SaveFormat.Pdf); saveOptions.AllColumnsInOnePagePerSheet = true; //是否单页 saveOptions.OnePagePerSheet = false; saveOptions.PdfCompression = Aspose.Cells.Rendering.PdfCompressionCore.Flate; saveOptions.PrintingPageType = Aspose.Cells.PrintingPageType.IgnoreBlank; excel.Save(pdfPath, saveOptions); } } public class FileDto { public FileDto() { } public FileDto(string fileName, string fileType) { FileName = fileName; FileType = fileType; FileToken = Guid.NewGuid().ToString("N"); } public string FileName { get; set; } public string FileToken { get; set; } public string FileType { get; set; } } }
Newd
版权声明
作者:も不秃不秃
地址:https://www.cnblogs.com/Newd/p/13272359.html
© Newd 尊重知识产权,引用请注出处
广告位
(虚位以待,如有需要请私信)