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"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="main"/>
</Unit1>
</Units>
</ProjectOptions>

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@ type
end;
var
InsDelTestData: array[0..21] of TInsDelTestDataItem;
InsDelTestData: array[0..25] of TInsDelTestDataItem;
procedure InitTestData;
@ -79,6 +79,12 @@ type
procedure TestWriteRead_InsDelColRow_20; // after formula cell
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;
implementation
@ -87,7 +93,7 @@ uses
StrUtils;
const
InsertColRowSheet = 'Insert_Columns_Rows';
InsertColRowSheet = 'InsertDelete_ColumnsRows';
procedure InitTestData;
var
@ -489,6 +495,103 @@ begin
'67890123';
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;
@ -515,16 +618,40 @@ var
row, col: Integer;
MyCell: PCell;
TempFile: string; //write xls/xml to this file and read back from it
L: TStringList;
L, LL: TStringList;
s: String;
expected: String;
actual: String;
expectedFormulas: array of array of String;
begin
TempFile := GetTempFileName;
L := TStringList.Create;
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.StrictDelimiter := true;
L.DelimitedText := InsDelTestData[ATestIndex].Layout;
@ -539,9 +666,16 @@ begin
s := L[row];
for col := 0 to Length(s)-1 do
case s[col+1] of
' ' : ; // Leave cell empty
'0'..'9': MyWorksheet.WriteNumber(row, col, StrToInt(s[col+1]));
'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;
@ -593,14 +727,21 @@ begin
end;
if HasFormula(MyCell) then
begin
CheckEquals(
MyWorksheet.ReadFormulaAsString(MyCell),
InsDelTestData[ATestIndex].SollFormula,
'Formula mismatch, cell '+CellNotation(MyWorksheet, Row, Col)
);
if MyCell^.SharedFormulaBase <> nil then
CheckEquals(
expectedFormulas[row-MyCell^.SharedFormulaBase^.Row, col-MyCell^.SharedFormulaBase^.Col],
MyWorksheet.ReadFormulaAsString(MyCell),
'Shared formula mismatch, cell ' + CellNotation(MyWorksheet, Row, Col)
)
else
CheckEquals(
InsDelTestData[ATestIndex].SollFormula,
MyWorksheet.ReadFormulaAsString(MyCell),
'Formula mismatch, cell '+CellNotation(MyWorksheet, Row, Col)
);
end;
end;
CheckEquals(actual, expected,
CheckEquals(expected, actual,
'Test empty cell layout mismatch, cell '+CellNotation(MyWorksheet, Row, Col));
end;
finally
@ -746,6 +887,31 @@ begin
TestWriteRead_InsDelColRow(21);
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
RegisterTest(TSpreadWriteRead_InsDelColRow_Tests);
InitTestData;

View File

@ -828,21 +828,6 @@ begin
Result := 8;
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
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.
if (rfRelRow in flags)
then r := ACell^.Row + dr
else r := dr; //ACell^.SharedFormulaBase^.Row + dr;
else r := dr;
if (rfRelCol in flags)
then c := ACell^.Col + dc
else c := dc; //ACell^.SharedFormulaBase^.Col + dc;
else c := dc;
case token of
INT_EXCEL_TOKEN_TREFN_V: rpnItem := RPNCellValue(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
RPNLength: Word = 0;
RecordSizePos, StartPos, FinalPos: Int64;
r1,c1,r2,c2: Cardinal;
begin
if (ARow >= FLimitations.MaxRowCount) or (ACol >= FLimitations.MaxColCount) then
exit;
@ -2459,13 +2460,13 @@ begin
if UseRelAddr then
case primaryExcelCode of
INT_EXCEL_TOKEN_TREFR : primaryExcelCode := INT_EXCEL_TOKEN_TREFN_R;
INT_EXCEL_TOKEN_TREFV : primaryExcelCode := INT_EXCEL_TOKEN_TREFN_V;
INT_EXCEL_TOKEN_TREFA : primaryExcelCode := INT_EXCEL_TOKEN_TREFN_A;
INT_EXCEL_TOKEN_TREFR : primaryExcelCode := INT_EXCEL_TOKEN_TREFN_R;
INT_EXCEL_TOKEN_TREFV : primaryExcelCode := INT_EXCEL_TOKEN_TREFN_V;
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_V: primaryExcelCode := INT_EXCEL_TOKEN_TAREAN_V;
INT_EXCEL_TOKEN_TAREA_A: primaryExcelCode := INT_EXCEL_TOKEN_TAREAN_A;
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_A : primaryExcelCode := INT_EXCEL_TOKEN_TAREAN_A;
end;
AStream.WriteByte(primaryExcelCode);