我有一个asp.net应用程序,它使用Microsoft.Office.Interop.Word.ApplicationClass将上传的ms doc转换为pdf。它在我的本地机器上工作正常,但它不能在已部署的IIS服务器上运行。有任何获取输出需要可执行权限。
错误是: 由于以下错误,检索CLSID为{000209FF-0000-0000-C000-000000000046}的组件的COM类工厂失败:80070005。
我的代码如下:
public class Word2Pdf
{
private Microsoft.Office.Interop.Word.ApplicationClass MSWordDoc;
object UnknownType = Type.Missing;
public string Word2PdfCOnversion(object InputLocation, object OutputLocation)
{
string result;
try
{
//if (MSWordDoc == null)
MSWordDoc = new Microsoft.Office.Interop.Word.ApplicationClass();
MSWordDoc.Visible = false;
MSWordDoc.Documents.Open(ref InputLocation, //Input File Name Location
ref UnknownType, // Conversion Conformation
ref UnknownType, // Set ReadOnly Property
ref UnknownType, // Add to the Recent Files
ref UnknownType, // Document Password Setting
ref UnknownType, // Password Templete
ref UnknownType, // Revert
ref UnknownType, // Write Password to Document
ref UnknownType, // Write Password Template
ref UnknownType, // File Format
ref UnknownType, // Encoding File
ref UnknownType, // Visibility
ref UnknownType, // To Open or Repair
ref UnknownType, // Document Direction
ref UnknownType, // Encoding Dialog
ref UnknownType); // XML Text Transform
MSWordDoc.Application.Visible = false; // To Invisible the Word Document
MSWordDoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize; // Minimize the Opened Word File.
object SavePDFFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
MSWordDoc.ActiveDocument.SaveAs(ref OutputLocation, //Output File Location
ref SavePDFFormat, // File Format
ref UnknownType, // Comment to PDF File
ref UnknownType, // Password
ref UnknownType, // Add to Recent File
ref UnknownType, // Write Password
ref UnknownType, // ReadOnly Propert
ref UnknownType, // Original Font Embeding
ref UnknownType, // Save Picture
ref UnknownType, // Saving Form Datas
ref UnknownType, // Save as AOVE Letter
ref UnknownType, // Encoding
ref UnknownType, // Inserting Line Breakes
ref UnknownType, // Allow Substitution
ref UnknownType, // Line Ending
ref UnknownType); // Add BiDi Marks
result = "Success";
}
catch (Exception)
{
result = "Error";
}
finally
{
if (MSWordDoc == null) { }
else { MSWordDoc.Documents.Close(ref UnknownType, ref UnknownType, ref UnknownType); }
MSWordDoc.Quit(ref UnknownType, ref UnknownType, ref UnknownType);
}
return result;
}
}
答案 0 :(得分:0)
您需要为要使用的COM组件设置权限。在服务器上,运行dcomcnfg
实用程序。
在“组件服务\计算机\我的计算机\ DCOM配置”下,找到所需单词组件的CLSID。 (有帮助的是,我看到有些机器将它们列为guids,即{000209FF-0000-0000-C000-000000000046}
,其他机器通过名称列出办公室组件。
您需要右键单击CLSID并选择属性,更改“启动和激活权限”,“访问权限”和“身份”设置,以允许网站应用程序池帐户具有自动化Word的权利。< / p>
顺便提一下,您可能需要比您提到的更多的CLSID。当我使用word将doc和/或html转换为PDF的项目时,我们不得不添加Word的CLSID和几种Word Picture类型。
从记忆中,CLSID是:
{000209FF-0000-0000-C000-000000000046}
{000209FF-0000-0000-C000-0000000000FE}
{000209FF-0000-0000-C000-0000000000FF}
希望这应该指向正确的方向。