我写一个Web服务,并想改变的.docx或.doc到.XPS。 我使用的办公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);
}
但是,我得到了异常,当我尝试通过Web方法调用:
System.Runtime.InteropServices.COMException:字发生问题在System.Dynamic.ComRuntimeHelpers.CheckThrowException(的Int32 HRESULT,EXCEPINFO&EXCEPINFO,UInt32的argErr,字符串消息)在CallSite.Target(封闭,调用点,ComObject,对象)在System.Dynamic .UpdateDelegates.UpdateAndExecute2 [T0,T1,TRET](调用点站点,T0为arg0,T1 ARG1)在CallSite.Target(封闭,调用点,对象,对象)在System.Dynamic.UpdateDelegates.UpdateAndExecute2 [T0,T1,TRET](用C调用点站点,T0为arg0,T1 ARG1)在DocProcessService.OfficeToXps.ConvertFromWord(字符串sourceFilePath,字符串&resultFilePath):\用户\冰柱\文件\快图美WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs:线145在DocProcessService。 OfficeToXps.ConvertToXps(字符串sourceFilePath,字符串&resultFilePath)在C:\用户\冰柱\文件\快图美WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs:线63在DocProcessService.DocDownload.GetDocPreviewUrl(字符串m_userName,字符串m_org 文件名)在C:\用户\冰柱\文件\快图美WP7 \ DocProcessService \ DocProcessService \ DocDownload.asmx.cs:线90
使用办公室保存为XPS的代码在我的WPF项目运作良好。 我怎样才能让使用它在我的asp.net 4.0 Web服务? 谢谢。