fpspreadsheet: Reactivate usage of ColCount and RowCount in the WorksheetGrid. Add cell content to fpsgrid demo (designtime version).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4447 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-01-20 21:05:02 +00:00
parent a352efef12
commit 7940866bb5
3 changed files with 94 additions and 49 deletions

View File

@ -6,8 +6,9 @@ object Form1: TForm1
Caption = 'fpsGrid' Caption = 'fpsGrid'
ClientHeight = 649 ClientHeight = 649
ClientWidth = 894 ClientWidth = 894
OnCreate = FormCreate
ShowHint = True ShowHint = True
LCLVersion = '1.5' LCLVersion = '1.7'
object Panel1: TPanel object Panel1: TPanel
Left = 0 Left = 0
Height = 41 Height = 41
@ -76,16 +77,19 @@ object Form1: TForm1
Height = 572 Height = 572
Top = 36 Top = 36
Width = 894 Width = 894
AutoCalc = True
FrozenCols = 0 FrozenCols = 0
FrozenRows = 0 FrozenRows = 0
ReadFormulas = False ReadFormulas = False
WorkbookSource = WorksheetGrid.internal WorkbookSource = WorksheetGrid.internal
Align = alClient Align = alClient
AutoAdvance = aaDown AutoAdvance = aaDown
ColCount = 27 ColCount = 10
DefaultColWidth = 64
DefaultRowHeight = 22
MouseWheelOption = mwGrid MouseWheelOption = mwGrid
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goThumbTracking, goDblClickAutoSize, goSmoothScroll, goHeaderHotTracking, goHeaderPushedLook, goFixedColSizing] Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goThumbTracking, goDblClickAutoSize, goSmoothScroll, goHeaderHotTracking, goHeaderPushedLook, goFixedColSizing, goCellHints]
RowCount = 101 RowCount = 10
TabOrder = 1 TabOrder = 1
TitleStyle = tsNative TitleStyle = tsNative
end end
@ -124,11 +128,6 @@ object Form1: TForm1
Text = 'Sheet 1' Text = 'Sheet 1'
end end
end end
object sWorkbookSource1: TsWorkbookSource
AutoDetectFormat = False
FileFormat = sfExcel8
Options = []
end
object OpenDialog: TOpenDialog object OpenDialog: TOpenDialog
DefaultExt = '.xls' DefaultExt = '.xls'
Filter = 'Excel spreadsheet (*.xls)|*.xls|Excel XML spreadsheet (*.xlsx)|*.xlsx|LibreOffice/OpenOffice spreadsheet (*.ods)|*.ods|Wikitable (pipes) (.wikitable_pipes)|.wikitable_pipes|All files (*.*)|*.*' Filter = 'Excel spreadsheet (*.xls)|*.xls|Excel XML spreadsheet (*.xlsx)|*.xlsx|LibreOffice/OpenOffice spreadsheet (*.ods)|*.ods|Wikitable (pipes) (.wikitable_pipes)|.wikitable_pipes|All files (*.*)|*.*'

View File

