请教!!如何在delphi5中自动进入excel后如何在worksheet中插入字符串?(200分)

  • 主题发起人 主题发起人 李勤
  • 开始时间 开始时间

李勤

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾:
请教,在delphi5中自动进入excel后如何在worksheet中插入字符串?
我的程序如下:
procedure TForm1.Button1Click(Sender: TObject);
var
ExcelApp,ExcelWorkSheet:Variant;
sheet:oleVariant;
begin
ExcelApp:=CreateOleObject('Excel.Application');
ExcelApp.Visible:=true;
ExcelWorkSheet:=ExcelApp.workbooks.open('d:/lzqtest/aaa.xls');
sheet:=ExcelWorkSheet.sheets[1];
sheet.cells(1,1):='bb'; //这是赋值不是insert
 
string := sheet.cells(1,1);
sheet.cells(1,1):='bb' + string;
 
var
m,n: integer;
xlApp,xlSheet:olevariant;
sExePath: string;
begin
inherited;
sExePath := ExtractFilePath(Application.ExeName);
xlApp:= CreateOleObject('Excel.Application');
xlApp.visible:=true;
xlApp.WorkBooks.open(sExepath+'report/aaa.xls');
xlSheet:=xlApp.WorkBooks[1].Worksheets[2];
xlSheet.activate;
for m := 11 to 15 do
for n := 4 to 10 do
xlSheet.Cells[m,n] := FArray[m-10,n-3];
end;
这样可以在使用后将Excel释放!不会留在内存中
其中m和n分别代表你要插入数据的Excel行和列
FArray是一个数组,这样你可以将数据库中的数据写入Excel,就像报表一样
 
多谢sea026的回答,我试了一下,提示'string:=sheet.cells(1,!) '
找不到成员?
 
后退
顶部