使用Workbooks.Open读取excel文件时出错,SOS

Jerzy 2007-08-20 04:44:47
。。。。。。
Excel.ApplicationClass app = new Excel.ApplicationClass();
Excel.WorkbookClass workBook = (Excel.WorkbookClass)app.Workbooks(Path,
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);

报如下错误:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in excel2txt.exe

Additional information: Old format or invalid type library.

请问是怎么回事啊,编译没错的阿

...全文
403 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwh_gsww 2007-08-20
  • 打赏
  • 举报
回复
加这个

_Application xlApp = null;
_Workbook xlWorkbook = null;
_Worksheet xlWorksheet = null;
System.Reflection.Missing oMissing = System.Reflection.Missing.Value;
lwh_gsww 2007-08-20
  • 打赏
  • 举报
回复
试试这个方法:

public Boolean open(String fileName)
{
try
{
xlApp = new ApplicationClass();
//xlApp.Visible = true;
xlApp.Visible = false;
xlApp.DisplayAlerts = false;
xlWorkbook = xlApp.Workbooks.Open(fileName, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
xlWorksheet = (_Worksheet)xlWorkbook.Sheets[1];
return true;
}
catch (Exception ex)
{
return false;
}
}
Jerzy 2007-08-20
  • 打赏
  • 举报
回复
SOS
Jerzy 2007-08-20
  • 打赏
  • 举报
回复
我也尝试了下面方式也报同样的错误:

Excel.Workbook workBook = app.Workbooks.Open(Path,
0,
true,
5,
"",
"",
true,
Excel.XlPlatform.xlWindows,
"\t",
false,
false,
0,
true,
1,
0);
Jerzy 2007-08-20
  • 打赏
  • 举报
回复
我用的就是11.0的,奇怪了,急啊我
shino_wu 2007-08-20
  • 打赏
  • 举报
回复
OWC组件是不是太旧了哦,用11.0代替

110,538

社区成员

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

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

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