Export TStringGrid

This code exports the contents of string grid to a worksheet.
uses
  {...}, OExport, OExport_Vcl, OExport_Vcl;

procedure ExportGrid(aGrid: TStringGrid);
var
  xExport: TOExport;
  xWS: TExportWorkSheet;
  xRow: TExportRow;
  I, L: Integer;
begin
  xExport := TOExport.Create;
  try
    xWS := xExport.AddWorkSheet('Grid');//create a worksheet

    for I := 0 to aGrid.RowCount-1 do
    begin
      xRow := xWS.AddRow;//create a row

      for L := 0 to aGrid.ColCount-1 do
      begin
        xRow.AddCellString(aGrid.Cells[L, I]);//create a new cell
      end;

      xRow.DeleteEmptyCellsFromEnd;//Delete cells from end that are not needed
    end;

    xExport.SaveToFileWithDialog('', '', True);//Save workbook with dialog, execute after the export
  finally
    xExport.Free;
  end;
end;
Categories