docx to html [此命令不可用。]

时间:2017-04-24 05:00:45

标签: c# html ms-word interop

我需要将word文档转换为HTML。我可以使用doc文件

来完成

但是当我使用docx作为输入时。我收到了错误

enter image description here

这是我的代码

        public static string DocToHtml(string path)
        {
            try
            {
                //I used Microsoft Interop v12 because this doesn't give me the Access Violation Error.
                Microsoft.Office.Interop.Word.Application _App = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document _Doc = _App.Documents.Open(path);

                //Let's save the converted document to the temp folder
                string tempDocx = System.IO.Path.GetTempPath() + "_tempConvertedToHtml.html";
                object _DocxFileName = tempDocx;
                object FileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML;
                _Doc.Convert();
                _Doc.SaveAs(ref _DocxFileName, ref FileFormat);


                //Close the Word interface
                _Doc.Close();
                _App.Quit();

                path = tempDocx;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
            return path;
        }

0 个答案:

没有答案