Sharepint 2013 的 Office Interop Word 错误

问题描述 投票:0回答:0

我开发了一个 webpart,它创建一个 word 文档并使用 ExportAsFixedFormat 将其导出为 PDF 格式。它在我的开发共享点服务器中工作。当我将其部署到生产服务器时,出现此错误

[COMException (0x80004005): Word has encountered a problem.]
   Microsoft.Office.Interop.Word.DocumentClass.ExportAsFixedFormat(String OutputFileName, WdExportFormat ExportFormat, Boolean OpenAfterExport, WdExportOptimizeFor OptimizeFor, WdExportRange Range, Int32 From, Int32 To, WdExportItem Item, Boolean IncludeDocProps, Boolean KeepIRM, WdExportCreateBookmarks CreateBookmarks, Boolean DocStructureTags, Boolean BitmapMissingFonts, Boolean UseISO19005_1, Object& FixedFormatExtClassPtr) +0
   test.PdfExporter.WebParts.PrintPDF.<>c__DisplayClass4_0.<generateWodDoc>b__0() +10785
   Microsoft.SharePoint.<>c__DisplayClass5.<RunWithElevatedPrivileges>b__3() +349
   Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) +197
   Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) +423
   Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) +95
   test.PdfExporter.WebParts.PrintPDF.PrintPDFUserControl.generateWodDoc(ServiceConfermationList serviceConfermationList) +158
   test.PdfExporter.WebParts.PrintPDF.PrintPDFUserControl.<btnPrint_Click>b__3_0() +2075
   Microsoft.SharePoint.<>c__DisplayClass5.<RunWithElevatedPrivileges>b__3() +349
   Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) +197
   Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) +423
   Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) +95
   test.PdfExporter.WebParts.PrintPDF.PrintPDFUserControl.btnPrint_Click(Object sender, EventArgs e) +94
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +99
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2749

这是使用代码的例子

using Microsoft.Office.Interop.Word;

// Create a new Word application
Application wordApp = new Application();

// Create a new document
Document doc = wordApp.Documents.Add();

// Insert content into the document
Paragraph para = doc.Content.Paragraphs.Add();
para.Range.Text = "Hello, World!";

// Export the document as PDF
string pdfFileName = "example.pdf";
doc.ExportAsFixedFormat(pdfFileName, WdExportFormat.wdExportFormatPDF);

// Clean up
doc.Close();
wordApp.Quit();

备注:

1- 我使用 wwroot 路径作为保存文件的目的地。

2- 我使用 office 2013.

解决我遇到的问题

c# sharepoint sharepoint-2013 office-interop web-parts
© www.soinside.com 2019 - 2024. All rights reserved.