zoukankan      html  css  js  c++  java
  • 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 尊重知识产权,引用请注出处

    广告位

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

  • 相关阅读:
    shell 时间循环
    t
    IntelliJ IDEA For Mac 快捷键
    JVM的默认参数
    qt不同模块使用多语言
    cocos2dx 实现gpu instancing
    so so.*.*
    Android开发-解决 AIDL 中找不到couldn't find import for class错误
    Android Watchdog源码简析--Based on Android 6.0.1
    View绘制流程--Based on kitkat
  • 原文地址:https://www.cnblogs.com/Newd/p/13272359.html
Copyright © 2011-2022 走看看