You've already forked lazarus-ccr
fpspreadsheet: Add property Worksheet.Index.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7005 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -7,13 +7,15 @@ object Form1: TForm1
|
|||||||
ClientHeight = 601
|
ClientHeight = 601
|
||||||
ClientWidth = 997
|
ClientWidth = 997
|
||||||
Menu = MainMenu1
|
Menu = MainMenu1
|
||||||
|
OnCreate = FormCreate
|
||||||
ShowHint = True
|
ShowHint = True
|
||||||
LCLVersion = '1.9.0.0'
|
LCLVersion = '2.1.0.0'
|
||||||
object sWorkbookTabControl1: TsWorkbookTabControl
|
object sWorkbookTabControl1: TsWorkbookTabControl
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 542
|
Height = 542
|
||||||
Top = 59
|
Top = 59
|
||||||
Width = 997
|
Width = 997
|
||||||
|
TabIndex = 0
|
||||||
Tabs.Strings = (
|
Tabs.Strings = (
|
||||||
'Sheet1'
|
'Sheet1'
|
||||||
)
|
)
|
||||||
@ -26,6 +28,7 @@ object Form1: TForm1
|
|||||||
Top = 23
|
Top = 23
|
||||||
Width = 993
|
Width = 993
|
||||||
AutoCalc = True
|
AutoCalc = True
|
||||||
|
FixedColWidth = 57
|
||||||
FrozenCols = 0
|
FrozenCols = 0
|
||||||
FrozenRows = 0
|
FrozenRows = 0
|
||||||
ReadFormulas = True
|
ReadFormulas = True
|
||||||
@ -82,7 +85,7 @@ object Form1: TForm1
|
|||||||
Width = 130
|
Width = 130
|
||||||
WorkbookSource = sWorkbookSource1
|
WorkbookSource = sWorkbookSource1
|
||||||
DropDownCount = 24
|
DropDownCount = 24
|
||||||
ItemIndex = 46
|
ItemIndex = 49
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
Text = 'Arial'
|
Text = 'Arial'
|
||||||
end
|
end
|
||||||
|
@ -54,6 +54,7 @@ type
|
|||||||
ToolButton8: TToolButton;
|
ToolButton8: TToolButton;
|
||||||
procedure FileOpen1Accept(Sender: TObject);
|
procedure FileOpen1Accept(Sender: TObject);
|
||||||
procedure FileSaveAs1Accept(Sender: TObject);
|
procedure FileSaveAs1Accept(Sender: TObject);
|
||||||
|
procedure FormCreate(Sender: TObject);
|
||||||
private
|
private
|
||||||
|
|
||||||
protected
|
protected
|
||||||
@ -78,6 +79,7 @@ uses
|
|||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
|
||||||
{ Loads the spreadsheet file selected by the FileOpen standard action }
|
{ Loads the spreadsheet file selected by the FileOpen standard action }
|
||||||
|
{
|
||||||
procedure TForm1.FileOpen1Accept(Sender: TObject);
|
procedure TForm1.FileOpen1Accept(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
sWorkbookSource1.AutodetectFormat := false;
|
sWorkbookSource1.AutodetectFormat := false;
|
||||||
@ -92,6 +94,35 @@ begin
|
|||||||
8: sWorkbookSource1.FileFormat := sfCSV; // Text files
|
8: sWorkbookSource1.FileFormat := sfCSV; // Text files
|
||||||
end;
|
end;
|
||||||
sWorkbookSource1.FileName :=FileOpen1.Dialog.FileName; // This loads the file
|
sWorkbookSource1.FileName :=FileOpen1.Dialog.FileName; // This loads the file
|
||||||
|
sWorksheetGrid1.ShowHeaders := false;
|
||||||
|
end; }
|
||||||
|
|
||||||
|
procedure TForm1.FileOpen1Accept(Sender: TObject);
|
||||||
|
var
|
||||||
|
wb: TsWorkbook;
|
||||||
|
sh: TsWorksheet;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
wb := TsWorkbook.Create;
|
||||||
|
case FileOpen1.Dialog.FilterIndex of
|
||||||
|
1: wb.ReadfromFile(FileOpen1.Dialog.FileName); // all spreadsheet files --> autodetect
|
||||||
|
2: wb.ReadFromFile(FileOpen1.Dialog.FileName); // all Excel files --> autodetect
|
||||||
|
3: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfOOXML); // Exel 2007+
|
||||||
|
4: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfExcel8); // Excel 97-2003
|
||||||
|
5: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfExcel5); // Excel 5.0
|
||||||
|
6: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfExcel2); // Excel 2.1
|
||||||
|
7: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfOpenDocument); // LibreOffice
|
||||||
|
8: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfCSV); // Text files
|
||||||
|
else
|
||||||
|
wb.Free;
|
||||||
|
MessageDlg('File format not implemented.', mtError, [mbOk], 0);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
for i := 0 to wb.GetWorksheetCount - 1 do begin
|
||||||
|
sh := wb.GetWorksheetByIndex(i);
|
||||||
|
sh.Options := sh.Options - [soShowHeaders];
|
||||||
|
end;
|
||||||
|
sWorkbookSource1.LoadFromWorkbook(wb);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Saves the spreadsheet to the file selected by the FileSaveAs1 action }
|
{ Saves the spreadsheet to the file selected by the FileSaveAs1 action }
|
||||||
@ -116,5 +147,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.FormCreate(Sender: TObject);
|
||||||
|
begin
|
||||||
|
sWorksheetGrid1.ShowHeaders := false;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -105,9 +105,11 @@ type
|
|||||||
function GetDefaultColWidth: Single;
|
function GetDefaultColWidth: Single;
|
||||||
function GetDefaultRowHeight: Single;
|
function GetDefaultRowHeight: Single;
|
||||||
function GetFormatSettings: TFormatSettings;
|
function GetFormatSettings: TFormatSettings;
|
||||||
|
function GetIndex: Integer;
|
||||||
procedure SetBiDiMode(AValue: TsBiDiMode);
|
procedure SetBiDiMode(AValue: TsBiDiMode);
|
||||||
procedure SetDefaultColWidth(AValue: Single);
|
procedure SetDefaultColWidth(AValue: Single);
|
||||||
procedure SetDefaultRowHeight(AValue: Single);
|
procedure SetDefaultRowHeight(AValue: Single);
|
||||||
|
procedure SetIndex(AValue: Integer);
|
||||||
procedure SetVirtualColCount(AValue: Cardinal);
|
procedure SetVirtualColCount(AValue: Cardinal);
|
||||||
procedure SetVirtualRowCount(AValue: Cardinal);
|
procedure SetVirtualRowCount(AValue: Cardinal);
|
||||||
procedure SetZoomFactor(AValue: Double);
|
procedure SetZoomFactor(AValue: Double);
|
||||||
@ -600,6 +602,8 @@ type
|
|||||||
property Formulas: TsFormulas read FFormulas;
|
property Formulas: TsFormulas read FFormulas;
|
||||||
{@@ FormatSettings for localization of some formatting strings }
|
{@@ FormatSettings for localization of some formatting strings }
|
||||||
property FormatSettings: TFormatSettings read GetFormatSettings;
|
property FormatSettings: TFormatSettings read GetFormatSettings;
|
||||||
|
{@@ Index of the worksheet in the workbook }
|
||||||
|
property Index: Integer read GetIndex write SetIndex;
|
||||||
{@@ Parameters to be used for printing by the Office applications }
|
{@@ Parameters to be used for printing by the Office applications }
|
||||||
property PageLayout: TsPageLayout read FPageLayout write FPageLayout;
|
property PageLayout: TsPageLayout read FPageLayout write FPageLayout;
|
||||||
{@@ List of all row records of the worksheet having a non-standard row height }
|
{@@ List of all row records of the worksheet having a non-standard row height }
|
||||||
@ -724,6 +728,7 @@ type
|
|||||||
function FixFormula(AFormula: PsFormula; ACorrection: TsFormulaCorrection;
|
function FixFormula(AFormula: PsFormula; ACorrection: TsFormulaCorrection;
|
||||||
AData: Pointer; AParam: PtrInt): Boolean;
|
AData: Pointer; AParam: PtrInt): Boolean;
|
||||||
|
|
||||||
|
procedure MoveSheet(AFromIndex, AToIndex: Integer);
|
||||||
public
|
public
|
||||||
{ Base methods }
|
{ Base methods }
|
||||||
constructor Create;
|
constructor Create;
|
||||||
@ -4492,7 +4497,6 @@ procedure TsWorksheet.Sort(const ASortParams: TsSortParams;
|
|||||||
dec(J);
|
dec(J);
|
||||||
end;
|
end;
|
||||||
until I > J;
|
until I > J;
|
||||||
|
|
||||||
if L < J then
|
if L < J then
|
||||||
QuickSort(L, J);
|
QuickSort(L, J);
|
||||||
|
|
||||||
@ -7247,6 +7251,34 @@ begin
|
|||||||
Result := FWorkbook.FormatSettings;
|
Result := FWorkbook.FormatSettings;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TsWorksheet.GetIndex: Integer;
|
||||||
|
begin
|
||||||
|
Result := TsWorkbook(FWorkbook).GetWorksheetIndex(self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Moves the worksheet to the specified index in the workbook.
|
||||||
|
|
||||||
|
@param AValue New index of the sheet in the workbook. If less than 0 the
|
||||||
|
worksheet will become the first, if greater than the
|
||||||
|
worksheet count it will become the last worksheet of the
|
||||||
|
workbook.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
procedure TsWorksheet.SetIndex(AValue: Integer);
|
||||||
|
var
|
||||||
|
oldIndex: Integer;
|
||||||
|
begin
|
||||||
|
if AValue < 0 then
|
||||||
|
AValue := 0
|
||||||
|
else
|
||||||
|
if AValue > TsWorkbook(FWorkbook).GetWorksheetCount then
|
||||||
|
Avalue := TsWorkbook(FWorkbook).GetWorksheetCount - 1;
|
||||||
|
oldIndex := GetIndex;
|
||||||
|
if oldIndex <> AValue then
|
||||||
|
TsWorkbook(FWorkbook).MoveSheet(oldIndex, Avalue);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Calculates the optimum height of a given row. Depends on the font size
|
Calculates the optimum height of a given row. Depends on the font size
|
||||||
of the individual cells in the row. Is converted to workbook units.
|
of the individual cells in the row. Is converted to workbook units.
|
||||||
@ -10118,6 +10150,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsWorkbook.MoveSheet(AFromIndex, AToIndex: Integer);
|
||||||
|
begin
|
||||||
|
FWorksheets.Move(AFromIndex, AToIndex);
|
||||||
|
if Assigned(FOnChangeWorksheet) then
|
||||||
|
FOnChangeWorksheet(Self, GetWorksheetByIndex(AToIndex));
|
||||||
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Writes the selected cells to a stream for usage in the clipboard.
|
Writes the selected cells to a stream for usage in the clipboard.
|
||||||
Transfer to the clipboard has do be done by the calling routine since
|
Transfer to the clipboard has do be done by the calling routine since
|
||||||
|
Reference in New Issue
Block a user