.NET實現在網頁中預覽Office文件的3個方法(2)_.Net教程
推薦:asp.net中控制反轉怎么理解?對IOC的解釋為:Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers are special because they use inversion of control is like saying my car is special because it has wheels. 我想對這一概念執行
#region 1.02 Excel文件轉換為HTML文件 +(string sourceFileName, string targetFileName, string guid)
/// <summary>
/// Excel文件轉換為HTML文件
/// </summary>
/// <param name="sourceFileName">Excel文件路徑</param>
/// <param name="targetFileName">目標路徑</param>
/// <returns>轉換是否成功</returns>
public static bool ConvertExcelToHtml(string sourceFileName, string targetFileName)
{
Souxuexiao.API.Logger.info(string.Format("準備執行Excel文件轉換為HTML文件,sourceFileName={0},targetFileName={1}",sourceFileName,targetFileName));
try
{
using (System.IO.Stream stream = new System.IO.FileStream(sourceFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
{
Aspose.Cells.Workbook workbook = new Workbook(stream);
workbook.Save(targetFileName, Aspose.Cells.SaveFormat.Html);
}
}
catch (Exception ex)
{
Souxuexiao.API.Logger.error(string.Format("Excel文件轉換為HTML文件ConvertExcelToHtml異常原因是:{0}", ex.Message));
}
return System.IO.File.Exists(targetFileName);
}
#endregion
#region 1.03 將PowerPoint文件轉換為PDF +ConvertPowerPointToPdf(string sourceFileName, string targetFileName)
/// <summary>
/// 將PowerPoint文件轉換為PDF
/// </summary>
/// <param name="sourceFileName">PPT/PPTX文件路徑</param>
/// <param name="targetFileName">目標文件路徑</param>
/// <returns>轉換是否成功</returns>
public static bool ConvertPowerPointToPdf(string sourceFileName, string targetFileName)
{
Souxuexiao.API.Logger.info(string.Format("準備執行PowerPoint轉換PDF,sourceFileName={0},targetFileName={1}",sourceFileName,targetFileName));
try
{
using (System.IO.Stream stream = new System.IO.FileStream(sourceFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
{
Aspose.Slides.Pptx.PresentationEx pptx = new Aspose.Slides.Pptx.PresentationEx(stream);
pptx.Save(targetFileName, Aspose.Slides.Export.SaveFormat.Pdf);
}
}
catch (Exception ex)
{
Souxuexiao.API.Logger.error(string.Format("將PowerPoint文件轉換為PDFConvertExcelToHtml異常原因是:{0}", ex.Message));
}
return System.IO.File.Exists(targetFileName);
}
#endregion
分享:delphi選擇文件夾例子所需單元 示例代碼
- 相關鏈接:
- 教程說明:
.Net教程-.NET實現在網頁中預覽Office文件的3個方法(2)
。