fpspreadsheet: Add option to define series labels in TsWorkbookChartSource.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6564 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-07-22 13:58:46 +00:00
parent 00c14b31a1
commit 8096d92b8f
6 changed files with 221 additions and 223 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<Version Value="11"/> <Version Value="10"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<General> <General>
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
@@ -11,43 +11,19 @@
<UseXPManifest Value="True"/> <UseXPManifest Value="True"/>
<Icon Value="0"/> <Icon Value="0"/>
</General> </General>
<i18n> <VersionInfo>
<EnableI18N LFM="False"/> <StringTable ProductVersion=""/>
</i18n> </VersionInfo>
<BuildModes Count="2"> <BuildModes Count="1">
<Item1 Name="Debug" Default="True"/> <Item1 Name="Default" Default="True"/>
<Item2 Name="Release">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
</SearchPaths>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
</CodeGeneration>
<Linking>
<Debugging>
<StripSymbols Value="True"/>
</Debugging>
<LinkSmart Value="True"/>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
</Item2>
</BuildModes> </BuildModes>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>
</PublishOptions> </PublishOptions>
<RunParams> <RunParams>
<FormatVersion Value="2"/> <local>
<Modes Count="1"> <FormatVersion Value="1"/>
<Mode0 Name="default"/> </local>
</Modes>
</RunParams> </RunParams>
<RequiredPackages Count="3"> <RequiredPackages Count="3">
<Item1> <Item1>
@@ -69,7 +45,6 @@
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/> <ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
</Unit1> </Unit1>
</Units> </Units>
@@ -84,14 +59,7 @@
<IncludeFiles Value="$(ProjOutDir)"/> <IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
</CodeGeneration>
<Linking> <Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2Set"/>
<UseExternalDbgSyms Value="True"/>
</Debugging>
<Options> <Options>
<Win32> <Win32>
<GraphicApplication Value="True"/> <GraphicApplication Value="True"/>

View File

