.NET实现在网页中预览Office文件的3个方法(2)

#region 1.02 Excel文件转换为HTML文件 +(string sourceFileName, string targetFileName, string guid)
        /// <summary>
        /// Excel文件转换为HTML文件
        /// </summary>
        /// <param>Excel文件路径</param>
        /// <param>目标路径</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>PPT/PPTX文件路径</param>
        /// <param>目标文件路径</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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzdgf.html