读书人

wordApp.Documents.Open()获不到对象

发布时间: 2013-01-23 10:44:49 作者: rapoo

wordApp.Documents.Open()获不到对象 请大神求救

bool isSucceed = false;
Word.WdExportFormat fileFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF;
Word._Application wordApp = null;
if (wordApp == null)
{
wordApp = new Word.Application();
}
Word._Document wordDoc = null;

try
{
wordDoc = wordApp.Documents.Open(fileName); wordDoc.ExportAsFixedFormat(outputFileName, fileFormat);
isSucceed = true;
}
为什么WordDoc的值为空,fileName的值是存在的,权限我也设置了。
[解决办法]
从你的代码上看,都是空值啊。 能设断点吗?
[解决办法]
试试:

wordApp.Documents.Open(ref templateFile, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,                                            ref Nothing, ref Nothing, ref Visible, ref Nothing, ref Nothing, ref Nothing, ref Nothing);

http://www.cnblogs.com/jin256/archive/2012/02/17.html
[解决办法]
用office组件编程有时也受服务器DCOM设置的影响。遇到过,在本地运行没问题,到了服务器就返回空。后来就抛弃了这种方式,改用OpenXML,如果是offcie2007以上,建议用OpenXML,开源的,很多基本操作开发人员都组了例子。

读书人网 >行业软件

热点推荐