一个简单的数据类型问题(在线等待)(50分)

C

cl_zhx

Unregistered / Unconfirmed
GUEST, unregistred user!
我想把Excel表中的多行数据导入到StringGrid中(如果Excel表中第一列数据为空时结束
导入我的程序代码如下但在 while sheet.cells[i,1]<>'' do 行有错误请指点多谢)

procedure TForm1.Button1Click(Sender: TObject);
var
filename:variant;
sheet:variant;
i:integer;
begin
try
ExcelApplication1.Connect ;
opendialog1.Execute ;
filename:=opendialog1.FileName ;
ExcelApplication1.Visible [0]:=false;
ExcelApplication1.Workbooks.Add(filename,0);

sheet:= ExcelApplication1.Workbooks[1].Worksheets [1];
i:=1

while sheet.cells[i,1]<>'' do //
begin
SGrid1.Cells [0,i]:=sheet.cells[i,1];
SGrid1.Cells [1,i]:=sheet.cells[i,2];
SGrid1.Cells [2,i]:=sheet.cells[i,3];
SGrid1.Cells [3,i]:=sheet.cells[i,4];
i:=i+1;
end;
finally
end;
ExcelApplication1.Quit ;
ExcelApplication1.Destroy ;
end;

end.
 
sheet.cells[i,1]是Excel表中的一个单元格数据请问它的数据类型
 
^_^是不是编译出错?
你的问题是i:=1后面没有【;】
 
to vecm
谢谢
我写错了
i:=1后有;
while sheet.cells[i,1]<>'' 也写错了
是while sheet.cells[i,1]<>'
编译出的错是sheet.cells[i,1]不是String类型
 
我用你的代码试了试,就是在i:=1后加个【;】编译通过,没有问题!
我给你贴一下,【Delphi6+Updata2、Win98】
procedure TForm1.Button1Click(Sender: TObject);
var
filename:variant;
sheet:variant;
i:integer;
begin
try
ExcelApplication1.Connect ;
opendialog1.Execute ;
filename:=opendialog1.FileName ;
ExcelApplication1.Visible [0]:=false;
ExcelApplication1.Workbooks.Add(filename,0);

sheet:= ExcelApplication1.Workbooks[1].Worksheets [1];
i:=1;

while sheet.cells[i,1]<>'' do //
begin
SGrid1.Cells [0,i]:=sheet.cells[i,1];
SGrid1.Cells [1,i]:=sheet.cells[i,2];
SGrid1.Cells [2,i]:=sheet.cells[i,3];
SGrid1.Cells [3,i]:=sheet.cells[i,4];
i:=i+1;
end;
finally
end;
ExcelApplication1.Quit ;
ExcelApplication1.Destroy ;
end;
 
改成 sheet.cells[i,1].value<>''
 
to vecm
编译是可以通过,但运行时出错;
to HunterTeam
编译可以通过,但运行时死机
我Delphi6+win2000 sp3
 
你只能是你的office有问题,我也遇到过!
 
to bbs-wqt
我用vb做为什莫可以
 
经我试验还是数据类型的问题是Null数据类型与String数据类型不匹配
请问如何将Null转化为String
是用
if Object is nil then
Str:='';
else
Str:=Object;
end;
还是用
if Object is Null then
Str:='';
else
Str:=Object;
end;
还是用
if Object=nil then
Str:='';
else
Str:=Object;
end;

 
procedure TForm1.Button1Click(Sender: TObject);
var
filename:variant;
sheet:variant;
i:integer;
s:string;
begin
try
ExcelApplication1.Connect ;
opendialog1.Execute ;
filename:=opendialog1.FileName ;
ExcelApplication1.Visible [0]:=false;
ExcelApplication1.Workbooks.Add(filename,0);

sheet:= ExcelApplication1.Workbooks[1].Worksheets [1];
i:=1;
s:=sheet.cells[i,1];
while s<>'' do //
begin
SGrid1.Cells [0,i]:=sheet.cells[i,1];
SGrid1.Cells [1,i]:=sheet.cells[i,2];
SGrid1.Cells [2,i]:=sheet.cells[i,3];
SGrid1.Cells [3,i]:=sheet.cells[i,4];
i:=i+1;
s:=sheet.cells[i,1];
end;
finally
end;
ExcelApplication1.Quit ;
ExcelApplication1.Destroy ;
end;

多几句话,就行了。
我想我认识你。
 
我想问一下,INTERBASE的配置问题,我是WIN2000个人版本,DELPHI6,怎样实现客户端和服务器
端的连接,有关文档我已经看了,可是还是连接不上。
 
to lhl20000
谢谢
问题解决了
我想你还是不认识我如果你认识我的话你就知道我有多菜,你就不会问我那个问题了
 
给分,我已经没分了.
记得给我发邮件:
LHL19770714@YAHOO.COM.CN
 
接受答案了.
 

Similar threads

I
回复
0
查看
807
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
559
import
I
顶部