fpspreadsheet: Update workbookchartsource demo to show multiple-y-values feature.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9046 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-11-26 23:04:52 +00:00
parent f2d3b35380
commit baf8abdc40
5 changed files with 108 additions and 62 deletions

View File

@ -61,6 +61,9 @@
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>
<Linking> <Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
<Options> <Options>
<Win32> <Win32>
<GraphicApplication Value="True"/> <GraphicApplication Value="True"/>

View File

@ -2,22 +2,22 @@ object Form1: TForm1
Left = 256 Left = 256
Height = 618 Height = 618
Top = 127 Top = 127
Width = 828 Width = 1047
Caption = 'Form1' Caption = 'Form1'
ClientHeight = 618 ClientHeight = 618
ClientWidth = 828 ClientWidth = 1047
LCLVersion = '3.99.0.0'
OnCreate = FormCreate OnCreate = FormCreate
LCLVersion = '1.8.4.0'
object Panel1: TPanel object Panel1: TPanel
Left = 0 Left = 0
Height = 33 Height = 33
Top = 0 Top = 0
Width = 828 Width = 1047
Align = alTop Align = alTop
AutoSize = True AutoSize = True
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 33 ClientHeight = 33
ClientWidth = 828 ClientWidth = 1047
TabOrder = 0 TabOrder = 0
object BtnDeleteSheet: TButton object BtnDeleteSheet: TButton
AnchorSideLeft.Control = Panel1 AnchorSideLeft.Control = Panel1
@ -32,8 +32,8 @@ object Form1: TForm1
BorderSpacing.Right = 4 BorderSpacing.Right = 4
BorderSpacing.Bottom = 4 BorderSpacing.Bottom = 4
Caption = 'Delete sheet' Caption = 'Delete sheet'
OnClick = BtnDeleteSheetClick
TabOrder = 0 TabOrder = 0
OnClick = BtnDeleteSheetClick
end end
object BtnRenameSheet: TButton object BtnRenameSheet: TButton
AnchorSideLeft.Control = BtnDeleteSheet AnchorSideLeft.Control = BtnDeleteSheet
@ -48,15 +48,15 @@ object Form1: TForm1
BorderSpacing.Right = 4 BorderSpacing.Right = 4
BorderSpacing.Bottom = 4 BorderSpacing.Bottom = 4
Caption = 'Rename sheet' Caption = 'Rename sheet'
OnClick = BtnRenameSheetClick
TabOrder = 1 TabOrder = 1
OnClick = BtnRenameSheetClick
end end
end end
object sWorkbookTabControl1: TsWorkbookTabControl object sWorkbookTabControl1: TsWorkbookTabControl
Left = 5 Left = 5
Height = 581 Height = 581
Top = 37 Top = 37
Width = 280 Width = 475
TabIndex = 0 TabIndex = 0
Tabs.Strings = ( Tabs.Strings = (
'Sheet1' 'Sheet1'
@ -68,10 +68,12 @@ object Form1: TForm1
Left = 2 Left = 2
Height = 556 Height = 556
Top = 23 Top = 23
Width = 276 Width = 471
AutoCalc = True AutoCalc = True
FrozenCols = 0 FrozenCols = 0
FrozenRows = 0 FrozenRows = 0
PageBreakPen.Color = clBlue
PageBreakPen.Style = psDash
ReadFormulas = True ReadFormulas = True
WorkbookSource = sWorkbookSource1 WorkbookSource = sWorkbookSource1
Align = alClient Align = alClient
@ -84,10 +86,10 @@ object Form1: TForm1
end end
end end
object Panel2: TPanel object Panel2: TPanel
Left = 285 Left = 480
Height = 581 Height = 581
Top = 37 Top = 37
Width = 543 Width = 567
Align = alClient Align = alClient
BevelOuter = bvNone BevelOuter = bvNone
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
@ -97,13 +99,13 @@ object Form1: TForm1
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1 ChildSizing.ControlsPerLine = 1
ClientHeight = 581 ClientHeight = 581
ClientWidth = 543 ClientWidth = 567
TabOrder = 2 TabOrder = 2
object Chart1: TChart object Chart1: TChart
Left = 0 Left = 0
Height = 194 Height = 194
Top = 0 Top = 0
Width = 543 Width = 567
AxisList = < AxisList = <
item item
Grid.Color = clSilver Grid.Color = clSilver
@ -128,17 +130,16 @@ object Form1: TForm1
'Chart from 1st sheet' 'Chart from 1st sheet'
) )
Title.Visible = True Title.Visible = True
object Chart1AreaSeries1: TAreaSeries object Chart1LineSeries1: TLineSeries
AreaBrush.Color = clSkyBlue
AreaLinesPen.Style = psClear
Source = sWorkbookChartSource1 Source = sWorkbookChartSource1
Styles = ChartStyles1
end end
end end
object Chart2: TChart object Chart2: TChart
Left = 0 Left = 0
Height = 194 Height = 194
Top = 194 Top = 194
Width = 543 Width = 567
AxisList = < AxisList = <
item item
Grid.Color = clSilver Grid.Color = clSilver
@ -164,6 +165,9 @@ object Form1: TForm1
) )
Title.Visible = True Title.Visible = True
object Chart2BarSeries1: TBarSeries object Chart2BarSeries1: TBarSeries
BarBrush.Color = 9934847
BarWidthStyle = bwPercentMin
Depth = 6
Marks.Distance = 5 Marks.Distance = 5
Marks.Format = '%.2f' Marks.Format = '%.2f'
Marks.Frame.Visible = False Marks.Frame.Visible = False
@ -171,8 +175,6 @@ object Form1: TForm1
Marks.LinkPen.Color = clGray Marks.LinkPen.Color = clGray
Marks.OverlapPolicy = opHideNeighbour Marks.OverlapPolicy = opHideNeighbour
Marks.Style = smsCustom Marks.Style = smsCustom
BarBrush.Color = 9934847
Depth = 6
Source = sWorkbookChartSource2 Source = sWorkbookChartSource2
end end
end end
@ -180,7 +182,7 @@ object Form1: TForm1
Left = 0 Left = 0
Height = 193 Height = 193
Top = 388 Top = 388
Width = 543 Width = 567
AxisList = < AxisList = <
item item
Visible = False Visible = False
@ -208,10 +210,11 @@ object Form1: TForm1
Title.Visible = True Title.Visible = True
object Chart3PieSeries1: TPieSeries object Chart3PieSeries1: TPieSeries
Legend.Multiplicity = lmPoint Legend.Multiplicity = lmPoint
Exploded = True
MarkPositions = pmpInside
Marks.Distance = 10 Marks.Distance = 10
Marks.Format = '%2:s' Marks.Format = '%2:s'
Marks.Style = smsLabel Marks.Style = smsLabel
MarkPositions = pmpInside
Source = sWorkbookChartSource3 Source = sWorkbookChartSource3
end end
end end
@ -220,7 +223,7 @@ object Form1: TForm1
Left = 0 Left = 0
Height = 4 Height = 4
Top = 33 Top = 33
Width = 828 Width = 1047
Align = alTop Align = alTop
Shape = bsTopLine Shape = bsTopLine
end end
@ -233,22 +236,39 @@ object Form1: TForm1
object sWorkbookSource1: TsWorkbookSource object sWorkbookSource1: TsWorkbookSource
FileFormat = sfUser FileFormat = sfUser
Options = [boAutoCalc, boReadFormulas] Options = [boAutoCalc, boReadFormulas]
left = 152 Left = 152
top = 184 Top = 184
end end
object sWorkbookChartSource3: TsWorkbookChartSource object sWorkbookChartSource3: TsWorkbookChartSource
WorkbookSource = sWorkbookSource1 WorkbookSource = sWorkbookSource1
left = 544 Left = 544
top = 503 Top = 503
end end
object sWorkbookChartSource2: TsWorkbookChartSource object sWorkbookChartSource2: TsWorkbookChartSource
WorkbookSource = sWorkbookSource1 WorkbookSource = sWorkbookSource1
left = 544 Left = 544
top = 316 Top = 316
end end
object sWorkbookChartSource1: TsWorkbookChartSource object sWorkbookChartSource1: TsWorkbookChartSource
WorkbookSource = sWorkbookSource1 WorkbookSource = sWorkbookSource1
left = 544 Left = 544
top = 120 Top = 120
end
object ChartStyles1: TChartStyles
Styles = <
item
Brush.Color = clRed
Pen.Color = clRed
end
item
Brush.Color = clBlue
Pen.Color = clBlue
end
item
Brush.Color = clYellow
Pen.Color = clOlive
end>
Left = 688
Top = 120
end end
end end

