Excel在线预览,使用Aspose.cell18.4将服务器存储的Word转换为PDF,再使用PDF.js 进行预览。 baidu网盘提取码:jlie baidu网盘pan.baidu.com/s/1QGFKkBusFIQQouaNWwmK5w
string FilePath = "Excel文件的路径,包括文件名";
string FilePathPdf = "生成PDF文件的路径,包括文件名";
string NewFileNamePdf = "";
string LastNewFileNameletter = xbase.NewFileName.Substring(xbase.NewFileName.Length - 1, 1);
if (LastNewFileNameletter == "x")
{
FilePathPdf = FilePath.Replace(".xlsx", ".pdf");
NewFileNamePdf = xbase.NewFileName.Replace(".xlsx", ".pdf");
}
else
{
FilePathPdf = FilePath.Replace(".xls", ".pdf");
NewFileNamePdf = xbase.NewFileName.Replace(".xls", ".pdf");
}
if (!System.IO.File.Exists(FilePathPdf))
{
var wb = new Workbook(FilePath);
var pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.OnePagePerSheet = true;
wb.Save(FilePathPdf, pdfSaveOptions);
}
string pathsrc = xbase.FileUpLoadPath.Replace("Upload", "");
string FileServerPath = pathsrc.Replace(@"\", @"/") + "/" + NewFileNamePdf;
url= FileOpenPdfPath + FileServerPath;
PDF生成成功后,再使用PDF.js 前端进行预览。