You've already forked lazarus-ccr
fpspreadsheet: Implement text rotation for BIFF5. Add text rotation test cases for BIIF5 and BIFF8 (no text rotation in BIFF2 by design). Pass.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2974 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -1,21 +1,23 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
|
<Version Value="9"/>
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
<Version Value="7"/>
|
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
<LRSInOutputDirectory Value="False"/>
|
<LRSInOutputDirectory Value="False"/>
|
||||||
</Flags>
|
</Flags>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
<TargetFileExt Value=".exe"/>
|
|
||||||
<Title Value="excel5read"/>
|
<Title Value="excel5read"/>
|
||||||
<UseAppBundle Value="False"/>
|
<UseAppBundle Value="False"/>
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
<VersionInfo>
|
||||||
<ProjectVersion Value=""/>
|
<StringTable ProductVersion=""/>
|
||||||
</VersionInfo>
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
<IgnoreBinaries Value="False"/>
|
<IgnoreBinaries Value="False"/>
|
||||||
@@ -42,12 +44,17 @@
|
|||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="8"/>
|
<Version Value="11"/>
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<OtherUnitFiles Value="..\"/>
|
<OtherUnitFiles Value=".."/>
|
||||||
<SrcPath Value="..\"/>
|
<SrcPath Value=".."/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
|
<Parsing>
|
||||||
|
<SyntaxOptions>
|
||||||
|
<UseAnsiStrings Value="False"/>
|
||||||
|
</SyntaxOptions>
|
||||||
|
</Parsing>
|
||||||
<Other>
|
<Other>
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
</Other>
|
</Other>
|
||||||
|
@@ -37,9 +37,6 @@ begin
|
|||||||
|
|
||||||
// Write some cells
|
// Write some cells
|
||||||
MyWorksheet.WriteNumber(0, 0, 1.0);// A1
|
MyWorksheet.WriteNumber(0, 0, 1.0);// A1
|
||||||
MyWorksheet.WriteUsedFormatting(0, 0, [uffBold]);
|
|
||||||
MyWorksheet.WriteBackgroundColor(0, 0, scRed);
|
|
||||||
|
|
||||||
MyWorksheet.WriteNumber(0, 1, 2.0);// B1
|
MyWorksheet.WriteNumber(0, 1, 2.0);// B1
|
||||||
MyWorksheet.WriteNumber(0, 2, 3.0);// C1
|
MyWorksheet.WriteNumber(0, 2, 3.0);// C1
|
||||||
MyWorksheet.WriteNumber(0, 3, 4.0);// D1
|
MyWorksheet.WriteNumber(0, 3, 4.0);// D1
|
||||||
@@ -59,11 +56,11 @@ begin
|
|||||||
MyWorksheet.WriteUTF8Text(4, 5, 'Stacked text');
|
MyWorksheet.WriteUTF8Text(4, 5, 'Stacked text');
|
||||||
MyWorksheet.WriteTextRotation(4, 5, rtStacked);
|
MyWorksheet.WriteTextRotation(4, 5, rtStacked);
|
||||||
|
|
||||||
MyWorksheet.WriteUTF8Text(4, 5, 'Rotated text');
|
MyWorksheet.WriteUTF8Text(4, 6, 'CW-rotated text');
|
||||||
MyWorksheet.WriteTextRotation(4, 5, rt90DegreeClockwiseRotation);
|
MyWorksheet.WriteTextRotation(4, 6, rt90DegreeClockwiseRotation);
|
||||||
|
|
||||||
MyWorksheet.WriteUTF8Text(4, 6, 'Rotated text');
|
MyWorksheet.WriteUTF8Text(4, 7, 'CCW-rotated text');
|
||||||
MyWorksheet.WriteTextRotation(4, 5, rt90DegreeCounterClockwiseRotation);
|
MyWorksheet.WriteTextRotation(4, 7, rt90DegreeCounterClockwiseRotation);
|
||||||
|
|
||||||
// Write current date/time
|
// Write current date/time
|
||||||
MyWorksheet.WriteDateTime(5, 0, now);
|
MyWorksheet.WriteDateTime(5, 0, now);
|
||||||
|
@@ -49,6 +49,8 @@ type
|
|||||||
procedure TestWriteReadBorder(AFormat: TsSpreadsheetFormat);
|
procedure TestWriteReadBorder(AFormat: TsSpreadsheetFormat);
|
||||||
// Test column widths
|
// Test column widths
|
||||||
procedure TestWriteReadColWidths(AFormat: TsSpreadsheetFormat);
|
procedure TestWriteReadColWidths(AFormat: TsSpreadsheetFormat);
|
||||||
|
// Test text rotation
|
||||||
|
procedure TestWriteReadTextRotation(AFormat:TsSpreadsheetFormat);
|
||||||
// Test word wrapping
|
// Test word wrapping
|
||||||
procedure TestWriteReadWordWrap(AFormat: TsSpreadsheetFormat);
|
procedure TestWriteReadWordWrap(AFormat: TsSpreadsheetFormat);
|
||||||
|
|
||||||
@@ -60,17 +62,22 @@ type
|
|||||||
procedure TestWriteReadBIFF2_Alignment;
|
procedure TestWriteReadBIFF2_Alignment;
|
||||||
procedure TestWriteReadBIFF2_Border;
|
procedure TestWriteReadBIFF2_Border;
|
||||||
procedure TestWriteReadBIFF2_ColWidths;
|
procedure TestWriteReadBIFF2_ColWidths;
|
||||||
|
// These features are not supported by Excel2 --> no test cases required!
|
||||||
|
// - TextRotation
|
||||||
|
// - Wordwrap
|
||||||
|
|
||||||
{ BIFF5 Tests }
|
{ BIFF5 Tests }
|
||||||
procedure TestWriteReadBIFF5_Alignment;
|
procedure TestWriteReadBIFF5_Alignment;
|
||||||
procedure TestWriteReadBIFF5_Border;
|
procedure TestWriteReadBIFF5_Border;
|
||||||
procedure TestWriteReadBIFF5_ColWidths;
|
procedure TestWriteReadBIFF5_ColWidths;
|
||||||
|
procedure TestWriteReadBIFF5_TextRotation;
|
||||||
procedure TestWriteReadBIFF5_WordWrap;
|
procedure TestWriteReadBIFF5_WordWrap;
|
||||||
|
|
||||||
{ BIFF8 Tests }
|
{ BIFF8 Tests }
|
||||||
procedure TestWriteReadBIFF8_Alignment;
|
procedure TestWriteReadBIFF8_Alignment;
|
||||||
procedure TestWriteReadBIFF8_Border;
|
procedure TestWriteReadBIFF8_Border;
|
||||||
procedure TestWriteReadBIFF8_ColWidths;
|
procedure TestWriteReadBIFF8_ColWidths;
|
||||||
|
procedure TestWriteReadBIFF8_TextRotation;
|
||||||
procedure TestWriteReadBIFF8_WordWrap;
|
procedure TestWriteReadBIFF8_WordWrap;
|
||||||
procedure TestWriteReadNumberFormats;
|
procedure TestWriteReadNumberFormats;
|
||||||
// Repeat with date/times
|
// Repeat with date/times
|
||||||
@@ -88,6 +95,7 @@ const
|
|||||||
ColWidthSheet = 'ColWidths';
|
ColWidthSheet = 'ColWidths';
|
||||||
BordersSheet = 'CellBorders';
|
BordersSheet = 'CellBorders';
|
||||||
AlignmentSheet = 'TextAlignments';
|
AlignmentSheet = 'TextAlignments';
|
||||||
|
TextRotationSheet = 'TextRotation';
|
||||||
WordwrapSheet = 'Wordwrap';
|
WordwrapSheet = 'Wordwrap';
|
||||||
|
|
||||||
// Initialize array with variables that represent the values
|
// Initialize array with variables that represent the values
|
||||||
@@ -513,6 +521,69 @@ begin
|
|||||||
TestWriteReadColWidths(sfExcel8);
|
TestWriteReadColWidths(sfExcel8);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadFormatTests.TestWriteReadTextRotation(AFormat: TsSpreadsheetFormat);
|
||||||
|
const
|
||||||
|
col = 0;
|
||||||
|
var
|
||||||
|
MyWorksheet: TsWorksheet;
|
||||||
|
MyWorkbook: TsWorkbook;
|
||||||
|
MyCell: PCell;
|
||||||
|
ActualColWidth: Single;
|
||||||
|
tr: TsTextRotation;
|
||||||
|
row: Integer;
|
||||||
|
TempFile: string; //write xls/xml to this file and read back from it
|
||||||
|
begin
|
||||||
|
TempFile:=GetTempFileName;
|
||||||
|
{// Not needed: use workbook.writetofile with overwrite=true
|
||||||
|
if fileexists(TempFile) then
|
||||||
|
DeleteFile(TempFile);
|
||||||
|
}
|
||||||
|
// Write out all test values
|
||||||
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
MyWorkSheet:= MyWorkBook.AddWorksheet(TextRotationSheet);
|
||||||
|
for tr := Low(TsTextRotation) to High(TsTextRotation) do begin
|
||||||
|
row := ord(tr);
|
||||||
|
MyWorksheet.WriteTextRotation(row, col, tr);
|
||||||
|
MyCell := MyWorksheet.GetCell(row, col);
|
||||||
|
CheckEquals(ord(tr), ord(MyCell^.TextRotation),
|
||||||
|
'Test unsaved textrotation mismatch, cell ' + CellNotation(MyWorksheet, row, col));
|
||||||
|
end;
|
||||||
|
MyWorkBook.WriteToFile(TempFile, AFormat, true);
|
||||||
|
MyWorkbook.Free;
|
||||||
|
|
||||||
|
// Open the spreadsheet
|
||||||
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
MyWorkbook.ReadFromFile(TempFile, AFormat);
|
||||||
|
if AFormat = sfExcel2 then
|
||||||
|
MyWorksheet := MyWorkbook.GetFirstWorksheet
|
||||||
|
else
|
||||||
|
MyWorksheet := GetWorksheetByName(MyWorkBook, TextRotationSheet);
|
||||||
|
if MyWorksheet=nil then
|
||||||
|
fail('Error in test code. Failed to get named worksheet');
|
||||||
|
for row := 0 to MyWorksheet.GetLastRowNumber do begin
|
||||||
|
MyCell := MyWorksheet.FindCell(row, col);
|
||||||
|
if MyCell = nil then
|
||||||
|
fail('Error in test code. Failed to get cell');
|
||||||
|
tr := MyCell^.TextRotation;
|
||||||
|
CheckEquals(ord(TsTextRotation(row)), ord(MyCell^.TextRotation),
|
||||||
|
'Test saved textrotation mismatch, cell ' + CellNotation(MyWorksheet, row, col));
|
||||||
|
end;
|
||||||
|
// Finalization
|
||||||
|
MyWorkbook.Free;
|
||||||
|
|
||||||
|
DeleteFile(TempFile);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_TextRotation;
|
||||||
|
begin
|
||||||
|
TestWriteReadTextRotation(sfExcel5);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_TextRotation;
|
||||||
|
begin
|
||||||
|
TestWriteReadTextRotation(sfExcel8);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSpreadWriteReadFormatTests.TestWriteReadWordWrap(AFormat: TsSpreadsheetFormat);
|
procedure TSpreadWriteReadFormatTests.TestWriteReadWordWrap(AFormat: TsSpreadsheetFormat);
|
||||||
const
|
const
|
||||||
LONGTEXT = 'This is a very, very, very, very long text.';
|
LONGTEXT = 'This is a very, very, very, very long text.';
|
||||||
|
@@ -1734,6 +1734,14 @@ begin
|
|||||||
// Word wrap
|
// Word wrap
|
||||||
lData.WordWrap := (xf.Align_TextBreak and MASK_XF_TEXTWRAP) <> 0;
|
lData.WordWrap := (xf.Align_TextBreak and MASK_XF_TEXTWRAP) <> 0;
|
||||||
|
|
||||||
|
// Text rotation
|
||||||
|
case xf.XFRotation of
|
||||||
|
XF_ROTATION_HORIZONTAL : lData.TextRotation := trHorizontal;
|
||||||
|
XF_ROTATION_90DEG_CCW : ldata.TextRotation := rt90DegreeCounterClockwiseRotation;
|
||||||
|
XF_ROTATION_90DEG_CW : lData.TextRotation := rt90DegreeClockwiseRotation;
|
||||||
|
XF_ROTATION_STACKED : lData.TextRotation := rtStacked;
|
||||||
|
end;
|
||||||
|
|
||||||
// Cell borders and background
|
// Cell borders and background
|
||||||
xf.Border_Background_1 := DWordLEToN(xf.Border_Background_1);
|
xf.Border_Background_1 := DWordLEToN(xf.Border_Background_1);
|
||||||
xf.Border_Background_2 := DWordLEToN(xf.Border_Background_2);
|
xf.Border_Background_2 := DWordLEToN(xf.Border_Background_2);
|
||||||
|
@@ -2317,6 +2317,14 @@ begin
|
|||||||
// Word wrap
|
// Word wrap
|
||||||
lData.WordWrap := (xf.Align_TextBreak and MASK_XF_TEXTWRAP) <> 0;
|
lData.WordWrap := (xf.Align_TextBreak and MASK_XF_TEXTWRAP) <> 0;
|
||||||
|
|
||||||
|
// TextRotation
|
||||||
|
case xf.XFRotation of
|
||||||
|
XF_ROTATION_HORIZONTAL : lData.TextRotation := trHorizontal;
|
||||||
|
XF_ROTATION_90DEG_CCW : ldata.TextRotation := rt90DegreeCounterClockwiseRotation;
|
||||||
|
XF_ROTATION_90DEG_CW : lData.TextRotation := rt90DegreeClockwiseRotation;
|
||||||
|
XF_ROTATION_STACKED : lData.TextRotation := rtStacked;
|
||||||
|
end;
|
||||||
|
|
||||||
// Cell borders
|
// Cell borders
|
||||||
xf.Border_Background_1 := DWordLEToN(xf.Border_Background_1);
|
xf.Border_Background_1 := DWordLEToN(xf.Border_Background_1);
|
||||||
lData.Borders := [];
|
lData.Borders := [];
|
||||||
|
@@ -305,6 +305,7 @@ type
|
|||||||
HorAlignment: TsHorAlignment;
|
HorAlignment: TsHorAlignment;
|
||||||
VertAlignment: TsVertAlignment;
|
VertAlignment: TsVertAlignment;
|
||||||
WordWrap: Boolean;
|
WordWrap: Boolean;
|
||||||
|
TextRotation: TsTextRotation;
|
||||||
Borders: TsCellBorders;
|
Borders: TsCellBorders;
|
||||||
BackgroundColor: TsColor;
|
BackgroundColor: TsColor;
|
||||||
end;
|
end;
|
||||||
@@ -470,6 +471,13 @@ begin
|
|||||||
else
|
else
|
||||||
Exclude(lCell^.UsedFormattingFields, uffWordWrap);
|
Exclude(lCell^.UsedFormattingFields, uffWordWrap);
|
||||||
|
|
||||||
|
// Text rotation
|
||||||
|
if XFData.TextRotation > trHorizontal then
|
||||||
|
Include(lCell^.UsedFormattingFields, uffTextRotation)
|
||||||
|
else
|
||||||
|
Exclude(lCell^.UsedFormattingFields, uffTextRotation);
|
||||||
|
lCell^.TextRotation := XFData.TextRotation;
|
||||||
|
|
||||||
// Borders
|
// Borders
|
||||||
if XFData.Borders <> [] then begin
|
if XFData.Borders <> [] then begin
|
||||||
Include(lCell^.UsedFormattingFields, uffBorder);
|
Include(lCell^.UsedFormattingFields, uffBorder);
|
||||||
|
Reference in New Issue
Block a user