You've already forked lazarus-ccr
fpspreadsheet: Writing and reading of horizontal and vertical text alignments in ods files. Add test cases. Pass.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3116 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
@ -44,7 +44,7 @@
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="9"/>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<SearchPaths>
|
||||
<OtherUnitFiles Value=".."/>
|
||||
|
@ -99,7 +99,9 @@ type
|
||||
private
|
||||
function WriteBackgroundColorStyleXMLAsString(const AFormat: TCell): String;
|
||||
function WriteBorderStyleXMLAsString(const AFormat: TCell): String;
|
||||
function WriteHorAlignmentStyleXMLAsString(const AFormat: TCell): String;
|
||||
function WriteTextRotationStyleXMLAsString(const AFormat: TCell): String;
|
||||
function WriteVertAlignmentStyleXMLAsString(const AFormat: TCell): String;
|
||||
function WriteWordwrapStyleXMLAsString(const AFormat: TCell): String;
|
||||
protected
|
||||
FPointSeparatorSettings: TFormatSettings;
|
||||
@ -1355,16 +1357,30 @@ begin
|
||||
' <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/>' + LineEnding;
|
||||
|
||||
// style:table-cell-properties
|
||||
if (FFormattingStyles[i].UsedFormattingFields <> []) then begin
|
||||
if (FFormattingStyles[i].UsedFormattingFields *
|
||||
[uffBorder, uffBackgroundColor, uffWordWrap, uffTextRotation, uffVertAlign] <> [])
|
||||
then begin
|
||||
Result := Result +
|
||||
' <style:table-cell-properties ' +
|
||||
WriteBorderStyleXMLAsString(FFormattingStyles[i]) +
|
||||
WriteBackgroundColorStyleXMLAsString(FFormattingStyles[i]) +
|
||||
WriteWordwrapStyleXMLAsString(FFormattingStyles[i]) +
|
||||
WriteTextRotationStyleXMLAsString(FFormattingStyles[i]) +
|
||||
WriteVertAlignmentStyleXMLAsString(FFormattingStyles[i]) +
|
||||
'/>' + LineEnding;
|
||||
end;
|
||||
|
||||
// style:paragraph-properties
|
||||
if (uffHorAlign in FFormattingStyles[i].UsedFormattingFields) and
|
||||
(FFormattingStyles[i].HorAlignment <> haDefault)
|
||||
then begin
|
||||
Result := Result +
|
||||
' <style:paragraph-properties ' +
|
||||
WriteHorAlignmentStyleXMLAsString(FFormattingStyles[i]) +
|
||||
'/>' + LineEnding;
|
||||
end;
|
||||
|
||||
|
||||
// End
|
||||
Result := Result +
|
||||
' </style:style>' + LineEnding;
|
||||
@ -1560,6 +1576,22 @@ begin
|
||||
Result := Result + 'fo:border-top="none" ';
|
||||
end;
|
||||
|
||||
{ Creates an XML string for inclusion of the horizontal alignment into the
|
||||
written file from the horizontal alignment setting in the format cell.
|
||||
Is called from WriteStyles (via WriteStylesXMLAsString). }
|
||||
function TsSpreadOpenDocWriter.WriteHorAlignmentStyleXMLAsString(
|
||||
const AFormat: TCell): String;
|
||||
begin
|
||||
Result := '';
|
||||
if not (uffHorAlign in AFormat.UsedFormattingFields) then
|
||||
exit;
|
||||
case AFormat.HorAlignment of
|
||||
haLeft : Result := 'fo:text-align="start" ';
|
||||
haCenter : Result := 'fo:text-align="center" ';
|
||||
haRight : Result := 'fo:text-align="end" ';
|
||||
end;
|
||||
end;
|
||||
|
||||
{ Creates an XML string for inclusion of the textrotation style option into the
|
||||
written file from the textrotation setting in the format cell.
|
||||
Is called from WriteStyles (via WriteStylesXMLAsString). }
|
||||
@ -1577,10 +1609,27 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ Creates an XML string for inclusion of the vertical alignment into the
|
||||
written file from the vertical alignment setting in the format cell.
|
||||
Is called from WriteStyles (via WriteStylesXMLAsString). }
|
||||
function TsSpreadOpenDocWriter.WriteVertAlignmentStyleXMLAsString(
|
||||
const AFormat: TCell): String;
|
||||
begin
|
||||
Result := '';
|
||||
if not (uffVertAlign in AFormat.UsedFormattingFields) then
|
||||
exit;
|
||||
case AFormat.VertAlignment of
|
||||
vaTop : Result := 'style:vertical-align="top" ';
|
||||
vaCenter : Result := 'style:vertical-align="middle" ';
|
||||
vaBottom : Result := 'style:vertical-align="bottom" ';
|
||||
end;
|
||||
end;
|
||||
|
||||
{ Creates an XML string for inclusion of the wordwrap option into the
|
||||
written file from the wordwrap setting in the format cell.
|
||||
Is called from WriteStyles (via WriteStylesXMLAsString). }
|
||||
function TsSpreadOpenDocWriter.WriteWordwrapStyleXMLAsString(const AFormat: TCell): String;
|
||||
function TsSpreadOpenDocWriter.WriteWordwrapStyleXMLAsString(
|
||||
const AFormat: TCell): String;
|
||||
begin
|
||||
if (uffWordWrap in AFormat.UsedFormattingFields) then
|
||||
Result := 'fo:wrap-option="wrap" '
|
||||
|
@ -104,6 +104,7 @@ type
|
||||
procedure TestWriteRead_BIFF8_WordWrap;
|
||||
|
||||
{ ODS Tests }
|
||||
procedure TestWriteRead_ODS_Alignment;
|
||||
procedure TestWriteRead_ODS_Border;
|
||||
procedure TestWriteRead_ODS_BorderStyles;
|
||||
procedure TestWriteRead_ODS_TextRotation;
|
||||
@ -425,12 +426,13 @@ begin
|
||||
for horAlign in TsHorAlignment do begin
|
||||
col := 0;
|
||||
if AFormat = sfExcel2 then begin
|
||||
// BIFF2 can only do horizontal alignment --> no need for vertical alignment.
|
||||
MyWorksheet.WriteUTF8Text(row, col, CELLTEXT);
|
||||
MyWorksheet.WriteHorAlignment(row, col, horAlign);
|
||||
MyCell := MyWorksheet.FindCell(row, col);
|
||||
if MyCell = nil then
|
||||
fail('Error in test code. Failed to get cell.');
|
||||
CheckEquals(horAlign = MyCell^.HorAlignment, true,
|
||||
CheckEquals(ord(horAlign), ord(MyCell^.HorAlignment),
|
||||
'Test unsaved horizontal alignment, cell ' + CellNotation(MyWorksheet,0,0));
|
||||
end else
|
||||
for vertAlign in TsVertAlignment do begin
|
||||
@ -440,9 +442,9 @@ begin
|
||||
MyCell := MyWorksheet.FindCell(row, col);
|
||||
if MyCell = nil then
|
||||
fail('Error in test code. Failed to get cell.');
|
||||
CheckEquals(true, vertAlign = MyCell^.VertAlignment,
|
||||
CheckEquals(ord(vertAlign),ord(MyCell^.VertAlignment),
|
||||
'Test unsaved vertical alignment, cell ' + CellNotation(MyWorksheet,0,0));
|
||||
CheckEquals(true, horAlign = MyCell^.HorAlignment,
|
||||
CheckEquals(ord(horAlign), ord(MyCell^.HorAlignment),
|
||||
'Test unsaved horizontal alignment, cell ' + CellNotation(MyWorksheet,0,0));
|
||||
inc(col);
|
||||
end;
|
||||
@ -454,33 +456,39 @@ begin
|
||||
// Open the spreadsheet
|
||||
MyWorkbook := TsWorkbook.Create;
|
||||
MyWorkbook.ReadFromFile(TempFile, AFormat);
|
||||
if AFormat = sfExcel2 then
|
||||
MyWorksheet := MyWorkbook.GetFirstWorksheet
|
||||
else
|
||||
if AFormat = sfExcel2 then begin
|
||||
MyWorksheet := MyWorkbook.GetFirstWorksheet;
|
||||
if MyWorksheet=nil then
|
||||
fail('Error in test code. Failed to get named worksheet');
|
||||
for row :=0 to MyWorksheet.GetLastRowIndex do begin
|
||||
MyCell := MyWorksheet.FindCell(row, col);
|
||||
if MyCell = nil then
|
||||
fail('Error in test code. Failed to get cell.');
|
||||
horAlign := TsHorAlignment(row);
|
||||
CheckEquals(ord(horAlign), ord(MyCell^.HorAlignment),
|
||||
'Test save horizontal alignment mismatch, cell '+CellNotation(MyWorksheet,row,col));
|
||||
end
|
||||
end
|
||||
else begin
|
||||
MyWorksheet := GetWorksheetByName(MyWorkBook, AlignmentSheet);
|
||||
if MyWorksheet=nil then
|
||||
fail('Error in test code. Failed to get named worksheet');
|
||||
for row := 0 to MyWorksheet.GetLastRowIndex do
|
||||
if AFormat = sfExcel2 then begin
|
||||
MyCell := MyWorksheet.FindCell(row, col);
|
||||
if MyCell = nil then
|
||||
fail('Error in test code. Failded to get cell.');
|
||||
horAlign := TsHorAlignment(row);
|
||||
CheckEquals(horAlign = MyCell^.HorAlignment, true,
|
||||
'Test saved horizontal alignment mismatch, cell '+CellNotation(MyWorksheet,row,col));
|
||||
end else
|
||||
for col := 0 to MyWorksheet.GetLastColIndex do begin
|
||||
for row :=0 to MyWorksheet.GetLastRowIndex do
|
||||
for col := 0 to MyWorksheet.GetlastColIndex do begin
|
||||
MyCell := MyWorksheet.FindCell(row, col);
|
||||
if MyCell = nil then
|
||||
fail('Error in test code. Failed to get cell.');
|
||||
vertAlign := TsVertAlignment(col);
|
||||
if vertAlign = vaDefault then vertAlign := vaBottom;
|
||||
CheckEquals(true, vertAlign = MyCell^.VertAlignment,
|
||||
'Test saved vertical alignment mismatch, cell '+CellNotation(MyWorksheet,Row,Col));
|
||||
if (vertAlign = vaDefault) and (AFormat <> sfOpenDocument) then
|
||||
vertAlign := vaBottom;
|
||||
CheckEquals(ord(vertAlign), ord(MyCell^.VertAlignment),
|
||||
'Test saved vertical alignment mismatch, cell '+CellNotation(MyWorksheet,row,col));
|
||||
horAlign := TsHorAlignment(row);
|
||||
CheckEquals(true, horAlign = MyCell^.HorAlignment,
|
||||
'Test saved horizontal alignment mismatch, cell '+CellNotation(MyWorksheet,Row,Col));
|
||||
CheckEquals(ord(horAlign), ord(MyCell^.HorAlignment),
|
||||
'Test saved horizontal alignment mismatch, cell '+CellNotation(MyWorksheet,row,col));
|
||||
end;
|
||||
end;
|
||||
|
||||
MyWorkbook.Free;
|
||||
|
||||
DeleteFile(TempFile);
|
||||
@ -501,6 +509,11 @@ begin
|
||||
TestWriteReadAlignment(sfExcel8);
|
||||
end;
|
||||
|
||||
procedure TSpreadWriteReadFormatTests.TestWriteRead_ODS_Alignment;
|
||||
begin
|
||||
TestWriteReadAlignment(sfOpenDocument);
|
||||
end;
|
||||
|
||||
|
||||
{ --- Border on/off tests --- }
|
||||
|
||||
|
Reference in New Issue
Block a user