解决本地调用office组件成功,但是发布到IIS中出现的错误(检索COM类工厂中CLSID为{00024500-0000-0000-C000-000000000046}的组件时失败)
在C#操作word或者Excel,我们可能会用到微软内置的COM组件,会出现很多问题。
如:在本地调试导出Excel没有问题,发布到IIS就有问题了,检测到的异常:
我们会发现在iis上运行的程序,没有打开word的进程。
因为你vs是管理员权限,而iis没有权限。
所以这要提高iis的权限。
启动IIS,应用程序池-“选定的应用程序池”-高级设置-进程模拟-标识:
选择自定义帐户然后单击设置以打开设置凭据对话框,输入管理员的用户名和密码。
输入管理员的账号和密码
在%windir%/System32/config/systemprofile下,建立Desktop文件夹。
一切IIS对COM组件的操作 均需要设置标识为 隶属于administrator组的用户.
-----------------------------------------------------------------------------------------------------------------
记录:
- //Word转换成pdf
- /// <summary>
- /// 把Word文件转换成为PDF格式文件
- /// </summary>
- /// <param name="sourcePath">源文件路径</param>
- /// <param name="targetPath">目标文件路径</param>
- /// <returns>true=转换成功</returns>
- private bool DOCConvertToPDF(string sourcePath, string targetPath)
- {
- bool result = false;
- Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF;
- object paramMissing = Type.Missing;
- Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
- Microsoft.Office.Interop.Word.Document wordDocument = null;
- try
- {
- object paramSourceDocPath = sourcePath;
- string paramExportFilePath = targetPath;
- Microsoft.Office.Interop.Word.WdExportFormat paramExportFormat = exportFormat;
- bool paramOpenAfterExport = false;
- Microsoft.Office.Interop.Word.WdExportOptimizeFor paramExportOptimizeFor = Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
- Microsoft.Office.Interop.Word.WdExportRange paramExportRange = Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument;
- int paramStartPage = ;
- int paramEndPage = ;
- Microsoft.Office.Interop.Word.WdExportItem paramExportItem = Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent;
- bool paramIncludeDocProps = true;
- bool paramKeepIRM = true;
- Microsoft.Office.Interop.Word.WdExportCreateBookmarks paramCreateBookmarks = Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
- bool paramDocStructureTags = true;
- bool paramBitmapMissingFonts = true;
- bool paramUseISO19005_1 = false;
- wordDocument = wordApplication.Documents.Open(
- ref paramSourceDocPath, ref paramMissing, ref paramMissing,
- ref paramMissing, ref paramMissing, ref paramMissing,
- ref paramMissing, ref paramMissing, ref paramMissing,
- ref paramMissing, ref paramMissing, ref paramMissing,
- ref paramMissing, ref paramMissing, ref paramMissing,
- ref paramMissing);
- if (wordDocument != null)
- wordDocument.ExportAsFixedFormat(paramExportFilePath,
- paramExportFormat, paramOpenAfterExport,
- paramExportOptimizeFor, paramExportRange, paramStartPage,
- paramEndPage, paramExportItem, paramIncludeDocProps,
- paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
- paramBitmapMissingFonts, paramUseISO19005_1,
- ref paramMissing);
- result = true;
- }
- catch
- {
- result = false;
- }
- finally
- {
- if (wordDocument != null)
- {
- wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
- wordDocument = null;
- }
- if (wordApplication != null)
- {
- wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
- wordApplication = null;
- }
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- return result;
- }
- /// <summary>
- /// 把Excel文件转换成PDF格式文件
- /// </summary>
- /// <param name="sourcePath">源文件路径</param>
- /// <param name="targetPath">目标文件路径</param>
- /// <returns>true=转换成功</returns>
- private bool XLSConvertToPDF(string sourcePath, string targetPath)
- {
- bool result = false;
- Microsoft.Office.Interop.Excel.XlFixedFormatType targetType = Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF;
- object missing = Type.Missing;
- Microsoft.Office.Interop.Excel.ApplicationClass application = null;
- Microsoft.Office.Interop.Excel.Workbook workBook = null;
- try
- {
- application = new Microsoft.Office.Interop.Excel.ApplicationClass();
- object target = targetPath;
- object type = targetType;
- workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
- missing, missing, missing, missing, missing, missing, missing, missing, missing);
- workBook.ExportAsFixedFormat(targetType, target, Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityMinimum, true, false, missing, missing, missing, missing);
- result = true;
- }
- catch
- {
- result = false;
- }
- finally
- {
- if (workBook != null)
- {
- workBook.Close(true, missing, missing);
- workBook = null;
- }
- if (application != null)
- {
- application.Quit();
- application = null;
- }
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- return result;
- }
- /// <summary>
- /// 把PowerPoing文件转换成PDF格式文件
- /// </summary>
- /// <param name="sourcePath">源文件路径</param>
- /// <param name="targetPath">目标文件路径</param>
- /// <returns>true=转换成功</returns>
- //private bool PPTConvertToPDF(string sourcePath, string targetPath)
- // {
- // bool result;
- // PowerPoint.PpSaveAsFileType targetFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
- // object missing = Type.Missing;
- // PowerPoint.ApplicationClass application = null;
- // PowerPoint.Presentation persentation = null;
- // try
- // {
- // application = new PowerPoint.ApplicationClass();
- // persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
- // persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
- // result = true;
- // }
- // catch
- // {
- // result = false;
- // }
- // finally
- // {
- // if (persentation != null)
- // {
- // persentation.Close();
- // persentation = null;
- // }
- // if (application != null)
- // {
- // application.Quit();
- // application = null;
- // }
- // GC.Collect();
- // GC.WaitForPendingFinalizers();
- // GC.Collect();
- // GC.WaitForPendingFinalizers();
- // }
- // return result;
- // }
解决本地调用office组件成功,但是发布到IIS中出现的错误(检索COM类工厂中CLSID为{00024500-0000-0000-C000-000000000046}的组件时失败)的更多相关文章
- 解决Office互操作错误"检索COML类工厂中 CLSID为 {xxx}的组件时失败,原因是出现以下错误: 80070005"
Excel为例(其他如Word也适用)文件数据导入时报出以下错误: 检索COML类工厂中 CLSID为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是 ...
- (原创)解决Excel 互操作错误"检索COML类工厂中 CLSID为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005"
最近在.net中处理Excel文件数据导入时报出以下错误: 检索COML类工厂中 CLSID为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下 ...
- 8000401a 错误 ,检索 COM 类工厂中 CLSID 为 的组件时失败,原因是出现以下错误: 8000401a。
"/"应用程序中的服务器错误. -------------------------------------------------------------------------- ...
- VS2008中 VB 报错 检索 COM 类工厂中 CLSID 为 {28E68F9A-8D75-11D1-8DC3-3C302A000000} 的组件失败,原因是出现以下错误: 80040154 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))。
Resvr32 .net中引用控件的名称 如果注册成功,问题不在出现 但是如果是在x64位的系统中,即使控件注册成功,错误依照提示,是因为大多数第三方写的COM控件,只支持32位的系统, 在VS中找到 ...
- .Net调用Office Com组件的原理及问题检索com类工厂组件检索 COM 类工厂中 CLSID 为 {XXX} 的组件失败
我是在本地32位操作系统+vs2010+office2007做创建并下载Excel,ppt文件的操作没有问题,发布到64位系统的服务器上报错,最开始报错:: 1:Retrieving the COM ...
- 检索COM 类工厂中CLSID 为{00024500-0000-0000-C000-000000000046}组件时失败
检索 COM 类工厂中 CLSID 为{00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005 当在ASP.NET应用程序中引 ...
- 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005。
错误描述:当在ASP.NET应用程序中引用Microsoft Excel组件,并在程序中调用时,部署到服务器上经常会遇到以下的错误:检索 COM 类工厂中 CLSID 为{00024500-0000- ...
- 解决C#调用执行js报检索 COM 类工厂中 CLSID 为 {0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC} 组件失败
最近做了一个模拟请求的网站简化原网站的繁琐数据,提出有用的数据简单展示并完成post.由于原网站数据有js加密,所以我抓出原网站的js解密方法,由C#调用js得到解密后的数据. 整个抓包的框架是用的苏 ...
- "检索COM类工厂中 CLSID为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005" 问题的解决
一.故障环境 Windows 2008 .net 3.0 二.故障描述 调用excel组件生成excel文档时页面报错.报错内容一大串,核心是"检索COM类工厂中 CLSID为 {000 ...
- 在IIS上Office Word下载失败,检索 COM 类工厂中 CLSID 为000209FF的组件失败,80070005 拒绝访问。
最近在做一个网站时,有一个下载word文档功能,在本地直接调试是可以下载的,但部署到IIS上就出现问题了. 出现问题如下:Error:下载简历方法出错:检索 COM 类工厂中 CLSID 为 {000 ...
随机推荐
- node爬虫(简版)
做node爬虫,首先像如何的去做这个爬虫,首先先想下思路,我这里要爬取一个页面的数据,要调取网页的数据,转换成页面格式(html+div)格式,然后提取里面独特的属性值,再把你提取的值,传送给你的页面 ...
- 【数位dp】bzoj1833: [ZJOI2010]count 数字计数
数位dp姿势一直很差啊:顺便庆祝一下1A Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包含一行两个整数a ...
- 离线web-ApplicationCache
https://www.html5rocks.com/en/tutorials/appcache/beginner/ http://diveintohtml5.info/offline.html#fa ...
- webpack-dev-server proxy代理
一个最简单的代理例子:index.html中有如下代码 fetch('/api/pub/article/list?pageSize=2').then((data)=>{ return data. ...
- JavaScript正则表达式-后缀选项(标记)
i:表示匹配时不区分大小写 Str = "JavaScript is different from java"; reg = /java\w*/i; arr_m = str.mat ...
- Java面试之基础题---对象Object
参数传递:Java支持两种数据类型:基本数据类型和引用数据类型. 原始数据类型是一个简单的数据结构,它只有一个与之相关的值.引用数据类型是一个复杂的数据结构,它表示一个对象.原始数据类型的变量将该值直 ...
- PHP 获取文件名和扩展名的方法
dirname(path) path: 代表你的文件路径,必须为绝对路径,可以使用__FILE__, 表示列出当前文件的绝对路径,包含文件名 函数会返回当前文件的上一级路径,也就是除了文件名称的路径 ...
- POJ-3481 Double Queue,Treap树和set花式水过!
Double Queue 本打算学二叉树,单纯的二叉树感觉也就那几种遍历了, 无意中看到了这个题,然后就 ...
- 九度oj 题目1173:查找
题目描述: 输入数组长度 n 输入数组 a[1...n] 输入查找个数m 输入查找数字b[1...m] 输出 YES or NO 查找有则YES 否则NO . 输入: 输入有多组数据. ...
- 【Luogu】P2422良好的感觉(单调栈)
题目链接 写代码能力需要极大提升.我在五分钟之内想到了单调栈,然后花了一个小时的时间去看我单调队列为啥写错了…… 首先这题需要转换自己的思维.枚举所有“最小点”,然后看它往左往右最大能扩展多少. 维护 ...