View File

@ -5,9 +5,9 @@ unit mainform;
interface interface
uses uses
Classes, SysUtils, FileUtil, TAGraph, TASources, TASeries, Forms, Controls, Classes, SysUtils, FileUtil, TAGraph, TASources, TASeries, TAStyles, Forms,
Graphics, Dialogs, ExtCtrls, StdCtrls, fpspreadsheetctrls, fpspreadsheetgrid, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, fpspreadsheetctrls,
fpspreadsheetchart, fpsallformats; fpspreadsheetgrid, fpspreadsheetchart, fpsallformats;
type type
@ -16,13 +16,16 @@ type
TForm1 = class(TForm) TForm1 = class(TForm)
Bevel1: TBevel; Bevel1: TBevel;
BtnDeleteSheet: TButton; BtnDeleteSheet: TButton;
BtnRenameSheet: TButton;
Button2: TButton; Button2: TButton;
Chart1: TChart; Chart1: TChart;
Chart1AreaSeries1: TAreaSeries; Chart1AreaSeries1: TLineSeries;
Chart1LineSeries1: TLineSeries;
Chart2: TChart; Chart2: TChart;
Chart2BarSeries1: TBarSeries; Chart2BarSeries1: TBarSeries;
Chart3: TChart; Chart3: TChart;
Chart3PieSeries1: TPieSeries; Chart3PieSeries1: TPieSeries;
ChartStyles1: TChartStyles;
Panel1: TPanel; Panel1: TPanel;
Panel2: TPanel; Panel2: TPanel;
Splitter1: TSplitter; Splitter1: TSplitter;
@ -53,11 +56,14 @@ implementation
procedure TForm1.FormCreate(Sender: TObject); procedure TForm1.FormCreate(Sender: TObject);
begin begin
sWorkbookSource1.Filename := 'test-data.xlsx'; sWorkbookSource1.Filename := 'test-data.xlsx';
sWorkbookChartSource1.XRange := 'Sheet1!A2:A21';
sWorkbookChartSource1.YRange := 'Sheet1!B2:B21'; sWorkbookChartSource1.XRange := 'Sheet1!A2:A32';
sWorkbookChartSource2.XRange := 'Sheet2!A2:A16'; sWorkbookChartSource1.YRange := '(Sheet1!B2:B32) (Sheet1!C2:C32) (Sheet1!D2:D17;Sheet1!E18:E32)';
sWorkbookChartSource2.YRange := 'Sheet2!B2:B16';
sWorkbookChartSource3.XRange := 'Sheet3!A2:A5'; sWorkbookChartSource2.XRange := 'Sheet2!A2:A27';
sWorkbookChartSource2.YRange := 'Sheet2!B2:B27';
sWorkbookChartSource3.XRange := 'Sheet3!C2:C5';
sWorkbookChartSource3.YRange := 'Sheet3!B2:B5'; sWorkbookChartSource3.YRange := 'Sheet3!B2:B5';
sWorkbookChartSource3.LabelRange := 'Sheet3!A2:A5'; sWorkbookChartSource3.LabelRange := 'Sheet3!A2:A5';
end; end;

