Use C # to invoke Word's interface to generate a doc file with the Htnl file

Source: Internet
Author: User

As starting from C # and using only C #, there is no contact with VB, only. NET, developers who have not used COM, and have been less aware of what is COM's ghost.

Now I see a chestnut in the book: A typical COM is the API for Word operations (personal understanding).

 Public Static voidWordtest () {Application app=Newapplication {Visible =true }; App.            Documents.Add (); Document Doc=app.            ActiveDocument; Paragraph par=Doc.            Paragraphs.add (); Par. Range.Text="hehe C # hellop"; stringfilename =AppDomain.CurrentDomain.BaseDirectory; Doc. SaveAs2 (FileName:Path.Combine (FileName,"demo.html"), FileFormat:WdSaveFormat.wdFormatFilteredHTML);
Doc. SaveAs2 (FileName:Path.Combine (FileName, "Demo.doc"), FileFormat:WdSaveFormat.wdFormatDocument97); Doc. Close (); App. Application.Quit (); }

The above is a static method that can be invoked using the console and generate a doc file and HTML file containing the text under the program's current path.

Environment: VS2013, added a reference to Microsoft.Office.Interop.Word, office2010 installed on the machine.

Use C # to invoke the interface of Word to generate a doc file with a htnl file

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.