请问如何在excelsheet中得到excel表格的行数(30分)

  • 主题发起人 主题发起人 cuijingjun
  • 开始时间 开始时间
C

cuijingjun

Unregistered / Unconfirmed
GUEST, unregistred user!
请问我想得到excel表格的行数,用了以下语句:
ExcelWorksheet1.Used.Range.Rows.Count;
但编译时报错:
[Error] : '[' expected but '.' found
原因是什麽?请大虾指点!
 
ExcelWorksheet1.UsedRange.Rows.Count;
注意应该是UsedRange而不是Used.Range
 
黄忠伟:
对不起!是我写错了,我写的就是:
ExcelWorksheet1.UsedRange.Rows.Count;
但编译报错
 
ExcelWorksheet1.UsedRange.Rows.Count ;
好象应该是这样。
 
弄影:
i代表什麽哪?
 
已测试过:
MsExcel := CreateOleObject('Excel.Application');
WorkBook := MsExcel.Application;
if openDialog1.Execute then
Fname:=openDialog1.FileName;
WorkBook.WorkBooks.Open(Fname);
WorkBook.Visible := False;
// MsExcel.Visible := True;
WorkSheet := WorkBook.ActiveSheet;
with stringgrid1 do begin
rowcount:=WorkSheet.UsedRange.Rows.count; //得到实际行数
colcount:=WorkSheet.UsedRange.Columns.Count+1;
end;
 
谢谢linsb,但我用的是delphi自带的控件excelapplication,excelsheet,excelbook
不知道他们之间是否有区别?
请各位关注!
 
lcid: integer;
......

ExcelApplication1.Workbooks.Open(Filename, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, lcid);
lcid := GetUserDefaultLCID;
ExcelApplication1.Visible[lcid] := True;
WkBk.ConnectTo(ExcelApplication1.Workbooks[1]);
WS.ConnectTo(WkBk.Worksheets[1] as _Worksheet);
RowCount:=WS.UsedRange[LCID].Rows.Count;
ColCount:=WS.UsedRange[LCID].Columns.Count;
 
后退
顶部