📄 cell2.pas
字号:
unit Cell2;
{
********************************************************************************
******* XLSReadWriteII V2.00 *******
******* *******
******* Copyright(C) 1999,2004 Lars Arvidsson, Axolot Data *******
******* *******
******* email: components@axolot.com *******
******* URL: http://www.axolot.com *******
********************************************************************************
** Users of the XLSReadWriteII component must accept the following **
** disclaimer of warranty: **
** **
** XLSReadWriteII is supplied as is. The author disclaims all warranties, **
** expressedor implied, including, without limitation, the warranties of **
** merchantability and of fitness for any purpose. The author assumes no **
** liability for damages, direct or consequential, which may result from the **
** use of XLSReadWriteII. **
********************************************************************************
}
{$B-}
interface
uses Classes, SysUtils, Graphics, BIFFRecsII2, CellFormats2, XLSFonts2, SST2,
FormattedObj2;
// ctNotUsed was erlier ctRK.
type TCellType = (ctNone,ctBlank,ctNotUsed,ctInteger,ctFloat,ctString,ctBoolean,ctError,ctNumberFormula,ctStringFormula,ctBooleanFormula,ctErrorFormula,ctArrayFormula);
const TFormulaCellType = [ctNumberFormula,ctStringFormula,ctBooleanFormula,ctErrorFormula,ctArrayFormula];
const TNumCellType = [ctNotUsed,ctInteger,ctFloat,ctNumberFormula,ctArrayFormula];
type
//: Base class for all cell objects. Cell objects are never created directly
//: in code, instead they are created by the various methods that writes
//: values to to the cells.
TCell = class(TFormattedObject)
private
protected
FRowCol: longword;
public
destructor Destroy; override;
//: Returns the cell type. Implemented by the ancestor.
function CellType: TCellType; virtual; abstract;
//: @exclude
function MakeCopy: TCell; virtual;
//: @exclude
property RowCol: longword read FRowCol write FRowCol;
end;
type
//: A blank cell is a cell without a value, but that is formatted.
TBlankCell = class(TCell)
protected
public
constructor Create(RC: integer; Formats: TCellFormats; FormatIndex: word);
//: Returns the cell type, ctBlank.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
end;
type
//: A cell with a integer value.
TIntegerCell = class(TCell)
private
FValue: integer;
protected
public
constructor Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: integer);
//: Returns the cell type, ctInteger.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property Value: integer read FValue write FValue;
end;
type
//: A cell with a floating point value.
TFloatCell = class(TCell)
private
FValue: double;
protected
public
constructor Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: double);
//: Returns the cell type, ctFloat.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property Value: double read FValue write FValue;
end;
type
//: A cell with a string value.
TStringCell = class(TCell)
private
FValue: PXLSString;
protected
public
constructor Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: PXLSString);
//: Returns the cell type, ctString.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property Value: PXLSString read FValue write FValue;
end;
type
//: A cell with a boolean value.
TBooleanCell = class(TCell)
private
FValue: boolean;
protected
public
constructor Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: boolean);
//: Returns the cell type, ctBoolean.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property Value: boolean read FValue write FValue;
end;
type
//: A cell with a error value.
TErrorCell = class(TCell)
private
FValue: TCellError;
protected
public
constructor Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: TCellError);
//: Returns the cell type, ctError.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property Value: TCellError read FValue write FValue;
end;
type
//: Base class for formula cells.
TFormulaCell = class(TCell)
private
FPTGS: PByteArray;
FSize: integer;
FCalculated: boolean;
protected
public
constructor Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: PByteArray; Size: integer);
destructor Destroy; override;
property PTGS: PByteArray read FPTGS;
property Size: integer read FSize;
//: Returns true if the formula is calculated.
property Calculated: boolean read FCalculated write FCalculated;
end;
type
//: A formula cell with a floating point result.
TNumberFormulaCell = class(TFormulaCell)
private
FNumberValue: double;
public
//: Returns the cell type, ctNumberFormula.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property NumberValue: double read FNumberValue write FNumberValue;
end;
type
//: A formula cell with a string result.
TStringFormulaCell = class(TFormulaCell)
private
FStringValue: WideString;
public
//: Returns the cell type, ctStringFormula.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property StringValue: WideString read FStringValue write FStringValue;
end;
type
//: A formula cell with a boolean result.
TBooleanFormulaCell = class(TFormulaCell)
private
FBooleanValue: boolean;
public
//: Returns the cell type, ctBooleanFormula.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property BooleanValue: boolean read FBooleanValue write FBooleanValue;
end;
type
//: A formula cell with an error result.
TErrorFormulaCell = class(TFormulaCell)
private
FErrorValue: TCellError;
public
//: Returns the cell type, ctErrorFormula.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property ErrorValue: TCellError read FErrorValue write FErrorValue;
end;
type
//: A formula cell with an array result.
TArrayFormulaCell = class(TFormulaCell)
private
FNumberValue: double;
FArray: PByteArray;
FArraySize: integer;
public
constructor Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: PByteArray; Size: integer; Arr: PByteArray; ArrSize: integer);
destructor Destroy; override;
//: Returns the cell type, ctArrayFormula.
function CellType: TCellType; override;
function MakeCopy: TCell; override;
property NumberValue: double read FNumberValue write FNumberValue;
property ArrayData: PByteArray read FArray;
property ArraySize: integer read FArraySize;
end;
implementation
{ TBlankCell }
constructor TBlankCell.Create(RC: integer; Formats: TCellFormats; FormatIndex: word);
begin
inherited Create(Formats,FormatIndex);
RowCol := RC;
end;
function TBlankCell.CellType: TCellType;
begin
Result := ctBlank;
end;
function TBlankCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TBlankCell.Create(FRowCol,FFormats,FFormat.Index);
end;
{ TIntegerCell }
constructor TIntegerCell.Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: integer);
begin
inherited Create(Formats,FormatIndex);
RowCol := RC;
FValue := Val;
end;
function TIntegerCell.CellType: TCellType;
begin
Result := ctInteger;
end;
function TIntegerCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TIntegerCell.Create(FRowCol,FFormats,FFormat.Index,FValue);
end;
{ TFloatCell }
constructor TFloatCell.Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: double);
begin
inherited Create(Formats,FormatIndex);
RowCol := RC;
FValue := Val;
end;
function TFloatCell.CellType: TCellType;
begin
Result := ctFloat;
end;
function TFloatCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TFloatCell.Create(FRowCol,FFormats,FFormat.Index,FValue);
end;
{ TStringCell }
constructor TStringCell.Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: PXLSString);
begin
inherited Create(Formats,FormatIndex);
RowCol := RC;
FValue := Val;
end;
function TStringCell.CellType: TCellType;
begin
Result := ctString;
end;
function TStringCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TStringCell.Create(FRowCol,FFormats,FFormat.Index,FValue);
Inc(TStringCell(Result).Value.RefCount);
end;
{ TBooleanCell }
constructor TBooleanCell.Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: boolean);
begin
inherited Create(Formats,FormatIndex);
RowCol := RC;
FValue := Val;
end;
function TBooleanCell.CellType: TCellType;
begin
Result := ctBoolean;
end;
function TBooleanCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TBooleanCell.Create(FRowCol,FFormats,FFormat.Index,FValue);
end;
{ TErrorCell }
constructor TErrorCell.Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: TCellError);
begin
inherited Create(Formats,FormatIndex);
RowCol := RC;
FValue := Val;
end;
function TErrorCell.CellType: TCellType;
begin
Result := ctError;
end;
function TErrorCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TErrorCell.Create(FRowCol,FFormats,FFormat.Index,FValue);
end;
{ TFormulaCell }
constructor TFormulaCell.Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: PByteArray; Size: integer);
begin
inherited Create(Formats,FormatIndex);
RowCol := RC;
FSize := Size;
GetMem(FPTGS,FSize);
Move(Val^,FPTGS^,FSize);
end;
destructor TFormulaCell.Destroy;
begin
if FPTGS <> Nil then
FreeMem(FPTGS);
inherited;
end;
function TNumberFormulaCell.CellType: TCellType;
begin
Result := ctNumberFormula;
end;
function TNumberFormulaCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TNumberFormulaCell.Create(FRowCol,FFormats,FFormat.Index,FPTGS,FSize);
end;
function TStringFormulaCell.CellType: TCellType;
begin
Result := ctStringFormula;
end;
function TStringFormulaCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TStringFormulaCell.Create(FRowCol,FFormats,FFormat.Index,FPTGS,FSize);
end;
function TBooleanFormulaCell.CellType: TCellType;
begin
Result := ctBooleanFormula;
end;
function TBooleanFormulaCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TBooleanFormulaCell.Create(FRowCol,FFormats,FFormat.Index,FPTGS,FSize);
end;
{ TErrorFormulaCell }
function TErrorFormulaCell.CellType: TCellType;
begin
Result := ctErrorFormula;
end;
function TErrorFormulaCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TErrorFormulaCell.Create(FRowCol,FFormats,FFormat.Index,FPTGS,FSize);
end;
{ TArrayFormulaCell }
constructor TArrayFormulaCell.Create(RC: integer; Formats: TCellFormats; FormatIndex: word; Val: PByteArray;
Size: integer; Arr: PByteArray; ArrSize: integer);
begin
inherited Create(RC,Formats,FormatIndex,Val,Size);
FArraySize := ArrSize;
GetMem(FArray,ArrSize);
Move(Arr^,FArray^,ArrSize);
end;
destructor TArrayFormulaCell.Destroy;
begin
FreeMem(FArray);
inherited;
end;
function TArrayFormulaCell.CellType: TCellType;
begin
Result := ctArrayFormula;
end;
function TArrayFormulaCell.MakeCopy: TCell;
begin
inherited MakeCopy;
Result := TArrayFormulaCell.Create(FRowCol,FFormats,FFormat.Index,FPTGS,FSize,FArray,FArraySize);
end;
{ TCell }
destructor TCell.Destroy;
begin
if FFormat.Index >= FFormats.DeleteIndex then begin
FFormat.UsageCount := FFormat.UsageCount - 1;
if FFormat.UsageCount <= 0 then
FFormats.Delete(FFormat.Index);
end;
inherited;
end;
function TCell.MakeCopy: TCell;
begin
FFormat.UsageCount := FFormat.UsageCount + 1;
Result := Nil;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -