use*_*449 5 c# asp.net com ms-word exception
如何解决以下错误。运行时出现此错误。
由于以下错误,检索具有 CLSID {000209FF-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80040154 类未注册(HRESULT 异常:0x80040154 (REGDB_REGT)CLASSNO)。
代码:此代码用于将 word 转换为 pdf 文档文件。我在这一行出错。
Application wordApp = new Microsoft.Office.Interop.Word.Application();
Document wordDocument = new Document();
private void ConvertWord2PDF(string inputFile, string outputPath)
{
try
{
if (outputPath.Equals("") || !File.Exists(inputFile))
{
throw new Exception("Either file does not exist or invalid output path");
}
// app to open the document belower
Application wordApp = new Microsoft.Office.Interop.Word.Application();
Document wordDocument = new Document();
// input variables
object objInputFile = inputFile;
object missParam = Type.Missing;
wordDocument = wordApp.Documents.Open(ref objInputFile, ref missParam, ref missParam, ref missParam,
ref missParam, ref missParam, ref missParam, ref missParam, ref missParam, ref missParam,
ref missParam, ref missParam, ref missParam, ref missParam, ref missParam, ref missParam);
if (wordDocument != null)
{
// make the convertion
wordDocument.ExportAsFixedFormat(outputPath, WdExportFormat.wdExportFormatPDF, false,
WdExportOptimizeFor.wdExportOptimizeForOnScreen, WdExportRange.wdExportAllDocument,
0, 0, WdExportItem.wdExportDocumentContent, true, true,
WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, false, ref missParam);
}
// close document and quit application
wordDocument.Close();
wordApp.Quit();
Response.Write("File successfully converted");
//ClearTextBoxes();
}
catch (Exception e)
{
throw e;
}
}
Run Code Online (Sandbox Code Playgroud)
不应在服务或 Web 应用程序(如 IIS)中使用任何 Office 应用程序。其次,interop.word.dll 就像一个头文件,您实际上需要安装 Office\word 才能使用它。
请注意微软对此的立场:
Microsoft 当前不建议也不支持从任何无人参与的非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)自动化 Microsoft Office 应用程序,因为 Office 可能表现出不稳定的行为和/或在此环境中运行 Office 时出现死锁。
在 ASP.Net 中预览和转换 Word 文件 - 使用 OpenXML
| 归档时间: |
|
| 查看次数: |
10414 次 |
| 最近记录: |