@ -7,7 +7,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Menus, ExtCtrls, ActnList, Spin, Buttons, ButtonPanel, StdCtrls, Menus, ExtCtrls, ActnList, Spin, Buttons, ButtonPanel,
fpspreadsheetgrid, fpspreadsheet, fpsallformats, fpspreadsheetctrls; fpspreadsheetgrid, fpsallformats;
type type
@ -26,12 +26,12 @@ type
Panel1: TPanel; Panel1: TPanel;
Panel2: TPanel; Panel2: TPanel;
SaveDialog: TSaveDialog; SaveDialog: TSaveDialog;
sWorkbookSource1: TsWorkbookSource;
WorksheetGrid: TsWorksheetGrid; WorksheetGrid: TsWorksheetGrid;
procedure BtnNewClick(Sender: TObject); procedure BtnNewClick(Sender: TObject);
procedure BtnOpenClick(Sender: TObject); procedure BtnOpenClick(Sender: TObject);
procedure BtnSaveClick(Sender: TObject); procedure BtnSaveClick(Sender: TObject);
procedure BtnEnterTextClick(Sender: TObject); procedure BtnEnterTextClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SheetsComboSelect(Sender: TObject); procedure SheetsComboSelect(Sender: TObject);
private private
{ private declarations } { private declarations }
@ -46,7 +46,7 @@ var
implementation implementation
uses uses
fpcanvas, fpsutils, fpsRegFileFormats; fpcanvas, fpstypes, fpsutils, fpsRegFileFormats, fpspreadsheet;
{ TForm1 } { TForm1 }
@ -147,6 +147,60 @@ begin
end; end;
end; end;
procedure TForm1.FormCreate(Sender: TObject);
const
THICK_BORDER: TsCellBorderStyle = (LineStyle: lsThick; Color: clNavy);
MEDIUM_BORDER: TsCellBorderSTyle = (LineStyle: lsMedium; Color: clRed);
DOTTED_BORDER: TsCellBorderSTyle = (LineStyle: lsDotted; Color: clRed);
begin
// Add some cells and formats
WorksheetGrid.ColWidths[1] := 180;
WorksheetGrid.ColWidths[2] := 100;
WorksheetGrid.Cells[1,1] := 'This is a demo';
WorksheetGrid.MergeCells(1,1, 2,1);
WorksheetGrid.HorAlignment[1,1] := haCenter;
WorksheetGrid.CellBorders[1,1, 2,1] := [cbSouth];
WorksheetGrid.CellBorderStyles[1,1, 2,1, cbSouth] := THICK_BORDER;
WorksheetGrid.BackgroundColors[1,1, 2,1] := RGBToColor(220, 220, 220);
WorksheetGrid.CellFontColor[1,1] := clNavy;
WorksheetGrid.CellFontStyle[1,1] := [fssBold];
WorksheetGrid.Cells[1,2] := 'Number:';
WorksheetGrid.HorAlignment[1,2] := haRight;
WorksheetGrid.CellFontStyle[1,2] := [fssItalic];
WorksheetGrid.CellFontColor[1,2] := clNavy;
WorksheetGrid.Cells[2,2] := 1.234;
WorksheetGrid.Cells[1,3] := 'Date:';
WorksheetGrid.HorAlignment[1,3] := haRight;
WorksheetGrid.CellFontStyle[1,3] := [fssItalic];
WorksheetGrid.CellFontColor[1,3] := clNavy;
WorksheetGrid.NumberFormat[2,3] := 'mmm dd, yyyy';
WorksheetGrid.Cells[2,3] := date;
WorksheetGrid.Cells[1,4] := 'Time:';
WorksheetGrid.HorAlignment[1,4] := haRight;
WorksheetGrid.CellFontStyle[1,4] := [fssItalic];
WorksheetGrid.CellFontColor[1,4] := clNavy;
WorksheetGrid.NumberFormat[2,4] := 'hh:nn';
WorksheetGrid.Cells[2,4] := now();
WorksheetGrid.Cells[1,5] := 'Rich text:';
WorksheetGrid.HorAlignment[1,5] := haRight;
WorksheetGrid.CellFontStyle[1,5] := [fssItalic];
WorksheetGrid.CellFontColor[1,5] := clNavy;
WorksheetGrid.Cells[2,5] := '100 cm<sup>2</sup>';
WorksheetGrid.Cells[1,6] := 'Formula:';
WorksheetGrid.HorAlignment[1,6] := haRight;
WorksheetGrid.CellFontStyle[1,6] := [fssItalic];
WorksheetGrid.CellFontColor[1,6] := clNavy;
WorksheetGrid.Cells[2,6] := '=B2^2*PI()';
WorksheetGrid.CellComment[2,6] := 'Area of the circle with radius given in cell B2';
WorksheetGrid.NumberFormat[2,6] := '0.000';
end;
procedure TForm1.BtnEnterTextClick(Sender: TObject); procedure TForm1.BtnEnterTextClick(Sender: TObject);
begin begin
WorksheetGrid.Worksheet.WriteText(109, 27, EdNewCellText.Text); WorksheetGrid.Worksheet.WriteText(109, 27, EdNewCellText.Text);

