fpspreadsheet: Lots of cosmetics. Updated version of the chm help file.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3583 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-09-21 00:10:31 +00:00
parent b43fb99608
commit b2888a8042
7 changed files with 1045 additions and 792 deletions

View File

@ -46,6 +46,7 @@
<ComponentName Value="Form1"/> <ComponentName Value="Form1"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="main"/>
</Unit1> </Unit1>
</Units> </Units>
</ProjectOptions> </ProjectOptions>

View File

@ -22,11 +22,11 @@ object Form1: TForm1
OnChange = PageControlChange OnChange = PageControlChange
object TabDataGenerator: TTabSheet object TabDataGenerator: TTabSheet
Caption = '1 - Create database' Caption = '1 - Create database'
ClientHeight = 269 ClientHeight = 274
ClientWidth = 623 ClientWidth = 623
object Label2: TLabel object Label2: TLabel
Left = 4 Left = 4
Height = 20 Height = 15
Top = 4 Top = 4
Width = 615 Width = 615
Align = alTop Align = alTop
@ -38,25 +38,25 @@ object Form1: TForm1
end end
object Panel1: TPanel object Panel1: TPanel
Left = 0 Left = 0
Height = 241 Height = 251
Top = 28 Top = 23
Width = 623 Width = 623
Align = alClient Align = alClient
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 241 ClientHeight = 251
ClientWidth = 623 ClientWidth = 623
TabOrder = 0 TabOrder = 0
object HeaderLabel1: TLabel object HeaderLabel1: TLabel
Left = 8 Left = 8
Height = 20 Height = 15
Top = 11 Top = 11
Width = 88 Width = 71
Caption = 'Record count' Caption = 'Record count'
ParentColor = False ParentColor = False
end end
object EdRecordCount: TEdit object EdRecordCount: TEdit
Left = 107 Left = 107
Height = 28 Height = 23
Top = 8 Top = 8
Width = 64 Width = 64
Alignment = taRightJustify Alignment = taRightJustify
@ -66,7 +66,7 @@ object Form1: TForm1
object BtnCreateDbf: TButton object BtnCreateDbf: TButton
Left = 515 Left = 515
Height = 28 Height = 28
Top = 208 Top = 218
Width = 99 Width = 99
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
Caption = 'Run' Caption = 'Run'
@ -83,8 +83,8 @@ object Form1: TForm1
end end
object InfoLabel1: TLabel object InfoLabel1: TLabel
Left = 8 Left = 8
Height = 20 Height = 15
Top = 216 Top = 231
Width = 496 Width = 496
Anchors = [akLeft, akRight, akBottom] Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Around = 4 BorderSpacing.Around = 4
@ -93,9 +93,9 @@ object Form1: TForm1
end end
object Label1: TLabel object Label1: TLabel
Left = 8 Left = 8
Height = 20 Height = 15
Top = 40 Top = 40
Width = 409 Width = 324
Caption = 'Please note: the binary xls files can handle only 65536 records.' Caption = 'Please note: the binary xls files can handle only 65536 records.'
ParentColor = False ParentColor = False
end end
@ -149,7 +149,7 @@ object Form1: TForm1
ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1 ChildSizing.ControlsPerLine = 1
ClientHeight = 136 ClientHeight = 138
ClientWidth = 228 ClientWidth = 228
ItemIndex = 2 ItemIndex = 2
Items.Strings = ( Items.Strings = (

View File

@ -209,7 +209,7 @@ begin
worksheet.WriteColWidth(0, 20); worksheet.WriteColWidth(0, 20);
worksheet.WriteColWidth(1, 20); worksheet.WriteColWidth(1, 20);
worksheet.WriteColWidth(2, 20); worksheet.WriteColWidth(2, 20);
worksheet.WriteCOlWidth(3, 15); worksheet.WriteColWidth(3, 15);
// Setup virtual mode to save memory // Setup virtual mode to save memory
// FWorkbook.Options := FWorkbook.Options + [boVirtualMode, boBufStream]; // FWorkbook.Options := FWorkbook.Options + [boVirtualMode, boBufStream];

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@ type
end; end;
var var
InsDelTestData: array[0..21] of TInsDelTestDataItem; InsDelTestData: array[0..25] of TInsDelTestDataItem;
procedure InitTestData; procedure InitTestData;
@ -79,6 +79,12 @@ type
procedure TestWriteRead_InsDelColRow_20; // after formula cell procedure TestWriteRead_InsDelColRow_20; // after formula cell
procedure TestWriteRead_InsDelColRow_21; // cell in formula procedure TestWriteRead_InsDelColRow_21; // cell in formula
// Writes out cell layout with shared formula
procedure TestWriteRead_InsDelColRow_22; // no insert/delete; just test shared formula
// ... and inserts columns
procedure TestWriteRead_InsDelColRow_23; // column before shared formula cells
procedure TestWriteRead_InsDelColRow_24; // column after shared formula cells
procedure TestWriteRead_InsDelColRow_25; // column through cells addressed by shared formula
end; end;
implementation implementation
@ -87,7 +93,7 @@ uses
StrUtils; StrUtils;
const const
InsertColRowSheet = 'Insert_Columns_Rows'; InsertColRowSheet = 'InsertDelete_ColumnsRows';
procedure InitTestData; procedure InitTestData;
var var
@ -489,6 +495,103 @@ begin
'67890123'; '67890123';
end; end;
{ ---------------------------------------------------------------------------}
{ Layouts with shared formula }
{ ---------------------------------------------------------------------------}
// No insert/delete, just to test the shared formula
with InsDelTestData[22] do begin
Layout := '12345678|'+
'23456789|'+
'345S 890|'+ // "S" = shared formula (2 cols x 3 rows)
'456 901|'+
'567 012|'+
'67890123';
Formula := 'A3-$B$2';
SharedFormulaColCount := 2;
SharedFormulaRowCount := 3;
SollFormula := 'A3-$B$2,B3-$B$2;'+
'A4-$B$2,B4-$B$2;'+
'A5-$B$2,B5-$B$2';
// comma-separated --> cells along row; semicolon separates rows
SollLayout := '12345678|'+
'23456789|'+
'34501890|'+
'45612901|'+
'56723012|'+
'67890123';
end;
// Insert column before any cell referred to by the shared formula (col = 0)
with InsDelTestData[23] do begin
Layout := '12345678|'+
'23456789|'+
'345S 890|'+ // "S" = shared formula (2 cols x 3 rows)
'456 901|'+
'567 012|'+
'67890123';
InsertCol := 0;
Formula := 'A3-$B$2';
SharedFormulaColCount := 2;
SharedFormulaRowCount := 3;
SollFormula := 'B3-$C$2,C3-$C$2;'+ // all column indexes increase by 1 due to added col in front
'B4-$C$2,C4-$C$2;'+
'B5-$C$2,C5-$C$2';
// comma-separated --> cells along row; semicolon separates rows
SollLayout := ' 12345678|'+
' 23456789|'+
' 34501890|'+
' 45612901|'+
' 56723012|'+
' 67890123';
end;
// Insert column after last cell addressed by the shared formula
with InsDelTestData[24] do begin
Layout := '12345678|'+
'23456789|'+
'345S 890|'+ // "S" = shared formula (2 cols x 3 rows)
'456 901|'+
'567 012|'+
'67890123';
InsertCol := 7;
Formula := 'A3-$B$2';
SharedFormulaColCount := 2;
SharedFormulaRowCount := 3;
SollFormula := 'A3-$B$2,B3-$B$2;'+ // formulas unchanged by insert
'A4-$B$2,B4-$B$2;'+
'A5-$B$2,B5-$B$2';
// comma-separated --> cells along row; semicolon separates rows
SollLayout := '1234567 8|'+
'2345678 9|'+
'3450189 0|'+
'4561290 1|'+
'5672301 2|'+
'6789012 3';
end;
// Insert column between cells referred to by the shared formula (col = 1)
with InsDelTestData[25] do begin
Layout := '12345678|'+
'23456789|'+
'345S 890|'+ // "S" = shared formula (2 cols x 3 rows)
'456 901|'+
'567 012|'+
'67890123';
InsertCol := 1;
Formula := 'A3-$B$2';
SharedFormulaColCount := 2;
SharedFormulaRowCount := 3;
SollFormula := 'A3-$C$2,C3-$C$2;'+ // some column indexes increase by 1, some unchanged
'A4-$C$2,C4-$C$2;'+
'A5-$C$2,C5-$C$2';
SollLayout := '1 2345678|'+
'2 3456789|'+
'3 4501890|'+
'4 5612901|'+
'5 6723012|'+
'6 7890123';
end;
end; end;
@ -515,16 +618,40 @@ var
row, col: Integer; row, col: Integer;
MyCell: PCell; MyCell: PCell;
TempFile: string; //write xls/xml to this file and read back from it TempFile: string; //write xls/xml to this file and read back from it
L: TStringList; L, LL: TStringList;
s: String; s: String;
expected: String; expected: String;
actual: String; actual: String;
expectedFormulas: array of array of String;
begin begin
TempFile := GetTempFileName; TempFile := GetTempFileName;
L := TStringList.Create; L := TStringList.Create;
try try
// Extract soll formulas into a 2D array in case of shared formulas
if (InsDelTestData[ATestIndex].SharedFormulaRowCount > 0) or
(InsDelTestData[ATestIndex].SharedFormulaColCount > 0) then
begin
with InsDelTestData[ATestIndex] do
SetLength(expectedFormulas, SharedFormulaRowCount, SharedFormulaColCount);
L.Delimiter := ';';
L.DelimitedText := InsDelTestData[ATestIndex].SollFormula;
LL := TStringList.Create;
try
LL.Delimiter := ',';
for row := 0 to InsDelTestData[ATestIndex].SharedFormulaRowCount-1 do
begin
s := L[row];
LL.DelimitedText := L[row];
for col := 0 to InsDelTestData[ATestIndex].SharedFormulaColCount-1 do
expectedFormulas[row, col] := LL[col];
end;
finally
LL.Free;
end;
end;
L.Delimiter := '|'; L.Delimiter := '|';
L.StrictDelimiter := true; L.StrictDelimiter := true;
L.DelimitedText := InsDelTestData[ATestIndex].Layout; L.DelimitedText := InsDelTestData[ATestIndex].Layout;
@ -539,9 +666,16 @@ begin
s := L[row]; s := L[row];
for col := 0 to Length(s)-1 do for col := 0 to Length(s)-1 do
case s[col+1] of case s[col+1] of
' ' : ; // Leave cell empty
'0'..'9': MyWorksheet.WriteNumber(row, col, StrToInt(s[col+1])); '0'..'9': MyWorksheet.WriteNumber(row, col, StrToInt(s[col+1]));
'F' : MyWorksheet.WriteFormula(row, col, InsDelTestData[ATestIndex].Formula); 'F' : MyWorksheet.WriteFormula(row, col, InsDelTestData[ATestIndex].Formula);
' ' : ; 'S' : MyWorksheet.WriteSharedFormula(
row,
col,
row + InsDelTestData[ATestIndex].SharedFormulaRowCount-1,
col + InsDelTestData[ATestIndex].SharedFormulaColCount-1,
InsDelTestData[ATestIndex].Formula
);
end; end;
end; end;
@ -593,14 +727,21 @@ begin
end; end;
if HasFormula(MyCell) then if HasFormula(MyCell) then
begin begin
if MyCell^.SharedFormulaBase <> nil then
CheckEquals( CheckEquals(
expectedFormulas[row-MyCell^.SharedFormulaBase^.Row, col-MyCell^.SharedFormulaBase^.Col],
MyWorksheet.ReadFormulaAsString(MyCell), MyWorksheet.ReadFormulaAsString(MyCell),
'Shared formula mismatch, cell ' + CellNotation(MyWorksheet, Row, Col)
)
else
CheckEquals(
InsDelTestData[ATestIndex].SollFormula, InsDelTestData[ATestIndex].SollFormula,
MyWorksheet.ReadFormulaAsString(MyCell),
'Formula mismatch, cell '+CellNotation(MyWorksheet, Row, Col) 'Formula mismatch, cell '+CellNotation(MyWorksheet, Row, Col)
); );
end; end;
end; end;
CheckEquals(actual, expected, CheckEquals(expected, actual,
'Test empty cell layout mismatch, cell '+CellNotation(MyWorksheet, Row, Col)); 'Test empty cell layout mismatch, cell '+CellNotation(MyWorksheet, Row, Col));
end; end;
finally finally
@ -746,6 +887,31 @@ begin
TestWriteRead_InsDelColRow(21); TestWriteRead_InsDelColRow(21);
end; end;
procedure TSpreadWriteRead_InsDelColRow_Tests.TestWriteRead_InsDelColRow_22;
// no insert/delete; just test shared formula
begin
TestWriteRead_InsDelColRow(22);
end;
procedure TSpreadWriteRead_InsDelColRow_Tests.TestWriteRead_InsDelColRow_23;
// insert column before any cell addressed by the shared formula
begin
TestWriteRead_InsDelColRow(23);
end;
procedure TSpreadWriteRead_InsDelColRow_Tests.TestWriteRead_InsDelColRow_24;
// insert column after any cell addressed by the shared formula
begin
TestWriteRead_InsDelColRow(24);
end;
procedure TSpreadWriteRead_InsDelColRow_Tests.TestWriteRead_InsDelColRow_25;
// column through cells addressed by shared formula
begin
TestWriteRead_InsDelColRow(25);
end;
initialization initialization
RegisterTest(TSpreadWriteRead_InsDelColRow_Tests); RegisterTest(TSpreadWriteRead_InsDelColRow_Tests);
InitTestData; InitTestData;

View File

@ -828,21 +828,6 @@ begin
Result := 8; Result := 8;
end; end;
(*
{ Writes the borders of the cell range covered by a shared formula.
Needs to be overridden to write the column data (2 bytes in case of BIFF8). }
procedure TsSpreadBIFF8Writer.WriteSharedFormulaRange(AStream: TStream;
const ARange: TRect);
begin
inherited WriteSharedFormulaRange(AStream, ARange);
{
// Index to first column
AStream.WriteWord(WordToLE(ARange.Left));
// Index to last rcolumn
AStream.WriteWord(WordToLE(ARange.Right));
}
end;
*)
{ Helper function for writing a string with 8-bit length. Overridden version { Helper function for writing a string with 8-bit length. Overridden version
for BIFF8. Called for writing rpn formula string tokens. for BIFF8. Called for writing rpn formula string tokens.

View File

@ -1499,10 +1499,10 @@ begin
// For compatibility with other formats, convert offsets back to regular indexes. // For compatibility with other formats, convert offsets back to regular indexes.
if (rfRelRow in flags) if (rfRelRow in flags)
then r := ACell^.Row + dr then r := ACell^.Row + dr
else r := dr; //ACell^.SharedFormulaBase^.Row + dr; else r := dr;
if (rfRelCol in flags) if (rfRelCol in flags)
then c := ACell^.Col + dc then c := ACell^.Col + dc
else c := dc; //ACell^.SharedFormulaBase^.Col + dc; else c := dc;
case token of case token of
INT_EXCEL_TOKEN_TREFN_V: rpnItem := RPNCellValue(r, c, flags, rpnItem); INT_EXCEL_TOKEN_TREFN_V: rpnItem := RPNCellValue(r, c, flags, rpnItem);
INT_EXCEL_TOKEN_TREFN_R: rpnItem := RPNCellRef(r, c, flags, rpnItem); INT_EXCEL_TOKEN_TREFN_R: rpnItem := RPNCellRef(r, c, flags, rpnItem);
@ -2286,6 +2286,7 @@ procedure TsSpreadBIFFWriter.WriteRPNFormula(AStream: TStream;
var var
RPNLength: Word = 0; RPNLength: Word = 0;
RecordSizePos, StartPos, FinalPos: Int64; RecordSizePos, StartPos, FinalPos: Int64;
r1,c1,r2,c2: Cardinal;
begin begin
if (ARow >= FLimitations.MaxRowCount) or (ACol >= FLimitations.MaxColCount) then if (ARow >= FLimitations.MaxRowCount) or (ACol >= FLimitations.MaxColCount) then
exit; exit;
@ -2463,9 +2464,9 @@ begin
INT_EXCEL_TOKEN_TREFV : primaryExcelCode := INT_EXCEL_TOKEN_TREFN_V; INT_EXCEL_TOKEN_TREFV : primaryExcelCode := INT_EXCEL_TOKEN_TREFN_V;
INT_EXCEL_TOKEN_TREFA : primaryExcelCode := INT_EXCEL_TOKEN_TREFN_A; INT_EXCEL_TOKEN_TREFA : primaryExcelCode := INT_EXCEL_TOKEN_TREFN_A;
INT_EXCEL_TOKEN_TAREA_R: primaryExcelCode := INT_EXCEL_TOKEN_TAREAN_R; INT_EXCEL_TOKEN_TAREA_R : primaryExcelCode := INT_EXCEL_TOKEN_TAREAN_R;
INT_EXCEL_TOKEN_TAREA_V: primaryExcelCode := INT_EXCEL_TOKEN_TAREAN_V; INT_EXCEL_TOKEN_TAREA_V : primaryExcelCode := INT_EXCEL_TOKEN_TAREAN_V;
INT_EXCEL_TOKEN_TAREA_A: primaryExcelCode := INT_EXCEL_TOKEN_TAREAN_A; INT_EXCEL_TOKEN_TAREA_A : primaryExcelCode := INT_EXCEL_TOKEN_TAREAN_A;
end; end;
AStream.WriteByte(primaryExcelCode); AStream.WriteByte(primaryExcelCode);