You've already forked lazarus-ccr
fpspreadsheet: Add worksheet option soAutoDetectCellType
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7059 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1183,7 +1183,7 @@ begin
|
||||
|
||||
InitCryptoInfo(FCryptoInfo);
|
||||
|
||||
FOptions := [soShowGridLines, soShowHeaders];
|
||||
FOptions := [soShowGridLines, soShowHeaders, soAutoDetectCellType];
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -5274,21 +5274,17 @@ begin
|
||||
isPercent := Pos('%', AValue) = Length(AValue);
|
||||
if isPercent then Delete(AValue, Length(AValue), 1);
|
||||
|
||||
{
|
||||
if IsTextFormat(numFmtParams) then
|
||||
begin
|
||||
WriteText(ACell, AValue);
|
||||
exit;
|
||||
end;
|
||||
}
|
||||
|
||||
// Try to detect the cell content type automatically
|
||||
if TryStrToCurrency(AValue, number, currSym, AFormatSettings) then
|
||||
begin
|
||||
if (soAutoDetectCellType in FOptions) then begin
|
||||
WriteCurrency(ACell, number, nfCurrencyRed, -1, currSym);
|
||||
if IsTextFormat(numFmtParams) then begin
|
||||
WriteNumberFormat(ACell, nfText);
|
||||
WriteText(ACell, AValue);
|
||||
end;
|
||||
end else
|
||||
WriteNumber(ACell, number);
|
||||
exit;
|
||||
end;
|
||||
|
||||
@ -5296,18 +5292,21 @@ begin
|
||||
if TryFractionStrToFloat(AValue, number, ismixed, maxdig) then
|
||||
begin
|
||||
WriteNumber(ACell, number);
|
||||
if (soAutoDetectCellType in FOptions) then begin
|
||||
WriteFractionFormat(ACell, ismixed, maxdig, maxdig);
|
||||
if IsTextFormat(numFmtParams) then
|
||||
begin
|
||||
WriteNumberFormat(ACell, nfText);
|
||||
WriteText(ACell, AValue);
|
||||
end;
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
|
||||
// Check for a "number" value (floating point, or integer)
|
||||
if TryStrToFloat(AValue, number, AFormatSettings) then
|
||||
begin
|
||||
if (soAutoDetectCellType in FOptions) then begin
|
||||
if isPercent then
|
||||
WriteNumber(ACell, number/100, nfPercentage)
|
||||
else
|
||||
@ -5322,14 +5321,19 @@ begin
|
||||
WriteNumberFormat(ACell, nfText);
|
||||
WriteText(ACell, AValue);
|
||||
end;
|
||||
end else
|
||||
// Use pre-formatted style
|
||||
WriteNumber(ACell, number);
|
||||
exit;
|
||||
end;
|
||||
|
||||
|
||||
// Check for a date/time value:
|
||||
// Must be after float detection because StrToDateTime will accept a string
|
||||
// "1" as a valid date/time.
|
||||
if TryStrToDateTime(AValue, number, AFormatSettings) then
|
||||
begin
|
||||
if (soAutoDetectCellType in FOptions) then begin
|
||||
if number < 1.0 then // this is a time alone
|
||||
begin
|
||||
if not IsTimeFormat(numFmtParams) then
|
||||
@ -5357,6 +5361,9 @@ begin
|
||||
WriteNumberFormat(ACell, nfText);
|
||||
WriteText(ACell, AValue);
|
||||
end;
|
||||
end else
|
||||
// Use pre-formatted style
|
||||
WriteDateTime(ACell, number);
|
||||
exit;
|
||||
end;
|
||||
|
||||
|
@ -896,9 +896,10 @@ type
|
||||
is defined by LeftPaneWidth and TopPaneHeight.
|
||||
@param soHidden Worksheet is hidden.
|
||||
@param soProtected Worksheet is protected
|
||||
@param soPanesProtection Panes are locked due to workbook protection }
|
||||
@param soPanesProtection Panes are locked due to workbook protection
|
||||
@param soAutoDetectCellType Auomatically detect type of cell content}
|
||||
TsSheetOption = (soShowGridLines, soShowHeaders, soHasFrozenPanes, soHidden,
|
||||
soProtected, soPanesProtection);
|
||||
soProtected, soPanesProtection, soAutoDetectCellType);
|
||||
|
||||
{@@ Set of user interface options
|
||||
@ see TsSheetOption }
|
||||
|
@ -99,6 +99,7 @@ type
|
||||
FEditing: Boolean;
|
||||
FCellFont: TFont;
|
||||
FAutoCalc: Boolean;
|
||||
FAutoDetectCellType: Boolean;
|
||||
FTextOverflow: Boolean;
|
||||
FReadFormulas: Boolean;
|
||||
FDrawingCell: PCell;
|
||||
@ -187,6 +188,7 @@ type
|
||||
function GetWordwraps(ALeft, ATop, ARight, ABottom: Integer): Boolean;
|
||||
function GetZoomFactor: Double;
|
||||
procedure SetAutoCalc(AValue: Boolean);
|
||||
procedure SetAutoDetectCellType(AValue: Boolean);
|
||||
procedure SetBackgroundColor(ACol, ARow: Integer; AValue: TsColor);
|
||||
procedure SetBackgroundColors(ALeft, ATop, ARight, ABottom: Integer; AValue: TsColor);
|
||||
procedure SetCellBiDiMode(ACol, ARow: Integer; AValue: TsBiDiMode);
|
||||
@ -338,6 +340,9 @@ type
|
||||
write FAllowDragAndDrop default true;
|
||||
{@@ Automatically recalculate formulas whenever a cell value changes. }
|
||||
property AutoCalc: Boolean read FAutoCalc write SetAutoCalc default false;
|
||||
{@@ Automatically detect the cell's content type }
|
||||
property AutoDetectCellType: Boolean read FAutoDetectCellType
|
||||
write SetAutoDetectCellType default true;
|
||||
{@@ Automatically expand grid dimensions }
|
||||
property AutoExpand: TsAutoExpandModes read FAutoExpand write FAutoExpand
|
||||
default [aeData, aeNavigation, aeDefault];
|
||||
@ -618,6 +623,8 @@ type
|
||||
property AllowDragAndDrop;
|
||||
{@@ Automatically recalculates the worksheet formulas if a cell value changes. }
|
||||
property AutoCalc;
|
||||
{@@ Automatically detect the cell's content type }
|
||||
property AutoDetectCellType;
|
||||
{@@ Automatically expand grid dimensions }
|
||||
property AutoExpand;
|
||||
{@@ Displays column and row headers in the fixed col/row style of the grid.
|
||||
@ -1312,6 +1319,7 @@ begin
|
||||
AutoAdvance := aaDown;
|
||||
ExtendedSelect := true;
|
||||
FHeaderCount := 1;
|
||||
FAutoDetectCellType := true;
|
||||
ColCount := DEFAULT_COL_COUNT + FHeaderCount;
|
||||
RowCount := DEFAULT_ROW_COUNT + FHeaderCount;
|
||||
|
||||
@ -1970,6 +1978,7 @@ begin
|
||||
WorkbookSource.Options := WorkbookSource.Options + [boReadFormulas] else
|
||||
WorkbookSource.Options := Workbooksource.Options - [boReadFormulas];
|
||||
SetAutoCalc(FAutoCalc);
|
||||
SetAutoDetectCellType(FAutoDetectCellType);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -4709,6 +4718,7 @@ begin
|
||||
ae := RelaxAutoExpand;
|
||||
GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AFormat, AWorksheetIndex);
|
||||
RestoreAutoExpand(ae);
|
||||
SetAutoDetectCellType(FAutoDetectCellType);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -4731,6 +4741,7 @@ begin
|
||||
ae := RelaxAutoExpand;
|
||||
GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AFormatID, AWorksheetIndex);
|
||||
RestoreAutoExpand(ae);
|
||||
SetAutoDetectCellType(FAutoDetectCellType);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -4751,6 +4762,7 @@ begin
|
||||
ae := RelaxAutoExpand;
|
||||
GetWorkbookSource.LoadFromSpreadsheetFile(AFilename, AFormatID, AWorksheetIndex);
|
||||
RestoreAutoExpand(ae);
|
||||
SetAutoDetectCellType(FAutoDetectCellType);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -4771,6 +4783,7 @@ begin
|
||||
ae := RelaxAutoExpand;
|
||||
GetWorkbookSource.LoadFromWorkbook(AWorkbook, AWorksheetIndex);
|
||||
RestoreAutoExpand(ae);
|
||||
SetAutoDetectCellType(FAutoDetectCellType);
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
@ -6303,6 +6316,18 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TsCustomWorksheetGrid.SetAutoDetectCellType(AValue: Boolean);
|
||||
begin
|
||||
FAutoDetectCellType := AValue;
|
||||
|
||||
if Assigned(Worksheet) then begin
|
||||
if FAutoDetectCellType then
|
||||
Worksheet.Options := Worksheet.Options + [soAutoDetectCellType]
|
||||
else
|
||||
Worksheet.Options := Worksheet.Options - [soAutoDetectCellType];
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TsCustomWorksheetGrid.SetBackgroundColor(ACol, ARow: Integer;
|
||||
AValue: TsColor);
|
||||
var
|
||||
|
Reference in New Issue
Block a user