You've already forked lazarus-ccr
fpspreadsheet: Add method LoadFromWorkbook to WorksheetGrid and WorkbookSource. Remove "deprecated" from some overloaded workbook file access methods.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4448 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -35,6 +35,8 @@ object MainForm: TMainForm
|
||||
Align = alClient
|
||||
AutoAdvance = aaDown
|
||||
ColCount = 27
|
||||
DefaultColWidth = 64
|
||||
DefaultRowHeight = 22
|
||||
Font.Color = clBlack
|
||||
Font.Height = -13
|
||||
Font.Name = 'Arial'
|
||||
@@ -81,7 +83,7 @@ object MainForm: TMainForm
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goAlwaysShowEditor, goThumbTracking, goCellHints, goTruncCellHints]
|
||||
Strings.Strings = (
|
||||
'FileName='
|
||||
'FileFormat=-1 []'
|
||||
'FileFormat=(unknown)'
|
||||
'ActiveWorksheet=Sheet1'
|
||||
'Options=boAutoCalc, boCalcBeforeSaving, boReadFormulas'
|
||||
'(-) FormatSettings='
|
||||
|
@@ -416,16 +416,24 @@ end;
|
||||
|
||||
{ Loads the spreadsheet file selected by the AcFileOpen action }
|
||||
procedure TMainForm.AcFileOpenAccept(Sender: TObject);
|
||||
var
|
||||
crs: TCursor;
|
||||
begin
|
||||
WorkbookSource.AutodetectFormat := false;
|
||||
case AcFileOpen.Dialog.FilterIndex of
|
||||
1: WorkbookSource.AutoDetectFormat := true; // All spreadsheet files
|
||||
2: WorkbookSource.AutoDetectFormat := true; // All Excel files
|
||||
else WorkbookSource.FileFormatID := FOpenFormats[AcFileOpen.Dialog.FilterIndex - 3];
|
||||
crs := Screen.Cursor;
|
||||
Screen.Cursor := crHourglass;
|
||||
try
|
||||
WorkbookSource.AutodetectFormat := false;
|
||||
case AcFileOpen.Dialog.FilterIndex of
|
||||
1: WorkbookSource.AutoDetectFormat := true; // All spreadsheet files
|
||||
2: WorkbookSource.AutoDetectFormat := true; // All Excel files
|
||||
else WorkbookSource.FileFormatID := FOpenFormats[AcFileOpen.Dialog.FilterIndex - 3];
|
||||
// -3 because FilterIndex is 1-based and there are 2 add'l items at the top.
|
||||
end;
|
||||
WorkbookSource.FileName := UTF8ToAnsi(AcFileOpen.Dialog.FileName); // this loads the file
|
||||
UpdateCaption;
|
||||
finally
|
||||
Screen.Cursor := crs;
|
||||
end;
|
||||
WorkbookSource.FileName := UTF8ToAnsi(AcFileOpen.Dialog.FileName); // this loads the file
|
||||
UpdateCaption;
|
||||
end;
|
||||
|
||||
{ Saves the spreadsheet to the file selected by the AcFileSaveAs action }
|
||||
|
@@ -657,7 +657,7 @@ type
|
||||
procedure ReadFromFile(AFileName: string; AFormatID: TsSpreadFormatID;
|
||||
AParams: TsStreamParams = []); overload;
|
||||
procedure ReadFromFile(AFileName: string; AFormat: TsSpreadsheetFormat;
|
||||
AParams: TsStreamParams = []); overload; deprecated 'Use TsSpreadFormatID instead of TsSpreadsheetFormat';
|
||||
AParams: TsStreamParams = []); overload;
|
||||
procedure ReadFromFile(AFileName: string;
|
||||
AParams: TsStreamParams = []); overload;
|
||||
procedure ReadFromFileIgnoringExtension(AFileName: string;
|
||||
@@ -665,18 +665,18 @@ type
|
||||
procedure ReadFromStream(AStream: TStream; AFormatID: TsSpreadFormatID;
|
||||
AParams: TsStreamParams = []); overload;
|
||||
procedure ReadFromStream(AStream: TStream; AFormat: TsSpreadsheetFormat;
|
||||
AParams: TsStreamParams = []); overload; deprecated 'Use TsSpreadFormatID instead of TsSpreadsheetFormat';
|
||||
AParams: TsStreamParams = []); overload;
|
||||
|
||||
procedure WriteToFile(const AFileName: string; const AFormatID: TsSpreadFormatID;
|
||||
const AOverwriteExisting: Boolean = False; AParams: TsStreamParams = []); overload;
|
||||
procedure WriteToFile(const AFileName: string; const AFormat: TsSpreadsheetFormat;
|
||||
const AOverwriteExisting: Boolean = False; AParams: TsStreamParams = []); overload; deprecated 'Use TsSpreadFormatID instead of TsSpreadsheetFormat';
|
||||
const AOverwriteExisting: Boolean = False; AParams: TsStreamParams = []); overload;
|
||||
procedure WriteToFile(const AFileName: String;
|
||||
const AOverwriteExisting: Boolean = False; AParams: TsStreamParams = []); overload;
|
||||
procedure WriteToStream(AStream: TStream; AFormatID: TsSpreadFormatID;
|
||||
AParams: TsStreamParams = []); overload;
|
||||
procedure WriteToStream(AStream: TStream; AFormat: TsSpreadsheetFormat;
|
||||
AParams: TsStreamParams = []); overload; deprecated 'Use TsSpreadFormatID instead of TsSpreadsheetFormat';
|
||||
AParams: TsStreamParams = []); overload;
|
||||
|
||||
{ Worksheet list handling methods }
|
||||
function AddWorksheet(AName: string;
|
||||
|
@@ -94,6 +94,8 @@ type
|
||||
procedure InternalCreateNewWorkbook(AWorkbook: TsWorkbook = nil);
|
||||
procedure InternalLoadFromFile(AFileName: string; AAutoDetect: Boolean;
|
||||
AFormatID: TsSpreadFormatID; AWorksheetIndex: Integer = -1);
|
||||
procedure InternalLoadFromWorkbook(AWorkbook: TsWorkbook;
|
||||
AWorksheetIndex: Integer = -1);
|
||||
procedure Loaded; override;
|
||||
|
||||
public
|
||||
@@ -112,6 +114,7 @@ type
|
||||
AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer = -1); overload;
|
||||
procedure LoadFromSpreadsheetFile(AFileName: string;
|
||||
AFormatID: TsSpreadFormatID = sfidUnknown; AWorksheetIndex: Integer = -1); overload;
|
||||
procedure LoadFromWorkbook(AWorkbook: TsWorkbook; AWorksheetIndex: Integer = -1);
|
||||
{
|
||||
procedure LoadFromSpreadsheetFile(AFileName: string;
|
||||
AWorksheetIndex: Integer = -1); overload;
|
||||
@@ -937,8 +940,26 @@ begin
|
||||
DoShowError(FWorkbook.ErrorMsg);
|
||||
end;
|
||||
}
|
||||
|
||||
var
|
||||
book: TsWorkbook;
|
||||
begin
|
||||
book := TsWorkbook.Create;
|
||||
try
|
||||
if AAutoDetect then
|
||||
book.ReadfromFile(AFileName)
|
||||
else
|
||||
book.ReadFromFile(AFileName, AFormatID);
|
||||
except
|
||||
book.AddErrorMsg(rsCannotReadFile, [AFileName]);
|
||||
// Code executed subsequently will be a pain if there is no worksheet!
|
||||
if book.GetWorksheetCount = 0 then
|
||||
book.AddWorksheet(Format(rsDefaultSheetName, [1]));
|
||||
end;
|
||||
|
||||
InternalLoadFromWorkbook(book, AWorksheetIndex);
|
||||
(*
|
||||
|
||||
|
||||
// Create a new empty workbook
|
||||
InternalCreateNewWorkbook;
|
||||
|
||||
@@ -968,6 +989,26 @@ begin
|
||||
end;
|
||||
SelectWorksheet(FWorkbook.GetWorkSheetByIndex(AWorksheetIndex));
|
||||
|
||||
// If required, display loading error message
|
||||
if FWorkbook.ErrorMsg <> '' then
|
||||
DoShowError(FWorkbook.ErrorMsg);
|
||||
*)
|
||||
end;
|
||||
|
||||
procedure TsWorkbookSource.InternalLoadFromWorkbook(AWorkbook: TsWorkbook;
|
||||
AWorksheetIndex: Integer = -1);
|
||||
begin
|
||||
InternalCreateNewWorkbook(AWorkbook);
|
||||
WorkbookOpenedHandler(self);
|
||||
|
||||
if AWorksheetIndex = -1 then
|
||||
begin
|
||||
if FWorkbook.ActiveWorksheet <> nil then
|
||||
AWorksheetIndex := FWorkbook.GetWorksheetIndex(FWorkbook.ActiveWorksheet) else
|
||||
AWorksheetIndex := 0;
|
||||
end;
|
||||
SelectWorksheet(FWorkbook.GetWorksheetByIndex(AWorksheetIndex));
|
||||
|
||||
// If required, display loading error message
|
||||
if FWorkbook.ErrorMsg <> '' then
|
||||
DoShowError(FWorkbook.ErrorMsg);
|
||||
@@ -1047,6 +1088,18 @@ begin
|
||||
InternalLoadFromFile(AFileName, true, sfNotNeeded, AWorksheetIndex);
|
||||
end; *)
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Uses an already existing workbook in the visual controls.
|
||||
|
||||
IMPORTANT: THE CALLING ROUTINE MUST NOT DESTROY THE WORKBOOK, it is destroyed
|
||||
here by the TsWorkbookSource.
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsWorkbookSource.LoadFromWorkbook(AWorkbook: TsWorkbook;
|
||||
AWorksheetIndex: Integer = -1);
|
||||
begin
|
||||
InternalLoadFromWorkbook(AWorkbook, AWorksheetIndex);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Notifies listeners of workbook, worksheet, cell, or selection changes.
|
||||
The changed item is identified by the parameter AChangedItems.
|
||||
|
@@ -276,6 +276,7 @@ type
|
||||
AFormatID: TsSpreadFormatID; AWorksheetIndex: Integer = -1); overload;
|
||||
procedure LoadFromSpreadsheetFile(AFileName: string;
|
||||
AWorksheetIndex: Integer = -1); overload;
|
||||
procedure LoadFromWorkbook(AWorkbook: TsWorkbook; AWorksheetIndex: Integer = -1);
|
||||
procedure NewWorkbook(AColCount, ARowCount: Integer);
|
||||
procedure SaveToSpreadsheetFile(AFileName: string;
|
||||
AOverwriteExisting: Boolean = true); overload;
|
||||
@@ -3709,6 +3710,23 @@ begin
|
||||
GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AWorksheetIndex);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Loads an existing workbook into the grid.
|
||||
|
||||
@param AWorkbook Workbook that had been created/loaded before.
|
||||
@param AWorksheetIndex Index of the worksheet to be shown in the grid
|
||||
(If empty then the active worksheet is loaded)
|
||||
|
||||
@Note THE CALLING PROCEDURE MUST NOT DESTROY THE WORKBOOK! The workbook will
|
||||
be destroyed by the workbook source.
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsCustomWorksheetGrid.LoadFromWorkbook(AWorkbook: TsWorkbook;
|
||||
AWorksheetIndex: Integer = -1);
|
||||
begin
|
||||
GetWorkbookSource.LoadFromWorkbook(AWorkbook, AWorksheetIndex);
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Notification message received from the WorkbookLink telling which item of the
|
||||
spreadsheet has changed.
|
||||
|
Reference in New Issue
Block a user