var
ExcelApp : Variant;
sheet : Variant;
ExcelRowCount : integer; //Excel行数
ExcelColCount : integer; //Excel列数
i : integer; //行变量
j : integer; //列变量
str : String;
WBK : OleVariant;
begin
if Edit1.Text = '' then
showmessage('首先选择要导入的Excel文件')
else
begin
//导入数据到DBGrid
ExcelApp:=CreateOleObject('Excel.Application'); //建立Excel对象
WBK := ExcelApp.WorkBooks.Open(Edit1.Text); //打开指定文件
sheet := ExcelApp.WorkSheets[1];
ExcelApp.Visible := False; //不显示Excel
ExcelRowCount := ExcelApp.WorkSheets[1].UsedRange.Rows.Count; //行数
ExcelColCount := ExcelApp.WorkSheets[1].UsedRange.Columns.Count; //列数
showmessage(inttostr(ExcelColCount));
for i := 1 to ExcelRowCount do
begin
for j := 1 to ExcelColCount do
begin
str := sheet.cells[j,i];
showmessage('第'+inttostr(i)+'行,第'+inttostr(j)+'列的值为'+str);
stringgrid1.Cells[j-1,i-1] := str;
end;
stringgrid1.RowCount := StringGrid1.RowCount + 1;
end;
WBK.Close(SaveChanges := True);
end;
end;把Excel的前5行删了,Excel导入Stringgrid后还是只显示前5行,奇怪了,不知道为什么。
ExcelApp : Variant;
sheet : Variant;
ExcelRowCount : integer; //Excel行数
ExcelColCount : integer; //Excel列数
i : integer; //行变量
j : integer; //列变量
str : String;
WBK : OleVariant;
begin
if Edit1.Text = '' then
showmessage('首先选择要导入的Excel文件')
else
begin
//导入数据到DBGrid
ExcelApp:=CreateOleObject('Excel.Application'); //建立Excel对象
WBK := ExcelApp.WorkBooks.Open(Edit1.Text); //打开指定文件
sheet := ExcelApp.WorkSheets[1];
ExcelApp.Visible := False; //不显示Excel
ExcelRowCount := ExcelApp.WorkSheets[1].UsedRange.Rows.Count; //行数
ExcelColCount := ExcelApp.WorkSheets[1].UsedRange.Columns.Count; //列数
showmessage(inttostr(ExcelColCount));
for i := 1 to ExcelRowCount do
begin
for j := 1 to ExcelColCount do
begin
str := sheet.cells[j,i];
showmessage('第'+inttostr(i)+'行,第'+inttostr(j)+'列的值为'+str);
stringgrid1.Cells[j-1,i-1] := str;
end;
stringgrid1.RowCount := StringGrid1.RowCount + 1;
end;
WBK.Close(SaveChanges := True);
end;
end;把Excel的前5行删了,Excel导入Stringgrid后还是只显示前5行,奇怪了,不知道为什么。
解决方案 »
- 【求助】delphi 改写看雪论坛“vista.win7 32/64 session隔离注入” 出错
- VLC播放器里面的LibVLC.dll调用问题
- quickRep没法打印
- 请教各位高手,有谁知道深圳市宝腾互联科技有限公司(万分感谢)
- 在线求9!!!如何在PB中调用Delphi编写的Dll
- 请问各位大虾,有关COM组件调试问题
- 大四学生朋友过来阿!
- FastReport报表控件安装问题.
- 求解?数据库无法删除是何原因?
- 如何开发多语言版本的软件!
- 新手求助,如何使用动态链接库?
- ********************新手有关access的ole字段如何写sql查询和插入语句的问题**********
这个有没有关系?
stringgrid的单元格内容是[列,行]