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

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐: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教程/更新时间:2014-10-11
相关.Net教程