C # exports HTML to Word (WPS-based)

Source: Internet
Author: User

Because of customer needs, we need to implement the ability to export Web pages to Word, in the process, try to use OpenOffice, Itext, Wordapi and other methods, are not satisfactory. OpenOffice Exported problems picture information under word2007 can not see, itext Export nested table format will be messy, WORDAPI export is normal, but cannot import picture information into the file. At last there was no way to try WPS with a whim and did not expect to succeed.

Before attempting to know if WPS has the relevant API or COM components, in advance call the Kingsoft Customer service asked the relevant matters, confirmed that WPS is to provide COM component calls, now attach the export code for everyone to test 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);

It is necessary to refer to the WPS COM component First, and using WPS, and it is very convenient to recommend the use of everyone.

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.