home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 October
/
Chip_2002-10_cd1.bin
/
zkuste
/
delphi
/
kolekce
/
d56
/
FLEXCEL.ZIP
/
Demo
/
UFlDemoEdit.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2002-06-15
|
3KB
|
129 lines
unit UFlDemoEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, UFlDemoData,
Grids, ComCtrls, ToolWin, UWaitCursor;
type
TDemoEdit = class(TForm)
ToolBar: TToolBar;
BtnClose: TToolButton;
BtnSave: TToolButton;
TabControl: TTabControl;
Data: TStringGrid;
procedure BtnCloseClick(Sender: TObject);
procedure BtnSaveClick(Sender: TObject);
procedure DataDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure DataSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure TabControlChange(Sender: TObject);
private
procedure GridToXls;
procedure XlsToGrid;
{ Private declarations }
public
procedure FillData;
{ Public declarations }
end;
implementation
{$R *.DFM}
{ TDemoEdit }
procedure TDemoEdit.FillData;
var
p: integer;
begin
TabControl.Tabs.Clear;
for p:=1 to DemoData.FlexCelImport.SheetCount do
begin
DemoData.FlexCelImport.ActiveSheet:=p;
TabControl.Tabs.Add(DemoData.FlexCelImport.ActiveSheetName);
end;
DemoData.FlexCelImport.ActiveSheet:=1;
TabControl.TabIndex:=DemoData.FlexCelImport.ActiveSheet-1;
XlsToGrid;
end;
procedure TDemoEdit.BtnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TDemoEdit.GridToXls;
var
i,k: integer;
e: extended;
WaitCursor: IWaitCursor;
begin
WaitCursor:=TWaitCursor.Create;
for i:=1 to Data.ColCount-1 do
for k:=1 to Data.RowCount-1 do
begin
//try to convert to number
if TextToFloat(PChar(Data.Cells[ i , k]), e, fvExtended) then //Dont use val because it doesnt handle locales
DemoData.FlexCelImport.CellValue[k,i]:=e else
DemoData.FlexCelImport.CellValue[k,i]:=Data.Cells[ i , k];
end;
end;
procedure TDemoEdit.XlsToGrid;
var
i,k: integer;
WaitCursor: IWaitCursor;
begin
WaitCursor:=TWaitCursor.Create;
Data.RowCount:=DemoData.FlexCelImport.MaxRow+2;
for i:=1 to Data.ColCount-1 do Data.Cells[ i , 0]:= chr(ord('A')+i-1);
for i:=1 to Data.RowCount-1 do Data.Cells[ 0 , i]:= IntToStr(i);
for i:=1 to Data.ColCount-1 do
for k:=1 to Data.RowCount-1 do
Data.Cells[ i , k]:= DemoData.FlexCelImport.CellValue[k,i];
end;
procedure TDemoEdit.BtnSaveClick(Sender: TObject);
begin
if not DemoData.XlsSaveDialog.Execute then exit;
if FileExists(DemoData.XlsSaveDialog.FileName) then DeleteFile(DemoData.XlsSaveDialog.FileName);
GridToXLS;
DemoData.FlexCelImport.Save(DemoData.XlsSaveDialog.FileName);
end;
procedure TDemoEdit.DataDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if DemoData.FlexCelImport.IsLoaded and (aRow>0) and (DemoData.FlexCelImport.IsEmptyRow(aRow)) and (aCol>0) then
with Sender as TStringGrid do
begin
Canvas.Brush.Color := clGray;
Canvas.FillRect(Rect);
Canvas.DrawFocusRect(Rect);
end;
end;
procedure TDemoEdit.DataSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
CanSelect:=
DemoData.FlexCelImport.IsLoaded and (not DemoData.FlexCelImport.IsEmptyRow(aRow));
end;
procedure TDemoEdit.TabControlChange(Sender: TObject);
begin
GridToXLS;
DemoData.FlexCelImport.ActiveSheet:= TabControl.TabIndex+1;
XLSToGrid;
end;
end.