Reference the Com component Microsoft Word 11.0 Object Library of Word. My office2003 version is 8.3, and the default installed Office does not have this component. Use an office disk to add or delete components. Select custom components. the. NET programmable support is available under Microsoft Office Word. Install.
This line is added to Web. config referenced in the project.
<Compilation debug = "false">
<Assemblies>
<Add assembly = "Microsoft. Office. Interop. Word, Version = 11.0.0.0, Culture = neutral, PublicKeyToken = 71e9bce111e9429c"/> </assemblies>
Program code:
Microsoft. Office. Interop. Word. Application word = new Microsoft. Office. Interop. Word. ApplicationClass ();
// Word. ApplicationClass word = new Word. ApplicationClass ();
Type wordType = word. GetType ();
Microsoft. Office. Interop. Word. Documents docs = word. Documents;
// Open the file
Type docsType = docs. GetType ();
Object fileName = "e: \ cc.doc ";
Microsoft. Office. Interop. Word. Document doc = (Microsoft. Office. Interop. Word. Document) docsType. InvokeMember ("Open ",
System. Reflection. BindingFlags. InvokeMethod, null, (object) docs, new Object [] {fileName, true, true });
// Convert the format and save it
Type docType = doc. GetType ();
Object saveFileName = "e: \ aaa.html ";
// The following is the Microsoft Word 9 (11.0) Object Library statement. If it is 10 (not tried), it may be written:
/*
DocType. InvokeMember ("SaveAs", System. Reflection. BindingFlags. InvokeMethod,
Null, doc, new object [] {saveFileName, Word. WdSaveFormat. wdFormatFilteredHTML });
*/
/// Other formats:
/// WdFormatHTML
/// WdFormatDocument
/// WdFormatDOSText
/// WdFormatDOSTextLineBreaks
/// WdFormatEncodedText
/// WdFormatRTF
/// WdFormatTemplate
/// WdFormatText
/// WdFormatTextLineBreaks
/// WdFormatUnicodeText
DocType. InvokeMember ("SaveAs", System. Reflection. BindingFlags. InvokeMethod,
Null, doc, new object [] {saveFileName, Microsoft. Office. Interop. Word. WdSaveFormat. wdFormatHTML });
// Exit Word
WordType. InvokeMember ("Quit", System. Reflection. BindingFlags. InvokeMethod,
Null, word, null );