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'
ClientHeight = 649
ClientWidth = 894
OnCreate = FormCreate
ShowHint = True
LCLVersion = '1.5'
LCLVersion = '1.7'
object Panel1: TPanel
Left = 0
Height = 41
@ -76,16 +77,19 @@ object Form1: TForm1
Height = 572
Top = 36
Width = 894
AutoCalc = True
FrozenCols = 0
FrozenRows = 0
ReadFormulas = False
WorkbookSource = WorksheetGrid.internal
Align = alClient
AutoAdvance = aaDown
ColCount = 27
ColCount = 10
DefaultColWidth = 64
DefaultRowHeight = 22
MouseWheelOption = mwGrid
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goThumbTracking, goDblClickAutoSize, goSmoothScroll, goHeaderHotTracking, goHeaderPushedLook, goFixedColSizing]
RowCount = 101
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goThumbTracking, goDblClickAutoSize, goSmoothScroll, goHeaderHotTracking, goHeaderPushedLook, goFixedColSizing, goCellHints]
RowCount = 10
TabOrder = 1
TitleStyle = tsNative
end
@ -124,11 +128,6 @@ object Form1: TForm1
Text = 'Sheet 1'
end
end
object sWorkbookSource1: TsWorkbookSource
AutoDetectFormat = False
FileFormat = sfExcel8
Options = []
end
object OpenDialog: TOpenDialog
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 (*.*)|*.*'

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Menus, ExtCtrls, ActnList, Spin, Buttons, ButtonPanel,
fpspreadsheetgrid, fpspreadsheet, fpsallformats, fpspreadsheetctrls;
fpspreadsheetgrid, fpsallformats;
type
@ -26,12 +26,12 @@ type
Panel1: TPanel;
Panel2: TPanel;
SaveDialog: TSaveDialog;
sWorkbookSource1: TsWorkbookSource;
WorksheetGrid: TsWorksheetGrid;
procedure BtnNewClick(Sender: TObject);
procedure BtnOpenClick(Sender: TObject);
procedure BtnSaveClick(Sender: TObject);
procedure BtnEnterTextClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SheetsComboSelect(Sender: TObject);
private
{ private declarations }
@ -46,7 +46,7 @@ var
implementation
uses
fpcanvas, fpsutils, fpsRegFileFormats;
fpcanvas, fpstypes, fpsutils, fpsRegFileFormats, fpspreadsheet;
{ TForm1 }
@ -147,6 +147,60 @@ begin
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);
begin
WorksheetGrid.Worksheet.WriteText(109, 27, EdNewCellText.Text);

View File

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