I'd like to extract the content of a MS Word 2003 document into HTML in C#.
Any ideas?
I'd like to extract the content of a MS Word 2003 document into HTML in C#.
Any ideas?
I think this is the easiest way to do it
http://asptutorials.net/C-SHARP/convert-ms-word-docs-to-html/
They key point in the article is that they use the SaveAs function http://msdn.microsoft.com/en-us/library/aa220734.aspx
Like this:
string newfilename = folder_to_save_in + FileUpload1.FileName.Replace(".doc", ".html");
object o_nullobject = System.Reflection.Missing.Value;
object o_newfilename = newfilename;
object o_format = Word.WdSaveFormat.wdFormatHTML;
object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
object o_endings = Word.WdLineEndingType.wdCRLF;
// SaveAs requires lots of parameters, but we can leave most of them empty:
wordApplication.ActiveDocument.SaveAs(ref o_newfilename, ref o_format, ref o_nullobject,
ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject,
ref o_nullobject, ref o_nullobject, ref o_encoding, ref o_nullobject,
ref o_nullobject, ref o_endings, ref o_nullobject);
The library is Microsoft.Office.Interop.Word;
If I remember correctly Word is required on the machine where the code is executed. If it's ASP.NET it is required on the server.
Three ways: 1. save as HTML, as described by napster 2. transform the Open XML to HTML; the XSLT is available at http://www.codeplex.com/OpenXMLViewer 3. for the cleanest HTML, write code to convert each style in the document to CSS, and put any direct formatting in @style.
Is Word installed on the computer running your C# code?