stringgrid加excel的问题,100分,答对了再加!(100分)

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

cz_liusen

Unregistered / Unconfirmed
GUEST, unregistred user!
我想把两个stringgrid中的内容导入到一个自己创建的excel中,先把stringgrid1中的内容导入到excel中这个我会,现在的问题是如何把stringgrid2中的内容接着stringgrid1的内容继续导入到同一个excel中
 
使用OLE可以对Excel进行每个单元格的控制
 
我没有用OLE,我是直接创建了一个EXCEL,只是想把两个stringgrid中的内容导入到这个EXCEL中,而且是先导入stringgrid1,再导入stringgrid2
 
导入stringgrid1后,将EXCEL文件保存,然后再打开,将stringgrid2的内容导进.
 
还是使用XLSREADWRITE控件吧,想怎么写XLS都可以。
 
各位高人:我要的是不间断的同时导入,不能关掉EXCEL再打开,只能按一下导入键
 
1.保存后再打开全部在导入键事件里做啊.外面是看不出的.
2.还是对每个单元格进行操作吧
 
能给点源代码吗
 
stringgrid1循环后再stringgrid2循环
 
给点代码吧
 
procedure ExportStrGrid(fileType : TfileType;stringgrid : TStringGrid;SaveFileName : string);
var
ExcelApp: Variant;
Arow,Acol : Word;
stringlist : TStringlist;
lines : string;
begin
case fileType of
Excel : begin
try
ExcelApp := Createoleobject('Excel.Application');
ExcelApp.workbooks.add;
except
raise Exception.Create('你没有安装Excel!');
end;
for Arow := 0 to stringgrid.RowCount-1 do
for Acol := 0 to stringgrid.ColCount-1 do
ExcelApp.worksheets['sheet1'].cells[arow+1,Acol+1].value := stringgrid.Cells[Acol,arow];
ExcelApp.activeworkbook.saveas(savefilename);
ExcelApp.activeworkbook.close;
end;
txt : begin
stringlist := TStringlist.Create;
for Arow := 0 to stringgrid.RowCount-1 do
begin
lines := '';
for Acol := 0 to stringgrid.ColCount-1 do
lines := lines+stringgrid.Cells[Acol,arow]+' , ';
stringlist.Add(lines);
end;
stringlist.SaveToFile(SaveFileName);
stringlist.Free;
end;
end;
end;
 
请解释一下这段程序什么意思
 
后退
顶部