View File

@ -50,8 +50,8 @@ type
// FOwnsWorkbook: Boolean; // FOwnsWorkbook: Boolean;
// FOwnedWorksheet: TsWorksheet; // FOwnedWorksheet: TsWorksheet;
FHeaderCount: Integer; FHeaderCount: Integer;
FInitColCount: Integer; // FInitColCount: Integer;
FInitRowCount: Integer; // FInitRowCount: Integer;
FFrozenCols: Integer; FFrozenCols: Integer;
FFrozenRows: Integer; FFrozenRows: Integer;
FEditText: String; FEditText: String;
@ -934,14 +934,16 @@ end;
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
constructor TsCustomWorksheetGrid.Create(AOwner: TComponent); constructor TsCustomWorksheetGrid.Create(AOwner: TComponent);
begin begin
FInternalWorkbookSource := TsWorkbookSource.Create(self); //AOwner); FInternalWorkbookSource := TsWorkbookSource.Create(self);
FInternalWorkbookSource.Name := 'internal'; FInternalWorkbookSource.Name := 'internal';
inherited Create(AOwner); inherited Create(AOwner);
AutoAdvance := aaDown; AutoAdvance := aaDown;
ExtendedSelect := true; ExtendedSelect := true;
FHeaderCount := 1; FHeaderCount := 1;
FInitColCount := DEFAULT_COL_COUNT; ColCount := DEFAULT_COL_COUNT + FHeaderCount;
FInitRowCount := DEFAULT_ROW_COUNT; RowCount := DEFAULT_ROW_COUNT + FHeaderCount;
// FInitColCount := DEFAULT_COL_COUNT;
// FInitRowCount := DEFAULT_ROW_COUNT;
FCellFont := TFont.Create; FCellFont := TFont.Create;
FHyperlinkTimer := TTimer.Create(self); FHyperlinkTimer := TTimer.Create(self);
FHyperlinkTimer.Interval := HYPERLINK_TIMER_INTERVAL; FHyperlinkTimer.Interval := HYPERLINK_TIMER_INTERVAL;
@ -1476,7 +1478,8 @@ end;
procedure TsCustomWorksheetGrid.DoOnResize; procedure TsCustomWorksheetGrid.DoOnResize;
begin begin
if (csDesigning in ComponentState) and (Worksheet = nil) then if (csDesigning in ComponentState) and (Worksheet = nil) then
NewWorkbook(FInitColCount, FInitRowCount); NewWorkbook(ColCount, RowCount);
// NewWorkbook(FInitColCount, FInitRowCount);
inherited; inherited;
end; end;
@ -3335,9 +3338,11 @@ begin
if AGridCol < FHeaderCount then if AGridCol < FHeaderCount then
exit; exit;
if LongInt(Worksheet.GetLastColIndex) + 1 + FHeaderCount >= FInitColCount then // if LongInt(Worksheet.GetLastColIndex) + 1 + FHeaderCount >= ColCount then //FInitColCount then
if GetGridCol(Worksheet.GetLastColIndex + 1) >= ColCount then
ColCount := ColCount + 1; ColCount := ColCount + 1;
c := AGridCol - FHeaderCount; c := GetWorksheetCol(AGridCol);
// c := AGridCol - FHeaderCount;
Worksheet.InsertCol(c); Worksheet.InsertCol(c);
UpdateColWidths(AGridCol); UpdateColWidths(AGridCol);
@ -3353,9 +3358,11 @@ begin
if AGridRow < FHeaderCount then if AGridRow < FHeaderCount then
exit; exit;
if LongInt(Worksheet.GetlastRowIndex) + 1 + FHeaderCount >= FInitRowCount then // if LongInt(Worksheet.GetlastRowIndex) + 1 + FHeaderCount >= FInitRowCount then
if GetGridRow(Worksheet.GetLastRowIndex + 1) >= RowCount then
RowCount := RowCount + 1; RowCount := RowCount + 1;
r := AGridRow - FHeaderCount; r := GetWorksheetRow(AGridRow);
// r := AGridRow - FHeaderCount;
Worksheet.InsertRow(r); Worksheet.InsertRow(r);
UpdateRowHeights(AGridRow); UpdateRowHeights(AGridRow);
@ -3620,7 +3627,6 @@ begin
inherited; inherited;
if FWorkbookSource = nil then if FWorkbookSource = nil then
Setup; Setup;
// NewWorkbook(FInitColCount, FInitRowCount);
end; end;
(* (*
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -3701,24 +3707,6 @@ procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
AWorksheetIndex: Integer); AWorksheetIndex: Integer);
begin begin
GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AWorksheetIndex); GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AWorksheetIndex);
{
if FOwnsWorkbook then
FreeAndNil(FOwnedWorkbook);
if FWorkbookSource <> nil then
FWorkbookSource.LoadFromSpreadsheetFile(AFileName, AWorksheetIndex)
else
begin
BeginUpdate;
try
CreateNewWorkbook;
Workbook.ReadFromFile(AFilename);
LoadFromWorksheet(Workbook.GetWorksheetByIndex(AWorksheetIndex));
finally
EndUpdate;
end;
end;
}
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -3968,8 +3956,10 @@ end;
procedure TsCustomWorksheetGrid.NewWorkbook(AColCount, ARowCount: Integer); procedure TsCustomWorksheetGrid.NewWorkbook(AColCount, ARowCount: Integer);
begin begin
GetWorkbookSource.CreateNewWorkbook; GetWorkbookSource.CreateNewWorkbook;
FInitColCount := AColCount; ColCount := AColCount + FHeaderCount;
FInitRowCount := ARowCount; RowCount := ARowCount + FHeaderCount;
// FInitColCount := AColCount;
// FInitRowCount := ARowCount;
Setup; Setup;
{ {
@ -4129,8 +4119,8 @@ begin
if (Worksheet = nil) or (Worksheet.GetCellCount = 0) then begin if (Worksheet = nil) or (Worksheet.GetCellCount = 0) then begin
if ShowHeaders then begin if ShowHeaders then begin
ColCount := FInitColCount + 1; //2; // ColCount := FInitColCount + 1; //2;
RowCount := FInitRowCount + 1; //2; // RowCount := FInitRowCount + 1; //2;
FixedCols := 1; FixedCols := 1;
FixedRows := 1; FixedRows := 1;
ColWidths[0] := GetDefaultHeaderColWidth; ColWidths[0] := GetDefaultHeaderColWidth;
@ -4138,15 +4128,17 @@ begin
end else begin end else begin
FixedCols := 0; FixedCols := 0;
FixedRows := 0; FixedRows := 0;
ColCount := FInitColCount; //0; // ColCount := FInitColCount; //0;
RowCount := FInitRowCount; //0; // RowCount := FInitRowCount; //0;
end; end;
end else end else
if Worksheet <> nil then begin if Worksheet <> nil then begin
Convert_sFont_to_Font(Workbook.GetDefaultFont, Font); Convert_sFont_to_Font(Workbook.GetDefaultFont, Font);
Canvas.Font.Assign(Font); Canvas.Font.Assign(Font);
ColCount := Max(integer(Worksheet.GetLastColIndex) + 1 + FHeaderCount, FInitColCount); ColCount := Max(GetGridCol(Worksheet.GetLastColIndex) + 1, ColCount);
RowCount := Max(integer(Worksheet.GetLastRowIndex) + 1 + FHeaderCount, FInitRowCount); RowCount := Max(GetGridRow(Worksheet.GetLastRowIndex) + 1, RowCount);
//ColCount := Max(integer(Worksheet.GetLastColIndex) + 1 + FHeaderCount, FInitColCount);
//RowCount := Max(integer(Worksheet.GetLastRowIndex) + 1 + FHeaderCount, FInitRowCount);
FixedCols := FFrozenCols + FHeaderCount; FixedCols := FFrozenCols + FHeaderCount;
FixedRows := FFrozenRows + FHeaderCount; FixedRows := FFrozenRows + FHeaderCount;
if ShowHeaders then begin if ShowHeaders then begin