Web サービスを作成していて、.docx または .doc を .xps に変更したいと考えています。次のように .xps 形式で保存するために、office com を使用しています。
[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);
}
ただし、Web メソッドで呼び出そうとすると例外が発生しました。
System.Runtime.InteropServices.COMException: System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message) での Word の問題。 .UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite サイト、T0 arg0、T1 arg1) で CallSite.Target(Closure 、CallSite 、Object 、Object ) で System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet]( C:\Users\Icicle\Documents\Fotomax WP7\DocProcessService\DocProcessService\OfficeHelper\OfficeToXps.cs: DocProcessService の 145 行目の DocProcessService.OfficeToXps.ConvertFromWord(String sourceFilePath, String& resultFilePath) の CallSite サイト、T0 arg0、T1 arg1)。 OfficeToXps.ConvertToXps(String sourceFilePath, String& resultFilePath) in C:\Users\Icicle\Documents\Fotomax WP7\DocProcessService\DocProcessService\OfficeHelper\OfficeToXps.cs: C:\Users\Icicle\Documents\Fotomax WP7\DocProcessService\ の DocProcessService.DocDownload.GetDocPreviewUrl(String m_userName, String m_orgFileName) の 63 行目DocProcessService\DocDownload.asmx.cs:90行目
office を使用して xps として保存するコードは、私の WPF プロジェクトでうまく機能していました。asp.net 4.0 Web サービスで使用するにはどうすればよいですか? ありがとう。