用Aspose.Cells把Excel文件转成PDF

Aspose.Cells版本:21.10.0

 1 [HttpPost]
 2 [Route("api/report/ConvertExcelToPDF")]
 3 public HttpResponseMessage ConvertExcelToPDF(string excelPath)
 4 {
 5     try
 6     {
 7         var licensePath = @"C:\Aspose.Total.lic";
 8         var license = new License();
 9         license.SetLicense(licensePath);
10         var wb = new Workbook(excelPath);
11 
12         var pdfPath = Path.ChangeExtension(excelPath, ".pdf");
13         var pdfSaveOptions = new PdfSaveOptions();
14         pdfSaveOptions.OnePagePerSheet = true;
15         //pdfSaveOptions.AllColumnsInOnePagePerSheet = true;
16 
17         wb.Save(pdfPath, pdfSaveOptions);
18 
19         return new HttpResponseMessage()
20         {
21             Content = new StringContent(pdfPath, Encoding.UTF8)
22         };
23     }
24     catch (Exception ex)
25     {
26         LogManager.Logger.Error(ex);
27         return new HttpResponseMessage()
28         {
29             Content = new StringContent(ex.Message, Encoding.UTF8)
30         };
31     }
32 }

 

posted @ 2021-10-22 10:20  ㄌㄟ  阅读(1024)  评论(0编辑  收藏  举报