asp.netweb服务使用office2010COM我正在??写一个web服务,想把.docx或.doc转成.xps。我在使用officecom来帮助我保存为.xps格式如下:字符串m_orgFilePath=_currentDirectory+"\"+m_userName+"\"+m_orgFileName;如果(File.Exists(m_orgFilePath)){stringm_xpsFilePath=_currentDirectory+"\"+m_userName+"\"+Path.GetFileNameWithoutExtension(m_orgFileName)+".xps";OfficeToXpsConversionResultm_converstionResult=OfficeToXps.ConvertToXps(m_orgFilePath,refm_xpsFilePath);m_returnUrl=_baseUrl+m_userName+"/"+Path.GetFileName(m_xpsFilePath);}返回m_returnUrl;}privatestaticOfficeToXpsConversionResultConvertFromWord(stringsourceFilePath,refstringresultFilePath){objectpSourceDocPath=sourceFilePath;字符串pExportFilePath=string.IsNullOrWhiteSpace(resultFilePath)?GetTempXpsFilePath():结果文件路径;Word.Application()wordApplication=newWord.Application();//wordDocument=wordApplication.Documents.打开(参考pSourceDocPath);动态wordDocument=wordApplication.Documents.Add(pSourceDocPath);//返回新的OfficeToXpsConversionResult(ConversionResult.ErrorUnableToOpenOfficeFile,exc.Message,exc);如果(wordDocument!=null){wordDocument.SaveAs(pExportFileFormat,W.wdFormatXPS);}resultFilePath=pExportFilePath;返回新的OfficeToXpsConversionResult(ConversionResult.OK,pExportFilePath);但是当我尝试通过web方法调用时我得到异常:,字符串消息)on(Closure,CallSite,ComObject,Object)DocProcessService中的System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSitesite,T0arg0,T1arg1)CallSite.Target(Closure,CallSite,Object,Object))(CallSitesite,T0arg0,T1arg1)在C:\UsersIcicleDocuments\FotomaxWP7DocProcessServiceDocProcessServiceOfficeHelperOfficeToXps.cs:DocProcessService.OfficeToXps.ConvertFromWord(StringsourceFilePath,String&resultFilePath)online145.OfficeToXps.ConvertToXps(StringsourceFilePath,String&resultFilePath)在C:UsersIcicleDocumentsFotomaxWP7DocProcessServiceDocProcessServiceOfficeHelperOfficeToXps.cs:DocProcessService.DocDownload.GetDocPreviewUrl(Stringm_userName,StringW_orgFileName)处的第63行,位于C:UsersIcicleDocumentsP7FocumentDocProcessServiceDocProcessServiceDocDownload.asmx.cs:第90行使用officeworks保存为xps的代码在我的WPF项目中很好。我如何在我的asp.net4.0web服务中使用它?谢谢。MS不支持在Windows服务(例如IIS和ASP.NET)中使用自动化!根据自己的需要,可以使用一些库(免费的或者商业的):以上就是C#学习教程的全部内容:asp.netwebserviceusingoffice2010COM,如果对大家有用还需要了解一下C#学习教程,希望大家多多关注—本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
