C # export html to word (based on wps)

Source: Internet
Author: User

Because of the customer's needs, we need to implement the function of exporting web pages to word. In this process, we tried to use openoffice, itext, wordapi and other methods, which were not satisfactory. The image information exported by openoffice cannot be seen in word2007. It is normal for itext to export the nested table format in disorder and export the wordapi, but the image information cannot be imported into the file together. In the end, there was no way to try wps. I did not expect it to succeed.

Before the attempt, we did not know whether wps had related APIs or com components. We called Jinshan customer service in advance to inquire about related matters. After confirmation, wps provided the com component for calling, the exported code is now attached for testing and sharing.

 

C # code  
  1. WPS. Application wps = null;
  2. Try
  3. {
  4. Wps = new WPS. Application ();
  5. }
  6. Catch (Exception ex ){
  7. WriteLine (ex. Message );
  8. Return "";
  9. }
  10. WPS. Document doc = wps. Documents. Open (httpUrl, false, true );
  11. String filename = System. DateTime. Now. Year. ToString () + System. DateTime. Now. Month. ToString () + System. DateTime. Now. Day. ToString () +
  12. System. DateTime. Now. Hour. ToString () + System. DateTime. Now. Minute. ToString () + System. DateTime. Now. Second. ToString ();
  13. String serverPath = Server. MapPath ("~ /Doc /");
  14. String savePath = serverPath + filename + ". doc ";
  15. Object saveFileName = savePath;
  16. Doc. SaveAs (savePath, WPS. WdSaveFormat. wdFormatDocument );
  17. Doc. Close (WPS. WdSaveOptions. wdSaveChanges, WPS. WdOriginalFormat. wdWordDocument, WPS. WdRoutingSlipStatus. wdNotYetRouted );
  18. Wps. Quit (WPS. WdSaveOptions. wdSaveChanges, WPS. WdOriginalFormat. wdWordDocument, WPS. WdRoutingSlipStatus. wdNotYetRouted );

Here we need to first reference the com component of wps, and using WPS; it is very convenient to use.

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.