123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using Aspose.Cells;
- using Bowin.Common.Utility;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Security.Cryptography;
- using System.Text;
- namespace Bowin.Common.Office
- {
- public static class ExcelToPDF
- {
- public static MemoryStream Export(Stream excelStream)
- {
- Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
- Workbook wb = new Workbook(excelStream, new LoadOptions(LoadFormat.Auto));
- var pdfStream = new MemoryStream();
- wb.Save(pdfStream, new PdfSaveOptions(SaveFormat.Pdf) {
- });
- return pdfStream;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="excelStream"></param>
- /// <param name="filePath">相对路径</param>
- /// <returns></returns>
- public static string ExportToFile(MemoryStream excelStream, string filePath)
- {
- Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
- var pdfFileName = Guid.NewGuid().ToString() + ".pdf";
- var fullPath = filePath + (!filePath.EndsWith("/") ? "/" : "") + pdfFileName;
- var physicalFullPath = HttpHelper.MapPath(fullPath);
- Workbook wb = new Workbook(excelStream, new LoadOptions(LoadFormat.Auto));
- wb.Save(physicalFullPath, SaveFormat.Pdf);
- return fullPath;
- }
- }
- }
|