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
- 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 );
Here we need to first reference the com component of wps, and using WPS; it is very convenient to use.