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
- Wps. Application wps = null;
- Try
- {
- wps = New WPS. Application ();
- }
- catch (Exception ex) {
- WriteLine (ex. Message);
- return "";
- }
- Wps. Document doc = wps. Documents.Open (Httpurl, false, true);
- string filename = System.DateTime.Now.Year.ToString () + System.DateTime.Now.Month.ToString () + System.DateTime.Now.Day.ToString () +
- System.DateTime.Now.Hour.ToString () + System.DateTime.Now.Minute.ToString () + System.DateTime.Now.Second.ToString ( );
- string serverpath = Server.MapPath ("~/doc/");
- string savepath = serverpath + filename + ". Doc";
- object savefilename = Savepath;
- Doc. SaveAs (Savepath, WPS. Wdsaveformat.wdformatdocument);
- Doc. Close (WPS. Wdsaveoptions.wdsavechanges, WPS. Wdoriginalformat.wdworddocument, WPS. wdroutingslipstatus.wdnotyetrouted);
- 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.