Asp. Net converts word files to html files

Source: Internet
Author: User

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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.