@@ -7,12 +7,13 @@ uses
cthreads, cthreads,
{$ENDIF}{$ENDIF} {$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset Interfaces, // this includes the LCL widgetset
Forms, mainform; Forms, tachartlazaruspkg, mainform
{ you can add units after this };
{$R *.res} {$R *.res}
begin begin
RequireDerivedFormResource := True; RequireDerivedFormResource:=True;
Application.Initialize; Application.Initialize;
Application.CreateForm(TForm1, Form1); Application.CreateForm(TForm1, Form1);
Application.Run; Application.Run;

View File

@@ -1,119 +1,119 @@
object Form1: TForm1 object Form1: TForm1
Left = 354 Left = 256
Height = 634 Height = 618
Top = 132 Top = 127
Width = 877 Width = 828
Caption = 'Form1' Caption = 'Form1'
ClientHeight = 634 ClientHeight = 618
ClientWidth = 877 ClientWidth = 828
OnCreate = FormCreate OnCreate = FormCreate
LCLVersion = '1.9.0.0' LCLVersion = '1.8.4.0'
object Panel1: TPanel object Panel1: TPanel
Left = 0 Left = 0
Height = 40 Height = 33
Top = 0 Top = 0
Width = 877 Width = 828
Align = alTop Align = alTop
AutoSize = True
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 40 ClientHeight = 33
ClientWidth = 877 ClientWidth = 828
TabOrder = 0 TabOrder = 0
object Button1: TButton object BtnDeleteSheet: TButton
Left = 8 AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1
Left = 4
Height = 25 Height = 25
Top = 7 Top = 4
Width = 91 Width = 90
AutoSize = True
BorderSpacing.Left = 4
BorderSpacing.Top = 4
BorderSpacing.Right = 4
BorderSpacing.Bottom = 4
Caption = 'Delete sheet' Caption = 'Delete sheet'
OnClick = Button1Click OnClick = BtnDeleteSheetClick
TabOrder = 0 TabOrder = 0
end end
object Button2: TButton object BtnRenameSheet: TButton
Left = 107 AnchorSideLeft.Control = BtnDeleteSheet
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = BtnDeleteSheet
AnchorSideTop.Side = asrCenter
Left = 98
Height = 25 Height = 25
Top = 7 Top = 4
Width = 93 Width = 100
AutoSize = True
BorderSpacing.Right = 4
BorderSpacing.Bottom = 4
Caption = 'Rename sheet' Caption = 'Rename sheet'
OnClick = Button2Click OnClick = BtnRenameSheetClick
TabOrder = 1 TabOrder = 1
end end
object Bevel1: TBevel
Left = 0
Height = 3
Top = 37
Width = 877
Align = alBottom
Shape = bsBottomLine
end
end
object Splitter1: TSplitter
Left = 872
Height = 594
Top = 40
Width = 5
Align = alRight
ResizeAnchor = akRight
end end
object sWorkbookTabControl1: TsWorkbookTabControl object sWorkbookTabControl1: TsWorkbookTabControl
Left = 6 Left = 5
Height = 582 Height = 581
Top = 46 Top = 37
Width = 390 Width = 280
TabIndex = 0 TabIndex = 0
Tabs.Strings = ( Tabs.Strings = (
'Sheet1' 'Sheet1'
) )
Align = alClient Align = alLeft
BorderSpacing.Around = 6 TabOrder = 1
TabOrder = 2
WorkbookSource = sWorkbookSource1 WorkbookSource = sWorkbookSource1
object sWorksheetGrid1: TsWorksheetGrid object sWorksheetGrid1: TsWorksheetGrid
Left = 2 Left = 2
Height = 557 Height = 556
Top = 23 Top = 23
Width = 386 Width = 276
AutoCalc = True
FrozenCols = 0 FrozenCols = 0
FrozenRows = 0 FrozenRows = 0
ReadFormulas = False ReadFormulas = True
WorkbookSource = sWorkbookSource1 WorkbookSource = sWorkbookSource1
Align = alClient Align = alClient
AutoAdvance = aaDown AutoAdvance = aaDown
DefaultColWidth = 64 DefaultColWidth = 64
DefaultRowHeight = 22 DefaultRowHeight = 22
Font.Color = clBlack MouseWheelOption = mwGrid
Font.Height = -15 Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goThumbTracking, goSmoothScroll]
Font.Name = 'Calibri'
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goThumbTracking]
ParentFont = False
TabOrder = 1 TabOrder = 1
TitleFont.Color = clBlack
TitleFont.Height = -15
TitleFont.Name = 'Calibri'
end end
end end
object Panel2: TPanel object Panel2: TPanel
Left = 402 Left = 285
Height = 594 Height = 581
Top = 40 Top = 37
Width = 470 Width = 543
Align = alRight Align = alClient
BevelOuter = bvNone BevelOuter = bvNone
Caption = 'Panel2' ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ClientHeight = 594 ChildSizing.EnlargeVertical = crsHomogenousChildResize
ClientWidth = 470 ChildSizing.ShrinkHorizontal = crsHomogenousChildResize
TabOrder = 3 ChildSizing.ShrinkVertical = crsHomogenousChildResize
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 581
ClientWidth = 543
TabOrder = 2
object Chart1: TChart object Chart1: TChart
Left = 0 Left = 0
Height = 183 Height = 194
Top = 0 Top = 0
Width = 470 Width = 543
AxisList = < AxisList = <
item item
Grid.Color = clSilver
Marks.LabelBrush.Style = bsClear Marks.LabelBrush.Style = bsClear
Minors = <> Minors = <>
Title.LabelFont.Orientation = 900 Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear Title.LabelBrush.Style = bsClear
end end
item item
Grid.Color = clSilver
Alignment = calBottom Alignment = calBottom
Marks.LabelBrush.Style = bsClear Marks.LabelBrush.Style = bsClear
Minors = <> Minors = <>
@@ -128,34 +128,33 @@ object Form1: TForm1
'Chart from 1st sheet' 'Chart from 1st sheet'
) )
Title.Visible = True Title.Visible = True
Align = alTop
object Chart1AreaSeries1: TAreaSeries object Chart1AreaSeries1: TAreaSeries
AreaBrush.Color = clSkyBlue AreaBrush.Color = clSkyBlue
AreaLinesPen.Style = psClear AreaLinesPen.Style = psClear
Source = sWorkbookChartSource1 Source = sWorkbookChartSource1
UseZeroLevel = True
end end
end end
object Chart2: TChart object Chart2: TChart
Left = 0 Left = 0
Height = 218 Height = 194
Top = 183 Top = 194
Width = 470 Width = 543
AxisList = < AxisList = <
item item
Grid.Color = clSilver
Marks.LabelBrush.Style = bsClear Marks.LabelBrush.Style = bsClear
Minors = <> Minors = <>
Title.LabelFont.Orientation = 900 Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear Title.LabelBrush.Style = bsClear
end end
item item
Grid.Color = clSilver
Alignment = calBottom Alignment = calBottom
Marks.LabelBrush.Style = bsClear Marks.LabelBrush.Style = bsClear
Minors = <> Minors = <>
Title.LabelBrush.Style = bsClear Title.LabelBrush.Style = bsClear
end> end>
BackColor = clWhite BackColor = clWhite
Depth = 10
Foot.Brush.Color = clBtnFace Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace Title.Brush.Color = clBtnFace
@@ -164,24 +163,24 @@ object Form1: TForm1
'Chart from 2nd sheet' 'Chart from 2nd sheet'
) )
Title.Visible = True Title.Visible = True
Align = alClient
object Chart2BarSeries1: TBarSeries object Chart2BarSeries1: TBarSeries
Marks.Distance = 15 Marks.Distance = 5
Marks.Format = '%0:.2f' Marks.Format = '%.2f'
Marks.Frame.Color = clOlive Marks.Frame.Visible = False
Marks.LabelBrush.Color = clCream Marks.LabelBrush.Color = 13553407
Marks.LinkPen.Visible = False Marks.LinkPen.Color = clGray
Marks.OverlapPolicy = opHideNeighbour
Marks.Style = smsCustom Marks.Style = smsCustom
BarBrush.Color = 9934847 BarBrush.Color = 9934847
Depth = 10 Depth = 6
Source = sWorkbookChartSource2 Source = sWorkbookChartSource2
end end
end end
object Chart3: TChart object Chart3: TChart
Left = 0 Left = 0
Height = 193 Height = 193
Top = 401 Top = 388
Width = 470 Width = 543
AxisList = < AxisList = <
item item
Visible = False Visible = False
@@ -200,7 +199,6 @@ object Form1: TForm1
Foot.Brush.Color = clBtnFace Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue Foot.Font.Color = clBlue
Frame.Visible = False Frame.Visible = False
Legend.Alignment = laCenterRight
Legend.Visible = True Legend.Visible = True
Title.Brush.Color = clBtnFace Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue Title.Font.Color = clBlue
@@ -208,36 +206,49 @@ object Form1: TForm1
'Chart from 3rd sheet' 'Chart from 3rd sheet'
) )
Title.Visible = True Title.Visible = True
Align = alBottom
object Chart3PieSeries1: TPieSeries object Chart3PieSeries1: TPieSeries
Legend.Multiplicity = lmPoint Legend.Multiplicity = lmPoint
Marks.Distance = 8 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
end end
object Bevel1: TBevel
Left = 0
Height = 4
Top = 33
Width = 828
Align = alTop
Shape = bsTopLine
end
object Splitter1: TSplitter
Left = 0
Height = 581
Top = 37
Width = 5
end
object sWorkbookSource1: TsWorkbookSource object sWorkbookSource1: TsWorkbookSource
AutoDetectFormat = False
FileFormat = sfUser FileFormat = sfUser
Options = [] Options = [boAutoCalc, boReadFormulas]
left = 184 left = 152
top = 320 top = 184
end
object sWorkbookChartSource1: TsWorkbookChartSource
WorkbookSource = sWorkbookSource1
left = 640
top = 112
end
object sWorkbookChartSource2: TsWorkbookChartSource
WorkbookSource = sWorkbookSource1
left = 640
top = 320
end end
object sWorkbookChartSource3: TsWorkbookChartSource object sWorkbookChartSource3: TsWorkbookChartSource
WorkbookSource = sWorkbookSource1 WorkbookSource = sWorkbookSource1
left = 640 left = 544
top = 512 top = 503
end
object sWorkbookChartSource2: TsWorkbookChartSource
WorkbookSource = sWorkbookSource1
left = 544
top = 316
end
object sWorkbookChartSource1: TsWorkbookChartSource
WorkbookSource = sWorkbookSource1
left = 544
top = 120
end end
end end

