如何仅读取Excel文件中使用的行

如何仅读取Excel文件中使用的行,excel,vb6,Excel,Vb6,我想以只需取出使用过的行的方式读取Excel文件,即如果Excel文件最初包含47行,但只填充了10行,则必须读取10行数据(不想在读取时像A2C7一样提及,默认情况下需要这样做),是否可以在VB 6.0中实现。请帮助我解决此问题 Used Range Property has worked for me,but now i found another problem While using this method ,if i add a value in a row after the

我想以只需取出使用过的行的方式读取Excel文件,即如果Excel文件最初包含47行,但只填充了10行,则必须读取10行数据(不想在读取时像A2C7一样提及,默认情况下需要这样做),是否可以在VB 6.0中实现。请帮助我解决此问题

   Used Range Property has worked for me,but now i found another problem While using this method ,if i add a value in a row after the last used row and remove the value at once and saves the file , it is showing the wrong usedRange value (i.e) it is showing the address of the row where i added and removed the value at once.how to handle this?

尝试在循环中读取,直到行不为空(已使用)。您可以通过以下语法使用行计数:

<workbookname>.Sheets("<SheetName>").UsedRange.Rows.Count

查看
工作表
对象的
UsedRange
属性。我不确定您是否了解Excel如何存储行。你想得太多了。对您来说,最简单的方法可能是读取行中的数据,直到找到一个空行,然后停止。
Workbook1.Sheets("Sheet1").UsedRange.Rows.Count