泪奔求助:System.Runtime.InteropServices.COMException:命令失败

mmrwbb16 2011-02-22 10:11:16

代码:(红色为出错地方)

Microsoft.Office.Interop.Word._Application oWord = null;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
//oWord.Visible = true;
object ReadOnly = true;
oWord.ActivePrinter = "Microsoft Office Document Image Writer";
oDoc = oWord.Documents.Open(ref tempFileName,
ref oMissing, ref ReadOnly, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
try
{
// if (!Directory.Exists(savePath.ToString()))
// {
// Directory.CreateDirectory(savePath.ToString());
// }
savePath = sPath;//+ strFileName + "." + astdt;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;

oDoc.SaveAs(ref savePath, ref format,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);






Microsoft.Office.Interop.Word.WdStatistic stat = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
pageNum = oDoc.ComputeStatistics(stat, ref oMissing);


错误信息:

捕捉到 System.Runtime.InteropServices.COMException
HelpLink="C:\\Program Files\\Microsoft Office\\Office12\\2052\\WDMAIN11.CHM#36966"
Message="命令失败"
Source="Microsoft Word"
ErrorCode=-2146824090
StackTrace:
在 Microsoft.Office.Interop.Word.DocumentClass.SaveAs(Object& FileName, Object& FileFormat, Object& LockComments, Object& Password, Object& AddToRecentFiles, Object& WritePassword, Object& ReadOnlyRecommended, Object& EmbedTrueTypeFonts, Object& SaveNativePictureFormat, Object& SaveFormsData, Object& SaveAsAOCELetter, Object& Encoding, Object& InsertLineBreaks, Object& AllowSubstitutions, Object& LineEnding, Object& AddBiDiMarks)
在 UploadSystem.Doc2Swf.ToPdf(String path, String sPath, String sImagesPath) 位置 E:\web\Wendang\UploadSystem\Convert.cs:行号 66
InnerException: null



GG了2天 说COM权限问题,如是在能加权限的地方全加上了 例如组件服务的WORD启动和访问权限 还是报错 去年遇到过一次这样的错误,后来解决了,但是忘了怎么解决的,泪奔啊,我的天那,我一个地方载了2次了,请各位救救我吧,不然我投河了。
...全文
3378 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
kaifa123 2013-11-11
  • 打赏
  • 举报
回复
到底有没有人解决啊??
luoqiaoyan 2013-04-10
  • 打赏
  • 举报
回复
现在还没有人把它解决吗?我搞不懂。。。。。这些代码的意思。。。有哪位高手可以说说么。。
z_浪翻云 2012-12-26
  • 打赏
  • 举报
回复
/// <summary> /// Word文件转换成为PDF格式文件 ///</summary> ///<param name="sourcePath">源文件路径(物理路径)</param> ///<param name="targetPath">目标文件路径(物理路径)</param> /// <returns>true=转换成功</returns> public static bool WORD_ConvertTo_PDF(string sourcePath, string targetPath) { bool result = false; Word.WdExportFormat exportFormat = Word.WdExportFormat.wdExportFormatPDF; object paramMissing = Type.Missing; Word.ApplicationClass wordApplication = new Word.ApplicationClass(); Word.Document wordDocument = null; try { object paramSourceDocPath = sourcePath; string paramExportFilePath = targetPath; Word.WdExportFormat paramExportFormat = exportFormat; bool paramOpenAfterExport = false; Word.WdExportOptimizeFor paramExportOptimizeFor = Word.WdExportOptimizeFor.wdExportOptimizeForPrint; Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument; int paramStartPage = 0; int paramEndPage = 0; Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent; bool paramIncludeDocProps = true; bool paramKeepIRM = true; Word.WdExportCreateBookmarks paramCreateBookmarks = 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 (Exception ex) { 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; }
mmrwbb16 2011-02-23
  • 打赏
  • 举报
回复
太杯具了,根本无解的BUG 还在找解决方法的劝你们还是放弃吧。。。
mmrwbb16 2011-02-23
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zzxap 的回复:]

http://social.microsoft.com/Forums/zh-CN/Offtopic/thread/97e651ad-f07b-47e9-8036-48a3b845123f
[/Quote]

我跟他的问题是一样的,但是他也没有解决哦。。。能不能稍微提个醒啊?现在一点头脑都摸不着
zzxap 2011-02-23
  • 打赏
  • 举报
回复
http://social.microsoft.com/Forums/zh-CN/Offtopic/thread/97e651ad-f07b-47e9-8036-48a3b845123f
mmrwbb16 2011-02-23
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wuyq11 的回复:]

Windows 2003配额制权限,一般没问题
卸载office,重新安装
[/Quote]
我把office03卸载重新装了,不行,又装07 还是不行,再装10,还是不行..求解啊 我机子可以,服务器上就不行
wuyq11 2011-02-22
  • 打赏
  • 举报
回复
Windows 2003配额制权限,一般没问题
卸载office,重新安装
mmrwbb16 2011-02-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xingyuebuyu 的回复:]

http://www.cnblogs.com/star250/archive/2008/03/06/1093720.html
[/Quote]

这个解决方法行不通。
第一,我不是aspnet程序,是winform
第二,COM权限我全加完了。
mmrwbb16 2011-02-22
  • 打赏
  • 举报
回复
Windows 2003系统 + office2007
程序是用于DOC转PDF的 调用office2007的API
这个程序以前在我xp机子上运行也遇到这个问题,这是去年的事了,后来解决了,但是怎么解决的忘了,到现在在我机子上完全可以运行,但是仍到2003服务器上就不行了。
wuyq11 2011-02-22
  • 打赏
  • 举报
回复
什么系统
mmrwbb16 2011-02-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]

修改应用程序池的标识为本地系统
DCOMCNFG中配置,修改标识为本地用户
[/Quote]
DCOMCNFG中word的标识只有“交互式用户”,“启动用户”,“下列用户(密码访问)”
我试了3种 都不行
mmrwbb16 2011-02-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]

修改应用程序池的标识为本地系统
DCOMCNFG中配置,修改标识为本地用户
[/Quote]

我的是WinForm程序,跟应用池应该没关系吧?
组件服务权限全部加上了 不管用不用的用户也加上了 一共十几个用户组 全加满了 还是不行。

泪奔啊 现在我机器上运行可以(去年遇到过这个问题,解决了),而仍到服务器上就不行了。
ChrisAK 2011-02-22
  • 打赏
  • 举报
回复
...先换个路径试试
wuyq11 2011-02-22
  • 打赏
  • 举报
回复
修改应用程序池的标识为本地系统
DCOMCNFG中配置,修改标识为本地用户

110,580

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