zoukankan      html  css  js  c++  java
  • NetCore 使用Aspose.Cell把Excel转换成PDF

    NetCore 使用Aspose.Cell把Excel转换成PDF

    引言

    最近工作需要把生成的Excel转换为Pdf文件,网上有几个方案 Spire.XLS 软件收费、转换后文件还可以、但是收费。。。。 其他方案也类似,要么收费、要么转换后格式对 后来无意中发现这个文章使用Aspose可以导出PDF文件

    Aspose也是收费软件, 下载破解版: https://pan.baidu.com/s/1dRwY0mjeIbbAhWQgC3fLSA 提取码: 5eyr

    只需要简单几句代码就可以导出PDF 下载完成后、把DLL文件复制到项目Bin文件夹中 Vs中引用DLL文件 如下图所示 引用完成后

    导出PDF

    ``` private string ExportPDF(string execlPath, string pdfName) { try { Workbook wb = new Workbook(execlPath); foreach (Worksheet item in wb.Worksheets) { item.PageSetup.PaperSize = Aspose.Cells.PaperSizeType.PaperA4; item.PageSetup.Zoom = 98;//打印时页面设置,缩放比例 item.PageSetup.LeftMargin = 0; //左边距为0 item.PageSetup.RightMargin = 0; //右边距为0 item.PageSetup.CenterHorizontally = true;//水平居中 } wb.Save(pdfName, SaveFormat.Pdf); if (System.IO.File.Exists(execlPath)) { System.IO.File.Delete(execlPath); } return pdfName; } catch (Exception ex) { var logger = NLog.LogManager.GetCurrentClassLogger(); logger.Error("BudgetController_ExportPDF:" + ex.Message); throw; }

    }

    <h2>原始Excel截图</h2>
    <img class="alignnone wp-image-251 size-full" src="http://www.netcore.pub/wp-content/uploads/2019/12/20191227154758486_30872.png" alt="" width="755" height="777" />
    <h2>导出PDF截图</h2>
    <img class="alignnone wp-image-252 size-full" src="http://www.netcore.pub/wp-content/uploads/2019/12/20191227154821741_16448.png" alt="" width="870" height="948" />
  • 相关阅读:
    aws centos 基本环境安装
    aws 安装python解释器
    odoo 开发环境部署
    graphql规范
    python 字符串format使用
    设计模式
    集合的常见操作
    字典常见操作
    python实现简单的购物车
    python实现简单的登录管理
  • 原文地址:https://www.cnblogs.com/Zenderblogs/p/12107874.html
Copyright © 2011-2022 走看看