FPSpreadsheet: Show all charts of a worksheet in the chartlink demo

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9486 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-10-17 22:08:39 +00:00
parent 0fab687b13
commit 7bdff78242
2 changed files with 77 additions and 8 deletions

View File

@ -6,7 +6,7 @@ object Form1: TForm1
Caption = 'Form1' Caption = 'Form1'
ClientHeight = 527 ClientHeight = 527
ClientWidth = 1351 ClientWidth = 1351
LCLVersion = '3.99.0.0' LCLVersion = '4.99.0.0'
OnCreate = FormCreate OnCreate = FormCreate
object Splitter1: TSplitter object Splitter1: TSplitter
Left = 523 Left = 523
@ -109,6 +109,8 @@ object Form1: TForm1
Height = 375 Height = 375
Top = 1 Top = 1
Width = 521 Width = 521
OnChange = sWorkbookTabControl1Change
TabHeight = 25
TabIndex = 0 TabIndex = 0
Tabs.Strings = ( Tabs.Strings = (
'Sheet1' 'Sheet1'
@ -118,8 +120,8 @@ object Form1: TForm1
WorkbookSource = sWorkbookSource WorkbookSource = sWorkbookSource
object sWorksheetGrid: TsWorksheetGrid object sWorksheetGrid: TsWorksheetGrid
Left = 2 Left = 2
Height = 350 Height = 348
Top = 23 Top = 25
Width = 517 Width = 517
FrozenCols = 0 FrozenCols = 0
FrozenRows = 0 FrozenRows = 0
@ -151,8 +153,8 @@ object Form1: TForm1
TabOrder = 3 TabOrder = 3
object Chart: TChart object Chart: TChart
Left = 0 Left = 0
Height = 489 Height = 464
Top = 0 Top = 25
Width = 823 Width = 823
AxisList = < AxisList = <
item item
@ -173,6 +175,38 @@ object Form1: TForm1
) )
Align = alClient Align = alClient
end end
object Panel4: TPanel
Left = 0
Height = 25
Top = 0
Width = 823
Align = alTop
BevelOuter = bvNone
ClientHeight = 25
ClientWidth = 823
TabOrder = 1
Visible = False
object Label1: TLabel
AnchorSideTop.Control = Panel4
AnchorSideTop.Side = asrCenter
Left = 0
Height = 15
Top = 5
Width = 39
Caption = 'Chart #'
end
object seChartIndex: TSpinEdit
AnchorSideTop.Control = Panel4
AnchorSideTop.Side = asrCenter
Left = 48
Height = 23
Top = 1
Width = 74
Alignment = taRightJustify
TabOrder = 0
OnChange = seChartIndexChange
end
end
end end
object sWorkbookSource: TsWorkbookSource object sWorkbookSource: TsWorkbookSource
FileFormat = sfUser FileFormat = sfUser

View File

@ -5,11 +5,11 @@ unit main;
interface interface
uses uses
Classes, SysUtils, Classes, Spin, SysUtils,
LCLVersion, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, FileUtil, LazFileUtils, LCLVersion, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, FileUtil, LazFileUtils,
TAGraph, TASources, TAGraph, TASources,
fpSpreadsheet, fpsTypes, fpsOpenDocument, xlsxOOXML, fpSpreadsheet, fpsTypes, fpsOpenDocument, xlsxOOXML,
fpSpreadsheetCtrls, fpSpreadsheetGrid, fpSpreadsheetChart; fpSpreadsheetCtrls, fpSpreadsheetGrid, fpSpreadsheetChart, fpsChart;
type type
@ -20,6 +20,7 @@ type
btnOpen: TButton; btnOpen: TButton;
Chart: TChart; Chart: TChart;
cbFileNames: TComboBox; cbFileNames: TComboBox;
Label1: TLabel;
lblFileNames: TLabel; lblFileNames: TLabel;
ListChartSource: TListChartSource; ListChartSource: TListChartSource;
Memo: TMemo; Memo: TMemo;
@ -27,6 +28,8 @@ type
Panel1: TPanel; Panel1: TPanel;
Panel2: TPanel; Panel2: TPanel;
Panel3: TPanel; Panel3: TPanel;
Panel4: TPanel;
seChartIndex: TSpinEdit;
Splitter1: TSplitter; Splitter1: TSplitter;
sWorkbookSource: TsWorkbookSource; sWorkbookSource: TsWorkbookSource;
sWorkbookTabControl1: TsWorkbookTabControl; sWorkbookTabControl1: TsWorkbookTabControl;
@ -35,7 +38,9 @@ type
procedure btnOpenClick(Sender: TObject); procedure btnOpenClick(Sender: TObject);
procedure cbFileNamesSelect(Sender:TObject); procedure cbFileNamesSelect(Sender:TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure seChartIndexChange(Sender: TObject);
procedure sWorkbookSourceError(Sender: TObject; const AMsg: String); procedure sWorkbookSourceError(Sender: TObject; const AMsg: String);
procedure sWorkbookTabControl1Change(Sender: TObject);
private private
FDir: String; FDir: String;
sChartLink: TsWorkbookChartLink; sChartLink: TsWorkbookChartLink;
@ -121,11 +126,40 @@ begin
end; end;
end; end;
procedure TForm1.seChartIndexChange(Sender: TObject);
var
charts: TsChartArray;
i: Integer;
begin
charts := sWorkbookSource.Worksheet.GetCharts;
i := seChartIndex.Value;
if i < 0 then i := 0;
if i > High(charts) then i := High(charts);
sChartLink.WorkbookChartIndex := charts[i].Index;
end;
procedure TForm1.sWorkbookSourceError(Sender: TObject; const AMsg: String); procedure TForm1.sWorkbookSourceError(Sender: TObject; const AMsg: String);
begin begin
Memo.Lines.Add(AMsg); Memo.Lines.Add(AMsg);
end; end;
procedure TForm1.sWorkbookTabControl1Change(Sender: TObject);
var
charts: TsChartArray;
n: Integer;
begin
charts := sWorkbookSource.Worksheet.GetCharts;
n := Length(charts);
if n > 1 then
begin
Panel4.Show;
seChartIndex.MaxValue := n - 1;
seChartIndex.Value := 0;
sChartLink.WorkbookChartIndex := charts[0].Index;
end else
Panel4.Hide;
end;
procedure TForm1.LoadFile(AFileName: String); procedure TForm1.LoadFile(AFileName: String);
var var
ext: String; ext: String;
@ -156,7 +190,8 @@ begin
sChartLink := TsWorkbookChartLink.Create(self); sChartLink := TsWorkbookChartLink.Create(self);
sChartLink.Chart := Chart; sChartLink.Chart := Chart;
sChartLink.WorkbookSource := sWorkbookSource; sChartLink.WorkbookSource := sWorkbookSource;
sChartLink.WorkbookChartIndex := 0;
sWorkbookTabControl1Change(nil);
end; end;
end. end.