// Convert Word to HTML Format
Private void button_word_click (Object sender, system. eventargs E)
{
/// <Summary>
/// Summary of wordtohtml.
/// Add reference: Microsoft Word 9.0 Object Library
/// </Summary>
// Place user code here to initialize the page
Word. applicationclass word = new word. applicationclass ();
Type wordtype = word. GetType ();
Word. Documents docs = word. documents;
// Open the file
Type docstype = docs. GetType ();
Object filename = wordfile. value;
Word. Document Doc = (word. Document) docstype. invokemember ("open ",
System. reflection. bindingflags. invokemethod, null, Docs, new object [] {filename, true, true });
// Convert the format and save it
Type doctype = Doc. GetType ();
Object savefilename = "C: // pwordtohtml.html ";
// The following is the Microsoft Word 9 Object Library statement. If it is 10, it may be written as follows:
/*
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, word. wdsaveformat. wdformathtml });
// Exit word
Wordtype. invokemember ("quit", system. reflection. bindingflags. invokemethod,
Null, word, null );
}
// Convert HTML to Word Format
Private void button_html_click (Object sender, system. eventargs E)
{
/// <Summary>
/// Summary of wordtohtml.
/// Add reference: Microsoft Word 9.0 Object Library
/// </Summary>
// Place user code here to initialize the page
Word. applicationclass word = new word. applicationclass ();
Type wordtype = word. GetType ();
Word. Documents docs = word. documents;
// Open the file
/* Type docstype = docs. GetType ();
Object filename = "C: // pwordtohtml.html ";
Word. Document Doc = (word. Document) docstype. invokemember ("open ",
System. reflection. bindingflags. invokemethod, null, Docs, new object [] {filename, true, true });
*/
Object filename = "C: // pwordtohtml.html ";
Object readonly = false;
Object isvisible = true;
Object format = word. wdopenformat. wdopenformatauto;
Object missing = system. reflection. Missing. value;
Word. document Doc = word. documents. open (ref filename, ref missing, ref readonly, ref missing, ref format, ref missing, ref isvisible );
// Convert the format and save it
Type doctype = Doc. GetType ();
Object savefilename = "C: // pcword.doc ";
// The following is the Microsoft Word 9 Object Library statement. If it is 10, it may be written as follows:
/*
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, word. wdsaveformat. wdformatdocument });
// Exit word
Wordtype. invokemember ("quit", system. reflection. bindingflags. invokemethod,
Null, word, null );
}