// for col := 0 to StringGrid.ColumnCount - 2 do // for row := 0 to stringGrid.RowCount - 1 do // Sheet.Cells[row + 2, col + 1] := stringGrid.Cells[col, row];
for col := 0 to StringGrid.ColumnCount - 1 do for row := 0 to stringGrid.RowCount - 1 do Sheet.Cells[row + 1, col + 1] := stringGrid.Cells[col, row];
for i := 1 to 10 do begin Sheet.Cells[1, i].Font.Bold := True; // XLApp.WorkBooks[1].WorkSheets[1].Rows[i].Font.Color := clBlack; Sheet.Cells[1, i].Font.Size := 11; Sheet.Cells[1, i].Font.Name := 'Times New Roman'; end;
try XLApp.Workbooks[1].SaveAs(ExtractFilePath(ParamStr(0))+'..\..\Export\ais_'+ FormatDateTime('DD_MM_YYYY_hh_mm', Now)+'.xlsx'); Result := True; except // Error ? end; finally if not VarIsEmpty(XLApp) then begin XLApp.DisplayAlerts := False; XLApp.Quit; XLAPP := Unassigned; Sheet := Unassigned; // WinExec(PANsiChar('TASKKILL /F /IM EXCEL.exe'), SW_HIDE); end; end; end;
procedure TForm2.Button1Click(Sender: TObject); begin if SaveAsExcelFile(stringGrid1, 'd:\MyExcelFile.xls') then ShowMessage('Экспорт завершен'); end;