Windows server 2008 64-bit计划任务运行使用了excel 2003 32-bit .net开发组件的程序遇到的问题
代码:
2 {
3 excelApplication = new Excel.ApplicationClass();
4 excelWorkBooks = excelApplication.Workbooks;
5 excelWorkBook = ((Excel.Workbook)excelWorkBooks.Open(excelOpenFileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value));
6 excelWorkSheet = (Excel.Worksheet)excelWorkBook.Worksheets[excelActiveWorkSheetIndex];
7 excelApplication.Visible = false;
8
9 return true;
10 }
11 catch (Exception e)
12 {
13 CloseExcelApplication();
14 MessageBox.Show("(1)没有安装Excel 2003;(2)或没有安装Excel 2003 .NET 可编程性支持;\n详细信息:"
15 +e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
16 //throw new Exception(e.Message);
17 LabMessage.Text = "(1)没有安装Excel 2003;(2)或没有安装Excel 2003 .NET 可编程性支持;\n详细信息:"+ e.Message;
18 return false;
19 }
问题:
System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
解决办法:
On 64 bit system with 32 bit Office try this:
1. Start
2. Run
3. mmc -32
4. 4.File
5. Add Remove Snap-in
6. Component Services
7. Add
8. OK
9. Console Root
10. Component Services
11. Computers
12. My Computer
13. DCOM Config
14. Microsoft Excel Application
15. 右键打开属性对话框
16. 点击"安全"选项卡,
18. 把"启动和激活权限","配置权限",都选择为自定义,
19. 然后依次点击它们的编辑,把计划任务执行用的账号添加进去,并加入所有的权限...
如果以上解决办法无效,再试试下面的:
运行dcomcnfg打开组件服务
依次展开"组件服务"->"计算机"->"我的电脑"->"DCOM配置"
找到"Microsoft Excel应用程序"
右键打开属性对话框,点击"标识"选项卡,依次选择The interactive user或者This user试试。
如果还不行,看看执行计划任务的账户是否在administrator群组中,如没有,请加入administrator群组再测试一下。