C#将html导出到word(基于wps)

王朝学院·作者佚名  2016-05-17
窄屏简体版  字體: 小  |  中  |  大  |  超大  

C#将html导出到Word(基于wps)由于客户需要,我们需要实现将网页导出到word中的功能,在此过程中,尝试使用过openoffice、itext、wordapi等各种方法,都不尽如人意。openoffice导出的问题图片信息在word2007下看不到,itext导出嵌套表格格式会乱套、wordapi导出倒是正常,但是无法将图片信息一并导入到文件中。最后没有办法突发奇想用wps试试,没想到成功了。

在尝试之前因为不知道wps是否有相关的api或者com组件,事先致电了金山客服询问了相关事宜,经确认wps是提供com组件调用的,现在即附上导出代码供大家测试分享。

C#代码WPS.applicationwps=null;try{wps=newWPS.Application();}catch(Exceptionex){WriteLine(ex.Message);return"";}WPS.Documentdoc=wps.Documents.Open(httpUrl,false,true);stringfilename=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();stringserverPath=Server.MapPath("~/doc/");stringsavePath=serverPath+filename+".doc";objectsaveFileName=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);在此需要先引用wps的com组件,并且using WPS;使用还是非常方便的推荐大家使用.

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航