View File

@@ -5,9 +5,9 @@ unit mainform;
interface interface
uses uses
Classes, SysUtils, FileUtil, TAGraph, TASeries, Forms, Controls, Classes, SysUtils, FileUtil, TAGraph, TASources, TASeries, Forms, Controls,
Graphics, Dialogs, ExtCtrls, StdCtrls, Graphics, Dialogs, ExtCtrls, StdCtrls, fpspreadsheetctrls, fpspreadsheetgrid,
fpstypes, fpspreadsheetctrls, fpspreadsheetgrid, fpspreadsheetchart, fpsallformats; fpspreadsheetchart, fpsallformats;
type type
@@ -15,7 +15,7 @@ type
TForm1 = class(TForm) TForm1 = class(TForm)
Bevel1: TBevel; Bevel1: TBevel;
Button1: TButton; BtnDeleteSheet: TButton;
Button2: TButton; Button2: TButton;
Chart1: TChart; Chart1: TChart;
Chart1AreaSeries1: TAreaSeries; Chart1AreaSeries1: TAreaSeries;
@@ -32,13 +32,13 @@ type
sWorkbookSource1: TsWorkbookSource; sWorkbookSource1: TsWorkbookSource;
sWorkbookTabControl1: TsWorkbookTabControl; sWorkbookTabControl1: TsWorkbookTabControl;
sWorksheetGrid1: TsWorksheetGrid; sWorksheetGrid1: TsWorksheetGrid;
procedure Button1Click(Sender: TObject); procedure BtnDeleteSheetClick(Sender: TObject);
procedure Button2Click(Sender: TObject); procedure BtnRenameSheetClick(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
private private
{ private declarations }
public public
{ public declarations }
end; end;
var var
@@ -50,8 +50,19 @@ implementation
{ TForm1 } { TForm1 }
procedure TForm1.Button1Click(Sender: TObject); procedure TForm1.FormCreate(Sender: TObject);
// The same effect is obtained by using the built-in TsWorksheetDeleteAction. begin
sWorkbookSource1.Filename := 'test-data.xlsx';
sWorkbookChartSource1.XRange := 'Sheet1!A2:A21';
sWorkbookChartSource1.YRange := 'Sheet1!B2:B21';
sWorkbookChartSource2.XRange := 'Sheet2!A2:A16';
sWorkbookChartSource2.YRange := 'Sheet2!B2:B16';
sWorkbookChartSource3.XRange := 'Sheet3!A2:A5';
sWorkbookChartSource3.YRange := 'Sheet3!B2:B5';
sWorkbookChartSource3.LabelRange := 'Sheet3!A2:A5';
end;
procedure TForm1.BtnDeleteSheetClick(Sender: TObject);
begin begin
if sWorkbookSource1.Workbook.GetWorksheetCount = 1 then if sWorkbookSource1.Workbook.GetWorksheetCount = 1 then
MessageDlg('There must be a least 1 worksheet.', mtError, [mbOK], 0) MessageDlg('There must be a least 1 worksheet.', mtError, [mbOK], 0)
@@ -62,7 +73,7 @@ begin
sWorkbookSource1.Workbook.RemoveWorksheet(sWorkbookSource1.Worksheet); sWorkbookSource1.Workbook.RemoveWorksheet(sWorkbookSource1.Worksheet);
end; end;
procedure TForm1.Button2Click(Sender: TObject); procedure TForm1.BtnRenameSheetClick(Sender: TObject);
var var
s: String; s: String;
begin begin
@@ -76,16 +87,6 @@ begin
end; end;
end; end;
procedure TForm1.FormCreate(Sender: TObject);
begin
sWorkbookSource1.Filename := 'test-data.xlsx';
sWorkbookChartSource1.XRange := 'Sheet1!A2:A21';
sWorkbookChartSource1.YRange := 'Sheet1!B2:B21';
sWorkbookChartSource2.XRange := 'Sheet2!A2:A16';
sWorkbookChartSource2.YRange := 'Sheet2!B2:B16';
sWorkbookChartSource3.XRange := 'Sheet3!A2:A5';
sWorkbookChartSource3.YRange := 'Sheet3!B2:B5';
end;
end. end.

View File

@@ -79,31 +79,31 @@ type
{ TsWorkbookChartSource } { TsWorkbookChartSource }
TsXYRange = (rngX, rngY); TsXYLRange = (rngX, rngY, rngLabel);
TsWorkbookChartSource = class(TCustomChartSource, IsSpreadsheetControl) TsWorkbookChartSource = class(TCustomChartSource, IsSpreadsheetControl)
private private
FWorkbookSource: TsWorkbookSource; FWorkbookSource: TsWorkbookSource;
// FWorkbook: TsWorkbook; // FWorkbook: TsWorkbook;
FWorksheets: array[TsXYRange] of TsWorksheet; FWorksheets: array[TsXYLRange] of TsWorksheet;
FRangeStr: array[TsXYRange] of String; FRangeStr: array[TsXYLRange] of String;
FRanges: array[TsXYRange] of TsCellRangeArray; FRanges: array[TsXYLRange] of TsCellRangeArray;
FPointsNumber: Cardinal; FPointsNumber: Cardinal;
function GetRange(AIndex: TsXYRange): String; function GetRange(AIndex: TsXYLRange): String;
function GetWorkbook: TsWorkbook; function GetWorkbook: TsWorkbook;
procedure GetXYItem(XOrY:TsXYRange; APointIndex: Integer; procedure GetXYItem(ARangeIndex:TsXYLRange; APointIndex: Integer;
out ANumber: Double; out AText: String); out ANumber: Double; out AText: String);
procedure SetRange(AIndex: TsXYRange; const AValue: String); procedure SetRange(AIndex: TsXYLRange; const AValue: String);
procedure SetWorkbookSource(AValue: TsWorkbookSource); procedure SetWorkbookSource(AValue: TsWorkbookSource);
protected protected
FCurItem: TChartDataItem; FCurItem: TChartDataItem;
function BuildRangeStr(AIndex: TsXYRange; AListSeparator: char = #0): String; function BuildRangeStr(AIndex: TsXYLRange; AListSeparator: char = #0): String;
function CountValues(AIndex: TsXYRange): Integer; function CountValues(AIndex: TsXYLRange): Integer;
function GetCount: Integer; override; function GetCount: Integer; override;
function GetItem(AIndex: Integer): PChartDataItem; override; function GetItem(AIndex: Integer): PChartDataItem; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure Prepare; overload; procedure Prepare; overload;
procedure Prepare(AIndex: TsXYRange); overload; procedure Prepare(AIndex: TsXYLRange); overload;
procedure SetYCount(AValue: Cardinal); override; procedure SetYCount(AValue: Cardinal); override;
public public
destructor Destroy; override; destructor Destroy; override;
@@ -116,6 +116,7 @@ type
procedure RemoveWorkbookSource; procedure RemoveWorkbookSource;
published published
property WorkbookSource: TsWorkbookSource read FWorkbookSource write SetWorkbookSource; property WorkbookSource: TsWorkbookSource read FWorkbookSource write SetWorkbookSource;
property LabelRange: String index rngLabel read GetRange write SetRange;
property XRange: String index rngX read GetRange write SetRange; property XRange: String index rngX read GetRange write SetRange;
property YRange: String index rngY read GetRange write SetRange; property YRange: String index rngY read GetRange write SetRange;
end; end;
@@ -317,7 +318,7 @@ end;
to have the worksheet name in the range string in order to make the range to have the worksheet name in the range string in order to make the range
string unique. string unique.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorkbookChartSource.BuildRangeStr(AIndex: TsXYRange; function TsWorkbookChartSource.BuildRangeStr(AIndex: TsXYLRange;
AListSeparator: Char = #0): String; AListSeparator: Char = #0): String;
var var
L: TStrings; L: TStrings;
@@ -346,7 +347,7 @@ end;
@param AIndex Identifies whether values in the x or y ranges are counted. @param AIndex Identifies whether values in the x or y ranges are counted.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorkbookChartSource.CountValues(AIndex: TsXYRange): Integer; function TsWorkbookChartSource.CountValues(AIndex: TsXYLRange): Integer;
var var
range: TsCellRange; range: TsCellRange;
begin begin
@@ -382,23 +383,28 @@ end;
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorkbookChartSource.GetItem(AIndex: Integer): PChartDataItem; function TsWorkbookChartSource.GetItem(AIndex: Integer): PChartDataItem;
var var
dummy: String; dummyNumber: Double;
dummyString: String;
tmpLabel: String;
begin begin
GetXYItem(rngX, AIndex, FCurItem.X, FCurItem.Text); GetXYItem(rngX, AIndex, FCurItem.X, tmpLabel);
GetXYItem(rngY, AIndex, FCurItem.Y, dummy); GetXYItem(rngY, AIndex, FCurItem.Y, dummyString);
GetXYItem(rngLabel, AIndex, dummyNumber, FCurItem.Text);
if FCurItem.Text = '' then FCurItem.Text := tmpLabel;
FCurItem.Color := clDefault; FCurItem.Color := clDefault;
Result := @FCurItem; Result := @FCurItem;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Getter method for the cell range used for x or y coordinates (or x labels) Getter method for the cell range used for x or y coordinates or x labels
@param AIndex Determines whether the methods deals with x or y values @param AIndex Determines whether the methods deals with x, y values or
vakze labels.
@return An Excel string containing workbookname and cell block(s) in A1 @return An Excel string containing workbookname and cell block(s) in A1
notation. Multiple blocks are separated by the ListSeparator defined notation. Multiple blocks are separated by the ListSeparator defined
by the workbook's FormatSettings. by the workbook's FormatSettings.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorkbookChartsource.GetRange(AIndex: TsXYRange): String; function TsWorkbookChartsource.GetRange(AIndex: TsXYLRange): String;
begin begin
Result := FRangeStr[AIndex]; Result := FRangeStr[AIndex];
end; end;
@@ -418,14 +424,14 @@ end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Helper method the prepare the information required for the series data point. Helper method the prepare the information required for the series data point.
@param XOrY Identifies whether the method retrieves the x or y @param ARangeIndex Identifies whether the method retrieves the x or y
coordinate. coordinate, or the label text
@param APointIndex Index of the data point for which the data are required @param APointIndex Index of the data point for which the data are required
@param ANumber (output) x or y coordinate of the data point @param ANumber (output) x or y coordinate of the data point
@param AText Data point marks label text @param AText Data point marks label text
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorkbookChartSource.GetXYItem(XOrY:TsXYRange; APointIndex: Integer; procedure TsWorkbookChartSource.GetXYItem(ARangeIndex:TsXYLRange;
out ANumber: Double; out AText: String); APointIndex: Integer; out ANumber: Double; out AText: String);
var var
range: TsCellRange; range: TsCellRange;
idx: Integer; idx: Integer;
@@ -433,12 +439,17 @@ var
row, col: Cardinal; row, col: Cardinal;
cell: PCell; cell: PCell;
begin begin
cell := nil; ANumber := NaN;
idx := 0; AText := '';
if FRanges[XOrY] = nil then if FRanges[ARangeIndex] = nil then
exit;
if FWorksheets[ARangeIndex] = nil then
exit; exit;
for range in FRanges[XOrY] do cell := nil;
idx := 0;
for range in FRanges[ARangeIndex] do
begin begin
if (range.Col1 = range.Col2) then // vertical range if (range.Col1 = range.Col2) then // vertical range
begin begin
@@ -461,24 +472,22 @@ begin
break; break;
end; end;
end else end else
raise Exception.Create('x/y ranges can only be 1 column wide or 1 row high'); raise Exception.Create('Ranges can only be 1 column wide or 1 row high');
end; end;
cell := FWorksheets[XOrY].FindCell(row, col); cell := FWorksheets[ARangeIndex].FindCell(row, col);
if cell = nil then if cell <> nil then
begin case cell^.ContentType of
ANumber := NaN; cctUTF8String:
AText := ''; begin
end else ANumber := APointIndex;
if cell^.ContentType = cctUTF8String then begin AText := FWorksheets[ARangeIndex].ReadAsText(cell);
ANumber := APointIndex; end;
AText := FWorksheets[rngX].ReadAsText(cell); else
end else ANumber := FWorksheets[ARangeIndex].ReadAsNumber(cell);
begin AText := '';
ANumber := FWorksheets[rngX].ReadAsNumber(cell); end;
AText := '';
end;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@@ -500,7 +509,7 @@ var
ir: Integer; ir: Integer;
cell: PCell; cell: PCell;
ResetDone: Boolean; ResetDone: Boolean;
xy: TsXYRange; rng: TsXYLRange;
begin begin
Unused(AData); Unused(AData);
@@ -510,19 +519,19 @@ begin
// Used worksheet has been renamed? // Used worksheet has been renamed?
if (lniWorksheetRename in AChangedItems) then if (lniWorksheetRename in AChangedItems) then
for xy in TsXYRange do for rng in TsXYLRange do
if TsWorksheet(AData) = FWorksheets[xy] then begin if TsWorksheet(AData) = FWorksheets[rng] then begin
FRangeStr[xy] := BuildRangeStr(xy); FRangeStr[rng] := BuildRangeStr(rng);
Prepare(xy); Prepare(rng);
end; end;
// Used worksheet will be deleted? // Used worksheet will be deleted?
if (lniWorksheetRemoving in AChangedItems) then if (lniWorksheetRemoving in AChangedItems) then
for xy in TsXYRange do for rng in TsXYLRange do
if TsWorksheet(AData) = FWorksheets[xy] then begin if TsWorksheet(AData) = FWorksheets[rng] then begin
FWorksheets[xy] := nil; FWorksheets[rng] := nil;
FRangeStr[xy] := BuildRangeStr(xy); FRangeStr[rng] := BuildRangeStr(rng);
Prepare(xy); Prepare(rng);
end; 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
@@ -532,10 +541,10 @@ begin
cell := PCell(AData); cell := PCell(AData);
if (cell <> nil) then begin if (cell <> nil) then begin
ResetDone := false; ResetDone := false;
for xy in TsXYrange do for rng in TsXYLRange do
for ir:=0 to High(FRanges[xy]) do for ir:=0 to High(FRanges[rng]) do
begin begin
if FWorksheets[xy].CellInRange(cell^.Row, cell^.Col, FRanges[xy, ir]) then if FWorksheets[rng].CellInRange(cell^.Row, cell^.Col, FRanges[rng, ir]) then
begin begin
Reset; Reset;
ResetDone := true; ResetDone := true;
@@ -565,6 +574,7 @@ end;
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorkbookChartSource.Prepare; procedure TsWorkbookChartSource.Prepare;
begin begin
Prepare(rngLabel);
Prepare(rngX); Prepare(rngX);
Prepare(rngY); Prepare(rngY);
end; end;
@@ -573,11 +583,13 @@ end;
Parses the range string of the data specified by AIndex and extracts internal Parses the range string of the data specified by AIndex and extracts internal
information (worksheet used, cell range coordinates) information (worksheet used, cell range coordinates)
@param AIndex Identifies whether x or y cell ranges are analyzed @param AIndex Identifies whether x or y or label cell ranges are analyzed
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorkbookChartSource.Prepare(AIndex: TsXYRange); procedure TsWorkbookChartSource.Prepare(AIndex: TsXYLRange);
{
const const
XY: array[TsXYRange] of string = ('x', 'y'); XY: array[TsXYRange] of string = ('x', 'y', '');
}
var var
range: TsCellRange; range: TsCellRange;
begin begin
@@ -603,11 +615,14 @@ begin
end else end else
if (Workbook.GetWorksheetCount > 0) then begin if (Workbook.GetWorksheetCount > 0) then begin
if FWorksheets[AIndex] = nil then if FWorksheets[AIndex] = nil then
exit;
{
raise Exception.CreateFmt('Worksheet of %s cell range "%s" does not exist.', raise Exception.CreateFmt('Worksheet of %s cell range "%s" does not exist.',
[XY[AIndex], FRangeStr[AIndex]]) [XY[AIndex], FRangeStr[AIndex]])
else else
raise Exception.CreateFmt('No valid %s cell range in "%s".', raise Exception.CreateFmt('No valid %s cell range in "%s".',
[XY[AIndex], FRangeStr[AIndex]]); [XY[AIndex], FRangeStr[AIndex]]);
}
end; end;
end; end;
@@ -635,13 +650,15 @@ end;
If it does not contain the worksheet name the currently active worksheet of If it does not contain the worksheet name the currently active worksheet of
the WorkbookSource is assumed. the WorkbookSource is assumed.
@param AIndex Distinguishes whether the method deals with x or y ranges @param AIndex Distinguishes whether the method deals with x, y or
label ranges.
@param AValue String in Excel syntax containing the cell range to be @param AValue String in Excel syntax containing the cell range to be
used for x or y (depending on AIndex). Can contain multiple used for x or y (depending on AIndex). Can contain multiple
cell blocks which must be separator by the ListSeparator cell blocks which must be separator by the ListSeparator
character defined in the Workbook's FormatSettings. character defined in the Workbook's FormatSettings.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorkbookChartSource.SetRange(AIndex: TsXYRange; const AValue: String); procedure TsWorkbookChartSource.SetRange(AIndex: TsXYLRange;
const AValue: String);
begin begin
FRangeStr[AIndex] := AValue; FRangeStr[AIndex] := AValue;
Prepare; Prepare;