读Excel行数出错

lingjue_83 2008-11-05 02:50:09
excelApp = new Microsoft.Office.Interop.Excel.Application();
excelWBs = excelApp.Workbooks;
excelWB = excelWBs.Add(Type.Missing);
excelWB = excelApp.Workbooks.Open(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excelSheets = excelWB.Sheets;
excelWSheet = excelSheets.get_Item(1) as Excel._Worksheet;
excelWSheet.Activate();
range = excelWSheet.UsedRange;
int intRowCount = range.Rows.Count;

为什么明明我的Excel文件里面只用了5行,但是intRowCount返回的却是15行,哪位高手能帮忙看看到底哪里出了问题?有什么方法可以解决吗?
...全文
71 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
春天的气息 2008-11-05
  • 打赏
  • 举报
回复
没有这样的函数,你可以从读取空值来判断,没好的办法!
lingjue_83 2008-11-05
  • 打赏
  • 举报
回复
谢谢哦,有没有不用自己判断的函数啊?
gomoku 2008-11-05
  • 打赏
  • 举报
回复
Excel的UsedRange并不是很准确,它还包括那些曾经输入过后来清空的单元。
或许你要自己取值进行判断。

110,534

社区成员

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

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

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