View File

@ -524,16 +524,16 @@ end;
and to worksheet changes by selecting the tab corresponding to the selected and to worksheet changes by selecting the tab corresponding to the selected
worksheet. worksheet.
@param AChangedItems Set with elements identifying whether workbook, (@param AChangedItems Set of elements identifying whether workbook,
worksheet, cell content or cell formatting has changed worksheet, cell content or cell formatting has changed)
@param AData Additional data, not used here (@param AData Additional data, contains the worksheet for worksheet-related items)
@see TsNotificationItem @see TsNotificationItem
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorkbookChartSource.ListenerNotification( procedure TsWorkbookChartSource.ListenerNotification(
AChangedItems: TsNotificationItems; AData: Pointer = nil); AChangedItems: TsNotificationItems; AData: Pointer = nil);
var var
ir, i: Integer; ir, i, j: Integer;
cell: PCell; cell: PCell;
ResetDone: Boolean; ResetDone: Boolean;
rng: TsXYLRange; rng: TsXYLRange;
@ -555,13 +555,25 @@ begin
// Used worksheet will be deleted? // Used worksheet will be deleted?
if (lniWorksheetRemoving in AChangedItems) then if (lniWorksheetRemoving in AChangedItems) then
begin
for rng in TsXYLRange do for rng in TsXYLRange do
for i := 0 to High(FWorksheets[rng]) do for i := 0 to High(FWorksheets[rng]) do
if TsWorksheet(AData) = FWorksheets[rng, i] then begin if TsWorksheet(AData) = FWorksheets[rng, i] then
FWorksheets[rng] := nil; begin
for j := i+1 to High(FWorksheets[rng]) do
FWorksheets[rng, j-1] := FWorksheets[rng, j];
SetLength(FWorkSheets[rng], Length(FWorksheets[rng])-1);
for j := i+1 to High(FRanges[rng]) do
FRanges[rng, j-1] := FRanges[rng, j];
SetLength(FRanges[rng], Length(FRanges[rng])-1);
end;
for rng in TsXYLRange do
begin
FRangeStr[rng] := BuildRangeStr(rng); FRangeStr[rng] := BuildRangeStr(rng);
Prepare(rng); Prepare(rng);
end; end;
Reset;
end;
// Cell changes: Enforce recalculation of axes if modified cell is within the // Cell changes: Enforce recalculation of axes if modified cell is within the
// x or y range(s). // x or y range(s).
@ -625,12 +637,28 @@ var
ok: Boolean; ok: Boolean;
i, j: Integer; i, j: Integer;
begin begin
if (FWorkbookSource = nil) then
begin
FPointsNumber := 0;
Reset;
exit;
end;
s := FRangeStr[AIndex];
if (s = '') then
begin
if AIndex = rngY then
begin
FPointsNumber := 0;
Reset;
exit;
end;
end;
// Split range string into parts for the individual xindex and yindex parts. // Split range string into parts for the individual xindex and yindex parts.
// Each part is enclosed by parenthesis. // Each part is enclosed by parenthesis.
// Example for two y ranges: // Example for two y ranges:
// '(A1:A10) (B1:B5;B6:B11)' --> 1st y range is A1:A10, 2nd y range is B1:B5 and B6:B11 // '(A1:A10) (B1:B5;B6:B11)' --> 1st y range is A1:A10, 2nd y range is B1:B5 and B6:B11
s := '';
s := FRangeStr[AIndex];
if (s <> '') and (s[Length(s)] = ')') then if (s <> '') and (s[Length(s)] = ')') then
Delete(s, Length(s), 1); Delete(s, Length(s), 1);
for i := 1 to Length(s) do for i := 1 to Length(s) do
@ -656,17 +684,6 @@ begin
else ; else ;
end; end;
// Trivial valdiation
if (Workbook = nil) or (not ok) then
begin
FWorksheets[AIndex] := nil;
SetLength(FRanges[AIndex], 0);
if AIndex = rngY then
FPointsNumber := 0;
Reset;
exit;
end;
// Extract range parameters and store them in FRanges // Extract range parameters and store them in FRanges
SetLength(FRanges[AIndex], Length(sa)); SetLength(FRanges[AIndex], Length(sa));
SetLength(FWorksheets[AIndex], Length(sa)); SetLength(FWorksheets[AIndex], Length(sa));
@ -682,8 +699,8 @@ begin
Reset; Reset;
end else end else
if (Workbook.GetWorksheetCount > 0) then begin if (Workbook.GetWorksheetCount > 0) then begin
if FWorksheets[AIndex] = nil then if FWorksheets[AIndex, i] = nil then
exit; raise Exception.Create('Worksheet not found in ' + sa[i]);
end; end;
end; end;
// Make sure to include worksheet name in RangeString. // Make sure to include worksheet name in RangeString.