unit GridExport;
{PUBDIST}

interface

uses
  IWAppForm, IWApplication, IWTypes, Classes, Controls, IWControl,
  IWWebGrid, IWAdvWebGrid, IWCompButton, IWCompLabel, IWBaseControl,
  LeftFrame, Forms, TopFrame, IWVCLBaseControl, IWBaseHTMLControl,
  IWAdvWebGridExcel, tmsiwUFlxFormats, ImgList, SysUtils;

type
  TformGridExport = class(TIWAppForm)
    TIWAdvWebGrid1: TTIWAdvWebGrid;
    IWLabel1: TIWLabel;
    FrameTopFrame1: TFrameTopFrame;
    FrameLeftFrame1: TFrameLeftFrame;
    TIWAdvWebGridExcelIO1: TTIWAdvWebGridExcelIO;
    IWButtonExport: TIWButton;
    ImageList1: TImageList;
    procedure IWAppFormCreate(Sender: TObject);
    procedure IWButtonExportClick(Sender: TObject);
    procedure TIWAdvWebGridExcelIO1CellFormat(Sender: TTIWCustomWebGrid;
      const GridCol, GridRow, XlsCol, XlsRow: Integer; const Value: WideString;
      var Format: TFlxFormat);
  public

  end;

implementation
{$R *.dfm}

uses
  ServerController;

procedure TformGridExport.IWAppFormCreate(Sender: TObject);
var
  I: Integer;
begin

  for I := 0 to TIWAdvWebGrid1.TotalRows - 1 do
  begin
    TIWAdvWebGrid1.Cells[0,I] := IntToStr(Random(3));
  end;


  with tiwadvwebgrid1 do
  begin
    cells[1,0] := 'BMW';
    cells[2,0] := '330ci';
    cells[3,0] := '289';
    cells[4,0] := '1/8/2000';
    cells[5,0] := '45000';

    cells[1,1] := 'Mercedes';
    cells[2,1] := 'SLK 200';
    cells[3,1] := '164';
    cells[4,1] := '5/4/1996';
    cells[5,1] := '39000';

    cells[1,2] := 'Audi';
    cells[2,2] := 'TT';
    cells[3,2] := '225';
    cells[4,2] := '10/10/1999';
    cells[5,2] := '32000';

    cells[1,3] := 'Ferrari';
    cells[2,3] := 'F355';
    cells[3,3] := '476';
    cells[4,3] := '1/1/1995';
    cells[5,3] := '132000';

    cells[1,4] := 'Porsche';
    cells[2,4] := '911';
    cells[3,4] := '380';
    cells[4,4] := '1/10/1997';
    cells[5,4] := '75000';

    cells[1,5] := 'Mercedes';
    cells[2,5] := 'SLR';
    cells[3,5] := '576';
    cells[4,5] := '1/1/2003';
    cells[5,5] := '250000';

    cells[1,6] := 'Lotus';
    cells[2,6] := 'Elise';
    cells[3,6] := '122';
    cells[4,6] := '5/7/1998';
    cells[5,6] := '41000';

    cells[1,7] := 'Wiessman';
    cells[2,7] := 'MF';
    cells[3,7] := '193';
    cells[4,7] := '1/6/1997';
    cells[5,7] := '60000';

    cells[1,8] := 'Maserati';
    cells[2,8] := '4200 GT';
    cells[3,8] := '390';
    cells[4,8] := '25/12/2000';
    cells[5,8] := '85000';

    cells[1,9] := 'Lamborghini';
    cells[2,9] := 'Murcielago';
    cells[3,9] := '580';
    cells[4,9] := '16/3/2002';
    cells[5,9] := '224000';

  end;
end;

procedure TformGridExport.IWButtonExportClick(Sender: TObject);
begin
  TIWAdvWebGridExcelIO1.XLSExport('TMSGridExport.xls', WebApplication);
end;

procedure TformGridExport.TIWAdvWebGridExcelIO1CellFormat(
  Sender: TTIWCustomWebGrid; const GridCol, GridRow, XlsCol, XlsRow: Integer;
  const Value: WideString; var Format: TFlxFormat);
begin
    if GridCol = 5 then
      Format.Format := '$ #,##0';
end;

initialization
  TformGridExport.SetAsMainForm;

end.
