• 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 尊重知识产权,引用请注出处

    广告位

    (虚位以待,如有需要请私信)

  • 相关阅读:
    到现在为止中国荣获43金
    php fpdf 生成表格总结
    今天,开心``
    js 浮动层实现方法
    奥运,刘翔,CSDN,菲尔普斯,中国
    marc 数据基本字段
    Windows mobile下获取系统图标
    HTTP协议学习笔记
    UNIX网络编程学习(14)使用select正确处理EOF的str_cli函数修订版
    ARP协议学习笔记
  • 原文地址:https://www.cnblogs.com/Newd/p/13272359.html
Copyright © 2020-2023  润新知