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 }