Je suis en train d'écrire un service Web et je voudrais changer le fichier .docx ou .doc en .xps. J'utilise com bureau pour me aider à enregistrer en tant que format que .xps suivant:service Web asp.net utilisant Office 2010 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);
}
Cependant, je suis exception quand je tente d'appeler la méthode Web:
System.Runtime. InteropServices.COMException: Word 發生 問題 à System.Dynamic.ComRuntimeHelpers.CheckThrowException (Int32 de hresult, EXCEPINFO & excepInfo, UInt32 ARGERR, String message) à CallSite.Target (fermeture, callsite, ComObject, Object) à System.Dynamic. .UpdateDelegates.UpdateAndExecute2 [T0, T1, TRet] (Site du site d'appel, T0 arg0, T 1 arg1) à CallSite.Target (Clôture, callsite, d'objets, d'objets) à System.Dynamic.UpdateDelegates.UpdateAndExecute2 [T0, T1, TRET] (site de callsite, T0 arg0, T1 arg1) à DocProcessService.OfficeToXps.ConvertFromWord (String sourcefilepath, String & resultFilePath) dans C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs: ligne 145 à DocProcessService.OfficeToXps.ConvertToXps (String sourcefilepath, String & resultFilePath) par C : \ Utilisateurs \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs: ligne 63 à DocProcessService.DocDownload.GetDocPreviewUrl (Chaîne m_userName, String m_orgFileName) dans C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ DocDownload.asmx.cs: ligne 90
Le code d'utilisation de bureau pour enregistrer en xps fonctionnait bien dans mon projet WPF. Comment puis-je l'utiliser dans mon service Web asp.net 4.0? Merci.