zoukankan      html  css  js  c++  java
  • office转换为html在线预览

            /// <summary>
            ///  word 转换为html
            /// </summary>
            /// <param name="path">要转换的文档的路径</param>
            /// <param name="savePath">转换成的html的保存路径</param>
            /// <param name="wordFileName">转换后html文件的名字</param>
            private  void WordToHtml(string path, string savePath, string wordFileName)
            {
                Word.ApplicationClass word = new Word.ApplicationClass();
                Type wordType = word.GetType();
                Word.Documents docs = word.Documents;
                Type docsType = docs.GetType();
                Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {(object)path, true, true });
                Type docType = doc.GetType();
                string strSaveFileName = savePath + wordFileName + ".html";
                object saveFileName = (object)strSaveFileName;
                docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
                docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
                wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
            }
    
             /// <summary>
             /// excel 转换为html
           /// </summary>
           /// <param name="path">要转换的文档的路径</param>
           /// <param name="savePath">转换成的html的保存路径</param>
           /// <param name="wordFileName">转换后html文件的名字</param>
             public static void ExcelToHtml(string path, string savePath, string wordFileName)
             {
                 string str = string.Empty;
                 Microsoft.Office.Interop.Excel.Application repExcel = new Microsoft.Office.Interop.Excel.Application();
                 Microsoft.Office.Interop.Excel.Workbook workbook = null;
                 Microsoft.Office.Interop.Excel.Worksheet worksheet = null;
                 workbook = repExcel.Application.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                 worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];
                 object htmlFile = savePath + wordFileName + ".html";
                 object ofmt = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
                 workbook.SaveAs(htmlFile, ofmt, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                 object osave = false;
                 workbook.Close(osave, Type.Missing, Type.Missing);
                 repExcel.Quit();
             }
    
            /// <summary>
          /// ppt转换为html
          /// </summary>
          /// <param name="path">要转换的文档的路径</param>
          /// <param name="savePath">转换成的html的保存路径</param>
          /// <param name="wordFileName">转换后html文件的名字</param>
            public static void PPTToHtml(string path, string savePath, string wordFileName)
            {
                Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
                string strSourceFile = path;
                string strDestinationFile = savePath + wordFileName + ".html";
                Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(strSourceFile, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                prsPres.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue);
                prsPres.Close();
                ppApp.Quit();
            }

  • 相关阅读:
    NHibernate初学二之简单执行SQL及HQL、Linq
    Socket通信常用方法
    Android中自定义属性的使用
    四种常见的 POST 提交数据方式
    关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related
    1、memcache的守护进程启动方式(2017-8-10)
    c++封装简单日志操作
    关于vector的内存释放
    Linux进程通信-共享内存
    Linux进程通信总结
  • 原文地址:https://www.cnblogs.com/letnet/p/8525100.html
Copyright © 2011-2022 走看看