веб-сервис asp.net с использованием Office 2010 COM
Я пишу веб-сервис и хотел бы изменить .docx или .doc на .xps. Я использую office com, чтобы сохранить файл в формате .xps следующим образом:
[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);
}
Тем не менее, я получил исключение, когда я пытаюсь вызвать веб-метод:
System.Runtime.InteropServices.COMException: Word。 問題。 в System.Dynamic.ComRuntimeHelpers.CheckThrowException (Int32 hresult, ExcepInfo & excepInfo, UInt32 argErr, сообщение String) в CallSite.Target (объект замыкания, объект CallSiteO, объект CallSiteO, .UpdateDelegates.UpdateAndExecute2 [T0, T1, TRet] (сайт CallSite, T0 arg0, T1 arg1) в CallSite.Target (Closure, CallSite, Object, Object) в System.Dynamic.UpdateDelegates.UpdateAndExecute2 [T0, T1, T1, T1 Сайт CallSite, T0 arg0, T1 arg1) в DocProcessService.OfficeToXps.ConvertFromWord (String sourceFilePath, String & resultFilePath) в C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ Office_ProcessService. OfficeToXps.ConvertToXps (String sourceFilePath, String & resultFilePath) в C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs: строка 63 в DocProcessService.DocDownload._tring_name для обмена данными (String). FileName) в C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ DocDownload.asmx.cs: строка 90
Код использования office для сохранения в формате xps хорошо работал в моем проекте WPF. Как я могу использовать его в своем веб-сервисе asp.net 4.0? Благодарю.