软件中用到3个stringgrid,期中有两个可以保存成EXE且有数据,另一个可以保存但没数据procedure Temailqunfa.Button7Click(Sender: TObject);
var
  ExcelApp,workbook,sheet:Variant;
  i:integer;
  begin
    ExcelApp:=UnAssigned();
    ExcelApp:= CreateOleObject('Excel.application');
    workbook := ExcelApp.WorkBooks.Add;             
    Sheet := ExcelApp.Sheets[1];                   
    for i:=1 to stringgrid1.RowCount-1 do
    begin
    Sheet.cells[i,1].value := stringgrid1.Cells[1,i]; 
    Sheet.cells[i,2].value := stringgrid1.Cells[2,i];
    Sheet.cells[i,3].value := stringgrid1.Cells[3,i];
    end;
    if savedialog1.Execute then
    begin
    try
      ExcelApp.ActiveWorkbook.saveas(savedialog1.FileName);
    except
      exit;
    end;
    end
    else
    ExcelApp.ActiveWorkBook.Saved := True;    workbook.Close;  
    ExcelApp.quit; 
    ExcelApp := unassigned;
  end;
以上程序可以保存但没有数据,但改成另一个stringgrid又可以保存,奇怪想了两天也没找出问题,高手帮看一下。
 for i:=1 to stringgrid2.RowCount-1 do
    begin
    Sheet.cells[i,1].value := stringgrid2.Cells[1,i]; 
    Sheet.cells[i,2].value := stringgrid2.Cells[2,i];
    Sheet.cells[i,3].value := stringgrid2.Cells[3,i];
    end;
或者
 for i:=1 to findstringgrid.RowCount-1 do
    begin
    Sheet.cells[i,1].value := findstringgrid.Cells[1,i]; 
    Sheet.cells[i,2].value := findstringgrid.Cells[2,i];
    Sheet.cells[i,3].value := findstringgrid.Cells[3,i];
    end;
这两个都可以保存,源码一样只是所选的stringgrid不一样而已,百思不明