Loading

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" />
posted @ 2019-12-27 16:09  Howe_______ღ  阅读(1063)  评论(0编辑  收藏  举报