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:
wp_xxyyzz
2014-04-27 15:59:16 +00:00
parent 712e5fb61b
commit 34db575967
6 changed files with 117 additions and 18 deletions

View File

@ -1,21 +1,23 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<PathDelim Value="\"/>
<Version Value="7"/>
<General>
<Flags>
<LRSInOutputDirectory Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<TargetFileExt Value=".exe"/>
<Title Value="excel5read"/>
<UseAppBundle Value="False"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
@ -42,12 +44,17 @@
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="8"/>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<OtherUnitFiles Value="..\"/>
<SrcPath Value="..\"/>
<OtherUnitFiles Value=".."/>
<SrcPath Value=".."/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>

View File

@ -37,9 +37,6 @@ begin
// Write some cells
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, 2, 3.0);// C1
MyWorksheet.WriteNumber(0, 3, 4.0);// D1
@ -59,11 +56,11 @@ begin
MyWorksheet.WriteUTF8Text(4, 5, 'Stacked text');
MyWorksheet.WriteTextRotation(4, 5, rtStacked);
MyWorksheet.WriteUTF8Text(4, 5, 'Rotated text');
MyWorksheet.WriteTextRotation(4, 5, rt90DegreeClockwiseRotation);
MyWorksheet.WriteUTF8Text(4, 6, 'CW-rotated text');
MyWorksheet.WriteTextRotation(4, 6, rt90DegreeClockwiseRotation);
MyWorksheet.WriteUTF8Text(4, 6, 'Rotated text');
MyWorksheet.WriteTextRotation(4, 5, rt90DegreeCounterClockwiseRotation);
MyWorksheet.WriteUTF8Text(4, 7, 'CCW-rotated text');
MyWorksheet.WriteTextRotation(4, 7, rt90DegreeCounterClockwiseRotation);
// Write current date/time
MyWorksheet.WriteDateTime(5, 0, now);

View File

@ -49,6 +49,8 @@ type
procedure TestWriteReadBorder(AFormat: TsSpreadsheetFormat);
// Test column widths
procedure TestWriteReadColWidths(AFormat: TsSpreadsheetFormat);
// Test text rotation
procedure TestWriteReadTextRotation(AFormat:TsSpreadsheetFormat);
// Test word wrapping
procedure TestWriteReadWordWrap(AFormat: TsSpreadsheetFormat);
@ -60,17 +62,22 @@ type
procedure TestWriteReadBIFF2_Alignment;
procedure TestWriteReadBIFF2_Border;
procedure TestWriteReadBIFF2_ColWidths;
// These features are not supported by Excel2 --> no test cases required!
// - TextRotation
// - Wordwrap
{ BIFF5 Tests }
procedure TestWriteReadBIFF5_Alignment;
procedure TestWriteReadBIFF5_Border;
procedure TestWriteReadBIFF5_ColWidths;
procedure TestWriteReadBIFF5_TextRotation;
procedure TestWriteReadBIFF5_WordWrap;
{ BIFF8 Tests }
procedure TestWriteReadBIFF8_Alignment;
procedure TestWriteReadBIFF8_Border;
procedure TestWriteReadBIFF8_ColWidths;
procedure TestWriteReadBIFF8_TextRotation;
procedure TestWriteReadBIFF8_WordWrap;
procedure TestWriteReadNumberFormats;
// Repeat with date/times
@ -88,6 +95,7 @@ const
ColWidthSheet = 'ColWidths';
BordersSheet = 'CellBorders';
AlignmentSheet = 'TextAlignments';
TextRotationSheet = 'TextRotation';
WordwrapSheet = 'Wordwrap';
// Initialize array with variables that represent the values
@ -513,6 +521,69 @@ begin
TestWriteReadColWidths(sfExcel8);
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);
const
LONGTEXT = 'This is a very, very, very, very long text.';

View File

@ -1279,10 +1279,10 @@ begin
if uffTextRotation in FFormattingStyles[i].UsedFormattingFields then
begin
case FFormattingStyles[i].TextRotation of
trHorizontal : lTextRotation := XF_ROTATION_HORIZONTAL;
rt90DegreeClockwiseRotation : lTextRotation := XF_ROTATION_90DEG_CW;
rt90DegreeCounterClockwiseRotation: lTextRotation := XF_ROTATION_90DEG_CCW;
rtStacked : lTextRotation := XF_ROTATION_STACKED;
trHorizontal : lTextRotation := XF_ROTATION_HORIZONTAL;
rt90DegreeClockwiseRotation : lTextRotation := XF_ROTATION_90DEG_CW;
rt90DegreeCounterClockwiseRotation : lTextRotation := XF_ROTATION_90DEG_CCW;
rtStacked : lTextRotation := XF_ROTATION_STACKED;
end;
end;
@ -1734,6 +1734,14 @@ begin
// Word wrap
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
xf.Border_Background_1 := DWordLEToN(xf.Border_Background_1);
xf.Border_Background_2 := DWordLEToN(xf.Border_Background_2);

View File

@ -2317,6 +2317,14 @@ begin
// Word wrap
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
xf.Border_Background_1 := DWordLEToN(xf.Border_Background_1);
lData.Borders := [];

View File

@ -305,6 +305,7 @@ type
HorAlignment: TsHorAlignment;
VertAlignment: TsVertAlignment;
WordWrap: Boolean;
TextRotation: TsTextRotation;
Borders: TsCellBorders;
BackgroundColor: TsColor;
end;
@ -470,6 +471,13 @@ begin
else
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
if XFData.Borders <> [] then begin
Include(lCell^.UsedFormattingFields, uffBorder);