私はWebサービスを作成しています.docxまたは.docを.xpsに変更したいと思います。asp.net Webサービスを使用してオフィス2010 COM
System.Runtime:私は、Webメソッドで呼び出すようにしようとすると
[WebMethod] public string GetDocPreviewUrl(string m_userName, string m_orgFileName) { string m_returnUrl = ""; string m_orgFilePath = _currentDirectory + "\\" + m_userName + "\\" + m_orgFileName; if (File.Exists(m_orgFilePath)) { string m_xpsFilePath = _currentDirectory + "\\" + m_userName + "\\" + Path.GetFileNameWithoutExtension(m_orgFileName) + ".xps"; OfficeToXpsConversionResult m_converstionResult = OfficeToXps.ConvertToXps(m_orgFilePath, ref m_xpsFilePath); m_returnUrl = _baseUrl + m_userName + "/"+ Path.GetFileName(m_xpsFilePath); } return m_returnUrl; } private static OfficeToXpsConversionResult ConvertFromWord(string sourceFilePath, ref string resultFilePath) { object pSourceDocPath = sourceFilePath; string pExportFilePath = string.IsNullOrWhiteSpace(resultFilePath) ? GetTempXpsFilePath() : resultFilePath; Word.Application() wordApplication = new Word.Application(); //wordDocument = wordApplication.Documents.Open(ref pSourceDocPath); dynamic wordDocument = wordApplication.Documents.Add(pSourceDocPath); //return new OfficeToXpsConversionResult(ConversionResult.ErrorUnableToOpenOfficeFile, exc.Message, exc); if (wordDocument != null) { wordDocument.SaveAs(pExportFilePath, WdSaveFormat.wdFormatXPS); } resultFilePath = pExportFilePath; return new OfficeToXpsConversionResult(ConversionResult.OK, pExportFilePath); }
はしかし、私は、例外が発生しました:私は、次のようなフォーマットを.xpsとして保存するために私を助けるために、オフィスCOMを使用しています。 InteropServices.COMException:ワード發生問題System.Dynamic.ComRuntimeHelpers.CheckThrowException(のInt32 HRESULT、EXCEPINFO & EXCEPINFO、UInt32型argErr、文字列メッセージ)System.DynamicでCallSite.Targetで (閉鎖、呼び出し場所、ComObject、オブジェクト) で。 .UpdateDelegates.UpdateAndExecute2 [T0、T1、TRet](CallSiteサイト、T0 arg0、T (CallSiteサイト、T0 arg0、T1 arg1) at DocProcessService.OfficeToXps.ConvertFromWord(CallSiteサイト、T0 arg0、T1 arg1) で、DoSystem.OpdateToXps.UpdateAndExecute2 [] C:¥Users¥Icicle¥Documents¥Fotomax WP7¥DocProcessService¥DocProcessService¥OfficeHelper¥OfficeToXps.cs内のDocProcessService.OfficeToXps.ConvertToXps(文字列sourceFilePath、String & resultFilePath)の行145 の行(String sourceFilePath、String & resultFilePath) :\ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs:行63 DocProcessService.DocDownload.GetDocPreviewUrl(文字列m_userName、文字列m_orgFileName)C:\ Users \ ICc \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ DocDownload.asmx.cs:行90
オフィスを使用してxpsとして保存するコードは、私のWPFプロジェクトでうまくいきました。どうすれば私のasp.net 4.0 Webサービスでそれを使用することができますか?ありがとう。