我需要将word文档转换为HTML。我可以使用doc
文件
但是当我使用docx
作为输入时。我收到了错误
这是我的代码
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;
}