fpspreadsheet: Add unit tests for writing/reading of borders, borderstyle and wordwrap for ods files. Passed.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3109 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-05-27 22:12:48 +00:00
parent 4aa640489f
commit 99f6a6f1d1
4 changed files with 262 additions and 94 deletions

View File

@ -181,6 +181,13 @@ const
DATEMODE_1900_BASE=2; //StarCalc compatibility, 1900-01-01 in FPC DateTime
DATEMODE_1904_BASE=1462; //1/1/1904 in FPC TDateTime
const
// lsThin, lsMedium, lsDashed, lsDotted, lsThick, lsDouble, lsHair)
BORDER_LINESTYLES: array[TsLineStyle] of string =
('solid', 'solid', 'dashed', 'fine-dashed', 'solid', 'double', 'dotted');
BORDER_LINEWIDTHS: array[TsLinestyle] of string =
('0.002cm', '2pt', '0.002cm', '0.002cm', '3pt', '0.039cm', '0.002cm');
type
{ Style items relevant to FPSpreadsheet. Stored in the StylesList of the reader. }
TStyleData = class
@ -765,10 +772,12 @@ var
wrap: Boolean;
borders: TsCellBorders;
borderStyles: TsCellBorderStyles;
bkClr: DWord;
bkClr: TsColorValue;
s: String;
procedure SetBorderStyle(ABorder: TsCellBorder; AStyleValue: String);
const
EPS = 0.1; // takes care of rounding errors for line widths
var
L: TStringList;
i: Integer;
@ -776,7 +785,7 @@ var
s: String;
wid: Double;
linestyle: String;
rgb: DWord;
rgb: TsColorValue;
p: Integer;
begin
L := TStringList.Create;
@ -785,15 +794,14 @@ var
L.StrictDelimiter := true;
L.DelimitedText := AStyleValue;
wid := 0;
rgb := DWord(-1);
rgb := TsColorValue(-1);
linestyle := '';
for i:=0 to L.Count-1 do begin
s := L[i];
if (s = 'solid') or (s = 'dashed') or (s = 'fine-dashed') or (s = 'dotted')
then linestyle := s;
if s[1] = '#' then begin
s[1] := '$';
rgb := StrToInt(s);
if (s = 'solid') or (s = 'dashed') or (s = 'fine-dashed') or (s = 'dotted') or (s = 'double')
then begin
linestyle := s;
continue;
end;
p := pos('pt', s);
if p = Length(s)-1 then begin
@ -810,11 +818,12 @@ var
wid := cmToPts(StrToFloat(copy(s, 1, p-1), fs));
Continue;
end;
rgb := HTMLColorStrToColor(s);
end;
borderStyles[ABorder].LineStyle := lsThin;
if (linestyle = 'solid') then begin
if (wid >= 2) then borderStyles[ABorder].LineStyle := lsThick
else if (wid >= 1) then borderStyles[ABorder].LineStyle := lsMedium
if (wid >= 3 - EPS) then borderStyles[ABorder].LineStyle := lsThick
else if (wid >= 2 - EPS) then borderStyles[ABorder].LineStyle := lsMedium
end else
if (linestyle = 'dotted') then
borderStyles[ABorder].LineStyle := lsHair
@ -823,9 +832,12 @@ var
borderStyles[ABorder].LineStyle := lsDashed
else
if (linestyle = 'fine-dashed') then
borderStyles[ABorder].LineStyle := lsDotted;
borderStyles[ABorder].Color := IfThen(rgb = DWord(-1), scBlack,
Workbook.AddColorToPalette(LongRGBToExcelPhysical(rgb)));
borderStyles[ABorder].LineStyle := lsDotted
else
if (linestyle = 'double') then
borderStyles[ABorder].LineStyle := lsDouble;
borderStyles[ABorder].Color := IfThen(rgb = TsColorValue(-1),
scBlack, Workbook.AddColorToPalette(rgb));
finally
L.Free;
end;
@ -853,17 +865,15 @@ begin
borders := [];
wrap := false;
bkClr := DWord(-1);
bkClr := TsColorValue(-1);
styleChildNode := styleNode.FirstChild;
while Assigned(styleChildNode) do begin
if styleChildNode.NodeName = 'style:table-cell-properties' then begin
// Background color
s := GetAttrValue(styleChildNode, 'fo:background-color');
if (s <> '') and (s <> 'transparent') then begin
if s[1] = '#' then s[1] := '$';
bkClr := StrToInt(s);
end;
if (s <> '') and (s <> 'transparent') then
bkClr := HTMLColorStrToColor(s);
// Borders
s := GetAttrValue(styleChildNode, 'fo:border');
if (s <>'') then begin
@ -914,8 +924,8 @@ begin
style.TextRotation := trHorizontal;
style.Borders := borders;
style.BorderStyles := borderStyles;
style.BackgroundColor := IfThen(bkClr = DWord(-1), scNotDefined,
Workbook.AddColorToPalette(LongRGBToExcelPhysical(bkClr)));
style.BackgroundColor := IfThen(bkClr = TsColorValue(-1), scNotDefined,
Workbook.AddColorToPalette(bkClr));
styleIndex := FStyleList.Add(style);
end;
@ -1151,6 +1161,7 @@ end;
function TsSpreadOpenDocWriter.WriteStylesXMLAsString: string;
var
i: Integer;
clr: string;
begin
Result := '';
@ -1176,24 +1187,59 @@ begin
if (uffBorder in FFormattingStyles[i].UsedFormattingFields) then
begin
if cbSouth in FFormattingStyles[i].Border then Result := Result + 'fo:border-bottom="0.002cm solid #000000" '
else Result := Result + 'fo:border-bottom="none" ';
if cbSouth in FFormattingStyles[i].Border then begin
Result := Result + Format('fo:border-bottom="%s %s %s" ', [
BORDER_LINEWIDTHS[FFormattingStyles[i].BorderStyles[cbSouth].LineStyle],
BORDER_LINESTYLES[FFormattingStyles[i].BorderStyles[cbSouth].LineStyle],
Workbook.GetPaletteColorAsHTMLStr(FFormattingStyles[i].BorderStyles[cbSouth].Color)
]);
if FFormattingStyles[i].BorderStyles[cbSouth].LineStyle = lsDouble then
Result := Result + 'style:border-linewidth-bottom="0.002cm 0.035cm 0.002cm" ';
end
else
Result := Result + 'fo:border-bottom="none" ';
if cbWest in FFormattingStyles[i].Border then Result := Result + 'fo:border-left="0.002cm solid #000000" '
else Result := Result + 'fo:border-left="none" ';
if cbWest in FFormattingStyles[i].Border then begin
Result := Result + Format('fo:border-left="%s %s %s" ', [
BORDER_LINEWIDTHS[FFormattingStyles[i].BorderStyles[cbWest].LineStyle],
BORDER_LINESTYLES[FFormattingStyles[i].BorderStyles[cbWest].LineStyle],
Workbook.GetPaletteColorAsHTMLStr(FFormattingStyles[i].BorderStyles[cbWest].Color)
]);
if FFormattingStyles[i].BorderStyles[cbWest].LineStyle = lsDouble then
Result := Result + 'style:border-linewidth-left="0.002cm 0.035cm 0.002cm" ';
end
else
Result := Result + 'fo:border-left="none" ';
if cbEast in FFormattingStyles[i].Border then Result := Result + 'fo:border-right="0.002cm solid #000000" '
else Result := Result + 'fo:border-right="none" ';
if cbEast in FFormattingStyles[i].Border then begin
Result := Result + Format('fo:border-right="%s %s %s" ', [
BORDER_LINEWIDTHS[FFormattingStyles[i].BorderStyles[cbEast].LineStyle],
BORDER_LINESTYLES[FFormattingStyles[i].BorderStyles[cbEast].LineStyle],
Workbook.GetPaletteColorAsHTMLStr(FFormattingStyles[i].BorderStyles[cbEast].Color)
]);
if FFormattingStyles[i].BorderStyles[cbSouth].LineStyle = lsDouble then
Result := Result + 'style:border-linewidth-right="0.002cm 0.035cm 0.002cm" ';
end
else
Result := Result + 'fo:border-right="none" ';
if cbNorth in FFormattingStyles[i].Border then Result := Result + 'fo:border-top="0.002cm solid #000000" '
else Result := Result + 'fo:border-top="none" ';
if cbNorth in FFormattingStyles[i].Border then begin
Result := Result + Format('fo:border-top="%s %s %s" ', [
BORDER_LINEWIDTHS[FFormattingStyles[i].BorderStyles[cbNorth].LineStyle],
BORDER_LINESTYLES[FFormattingStyles[i].BorderStyles[cbNorth].LineStyle],
Workbook.GetPaletteColorAsHTMLStr(FFormattingStyles[i].BorderStyles[cbNorth].Color)
]);
if FFormattingStyles[i].BorderStyles[cbSouth].LineStyle = lsDouble then
Result := Result + 'style:border-linewidth-top="0.002cm 0.035cm 0.002cm" ';
end else
Result := Result + 'fo:border-top="none" ';
end;
if (uffBackgroundColor in FFormattingStyles[i].UsedFormattingFields) then
begin
Result := Result + 'fo:background-color="#'
+ Workbook.FPSColorToHexString(FFormattingStyles[i].BackgroundColor, FFormattingStyles[i].RGBBackgroundColor) +'" ';
end;
Result := Result + Format('fo:background-color="%s" ', [
Workbook.GetPaletteColorAsHTMLStr(FFormattingStyles[i].BackgroundColor)
]);
// + Workbook.FPSColorToHexString(FFormattingStyles[i].BackgroundColor, FFormattingStyles[i].RGBBackgroundColor) +'" ';
if (uffWordWrap in FFormattingStyles[i].UsedFormattingFields) then
begin
@ -1309,8 +1355,18 @@ end;
}
procedure TsSpreadOpenDocWriter.WriteBlank(AStream: TStream;
const ARow, ACol: Cardinal; ACell: PCell);
var
lStyle: String = '';
lIndex: Integer;
begin
// no action at the moment...
// Write empty cell only if it has formatting
if ACell^.UsedFormattingFields <> [] then begin
lIndex := FindFormattingInList(ACell);
lStyle := ' table:style-name="ce' + IntToStr(lIndex) + '" ';
FContent := FContent +
' <table:table-cell ' + lStyle + '>' + LineEnding +
' </table:table-cell>' + LineEnding;
end;
end;
{

View File

@ -554,6 +554,7 @@ type
function FPSColorToHexString(AColor: TsColor; ARGBColor: TFPColor): String;
function GetColorName(AColorIndex: TsColor): string;
function GetPaletteColor(AColorIndex: TsColor): TsColorValue;
function GetPaletteColorAsHTMLStr(AColorIndex: TsColor): String;
procedure SetPaletteColor(AColorIndex: TsColor; AColorValue: TsColorValue);
function GetPaletteSize: Integer;
procedure UseDefaultPalette;
@ -2921,6 +2922,15 @@ begin
Result := $000000; // "black" as default
end;
{@@
Converts the palette color of the given index to a string that can be used
in HTML code. For ods.
}
function TsWorkbook.GetPaletteColorAsHTMLStr(AColorIndex: TsColor): String;
begin
Result := ColorToHTMLColorStr(GetPaletteColor(AColorIndex));
end;
{@@
Replaces a color value of the current palette by a new value. The color must
be given as ABGR (little-endian), with A=0}

View File

@ -105,6 +105,9 @@ function FormatDateTime(const FormatStr: string; DateTime: TDateTime;
function cmToPts(AValue: Double): Double;
function mmToPts(AValue: Double): Double;
function HTMLColorStrToColor(AValue: String): TsColorValue;
function ColorToHTMLColorStr(AValue: TsColorValue): String;
implementation
uses
@ -1296,13 +1299,64 @@ end;
{ Converts centimeters to points (72 pts = 1 inch) }
function cmToPts(AValue: Double): Double;
begin
Result := AValue/(2.54*72);
Result := AValue/2.54*72;
end;
{ Converts millimeters to points (72 pts = 1 inch) }
function mmToPts(AValue: Double): Double;
begin
Result := AValue/(25.4*72);
Result := AValue/25.4*72;
end;
{ converts a HTML color string to a TsColorValue. For ods }
function HTMLColorStrToColor(AValue: String): TsColorValue;
begin
if AValue = '' then
Result := scNotDefined
else
if AValue[1] = '#' then begin
AValue[1] := '$';
Result := LongRGBToExcelPhysical(StrToInt(AValue));
end else begin
AValue := lowercase(AValue);
if AValue = 'red' then
Result := $0000FF
else if AValue = 'cyan' then
Result := $FFFF00
else if AValue = 'blue' then
Result := $FF0000
else if AValue = 'purple' then
Result := $800080
else if AValue = 'yellow' then
Result := $00FFFF
else if AValue = 'lime' then
Result := $00FF00
else if AValue = 'white' then
Result := $FFFFFF
else if AValue = 'black' then
Result := $000000
else if (AValue = 'gray') or (AValue = 'grey') then
Result := $808080
else if AValue = 'silver' then
Result := $C0C0C0
else if AValue = 'maroon' then
Result := $000080
else if AValue = 'green' then
Result := $008000
else if AValue = 'olive' then
Result := $008080;
end;
end;
{ converts an rgb color value to a string as used in HTML code (for ods) }
function ColorToHTMLColorStr(AValue: TsColorValue): String;
type
TRGB = record r,g,b,a: Byte end;
var
rgb: TRGB;
begin
rgb := TRGB(AValue);
Result := Format('#%.2x%.2x%.2x', [rgb.r, rgb.g, rgb.b]);
end;
end.

View File

@ -70,38 +70,43 @@ type
// If previous read tests are ok, this effectively tests writing.
{ BIFF2 Tests }
procedure TestWriteReadBIFF2_Alignment;
procedure TestWriteReadBIFF2_Border;
procedure TestWriteReadBIFF2_ColWidths;
procedure TestWriteReadBIFF2_RowHeights;
procedure TestWriteReadBIFF2_DateTimeFormats;
procedure TestWriteReadBIFF2_NumberFormats;
procedure TestWriteRead_BIFF2_Alignment;
procedure TestWriteRead_BIFF2_Border;
procedure TestWriteRead_BIFF2_ColWidths;
procedure TestWriteRead_BIFF2_RowHeights;
procedure TestWriteRead_BIFF2_DateTimeFormats;
procedure TestWriteRead_BIFF2_NumberFormats;
// These features are not supported by Excel2 --> no test cases required!
// - BorderStyle
// - TextRotation
// - Wordwrap
{ BIFF5 Tests }
procedure TestWriteReadBIFF5_Alignment;
procedure TestWriteReadBIFF5_Border;
procedure TestWriteReadBIFF5_BorderStyles;
procedure TestWriteReadBIFF5_ColWidths;
procedure TestWriteReadBIFF5_RowHeights;
procedure TestWriteReadBIFF5_DateTimeFormats;
procedure TestWriteReadBIFF5_NumberFormats;
procedure TestWriteReadBIFF5_TextRotation;
procedure TestWriteReadBIFF5_WordWrap;
procedure TestWriteRead_BIFF5_Alignment;
procedure TestWriteRead_BIFF5_Border;
procedure TestWriteRead_BIFF5_BorderStyles;
procedure TestWriteRead_BIFF5_ColWidths;
procedure TestWriteRead_BIFF5_RowHeights;
procedure TestWriteRead_BIFF5_DateTimeFormats;
procedure TestWriteRead_BIFF5_NumberFormats;
procedure TestWriteRead_BIFF5_TextRotation;
procedure TestWriteRead_BIFF5_WordWrap;
{ BIFF8 Tests }
procedure TestWriteReadBIFF8_Alignment;
procedure TestWriteReadBIFF8_Border;
procedure TestWriteReadBIFF8_BorderStyles;
procedure TestWriteReadBIFF8_ColWidths;
procedure TestWriteReadBIFF8_RowHeights;
procedure TestWriteReadBIFF8_DateTimeFormats;
procedure TestWriteReadBIFF8_NumberFormats;
procedure TestWriteReadBIFF8_TextRotation;
procedure TestWriteReadBIFF8_WordWrap;
procedure TestWriteRead_BIFF8_Alignment;
procedure TestWriteRead_BIFF8_Border;
procedure TestWriteRead_BIFF8_BorderStyles;
procedure TestWriteRead_BIFF8_ColWidths;
procedure TestWriteRead_BIFF8_RowHeights;
procedure TestWriteRead_BIFF8_DateTimeFormats;
procedure TestWriteRead_BIFF8_NumberFormats;
procedure TestWriteRead_BIFF8_TextRotation;
procedure TestWriteRead_BIFF8_WordWrap;
{ ODS Tests }
procedure TestWriteRead_ODS_Border;
procedure TestWriteRead_ODS_BorderStyles;
procedure TestWriteRead_ODS_WordWrap;
end;
implementation
@ -251,6 +256,9 @@ begin
inherited TearDown;
end;
{ --- Number format tests --- }
procedure TSpreadWriteReadFormatTests.TestWriteReadNumberFormats(AFormat: TsSpreadsheetFormat);
var
MyWorksheet: TsWorksheet;
@ -301,21 +309,24 @@ begin
DeleteFile(TempFile);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF2_NumberFormats;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF2_NumberFormats;
begin
TestWriteReadNumberFormats(sfExcel2);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_NumberFormats;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF5_NumberFormats;
begin
TestWriteReadNumberFormats(sfExcel5);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_NumberFormats;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF8_NumberFormats;
begin
TestWriteReadNumberFormats(sfExcel8);
end;
{ --- Date/time formats --- }
procedure TSpreadWriteReadFormatTests.TestWriteReadDateTimeFormats(AFormat: TsSpreadsheetFormat);
var
MyWorksheet: TsWorksheet;
@ -370,21 +381,24 @@ begin
DeleteFile(TempFile);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF2_DateTimeFormats;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF2_DateTimeFormats;
begin
TestWriteReadDateTimeFormats(sfExcel2);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_DateTimeFormats;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF5_DateTimeFormats;
begin
TestWriteReadDateTimeFormats(sfExcel5);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_DateTimeFormats;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF8_DateTimeFormats;
begin
TestWriteReadDateTimeFormats(sfExcel8);
end;
{ --- Alignment tests --- }
procedure TSpreadWriteReadFormatTests.TestWriteReadAlignment(AFormat: TsSpreadsheetFormat);
const
CELLTEXT = 'This is a text.';
@ -425,9 +439,9 @@ begin
MyCell := MyWorksheet.FindCell(row, col);
if MyCell = nil then
fail('Error in test code. Failed to get cell.');
CheckEquals(vertAlign = MyCell^.VertAlignment, true,
CheckEquals(true, vertAlign = MyCell^.VertAlignment,
'Test unsaved vertical alignment, cell ' + CellNotation(MyWorksheet,0,0));
CheckEquals(horAlign = MyCell^.HorAlignment, true,
CheckEquals(true, horAlign = MyCell^.HorAlignment,
'Test unsaved horizontal alignment, cell ' + CellNotation(MyWorksheet,0,0));
inc(col);
end;
@ -460,10 +474,10 @@ begin
fail('Error in test code. Failed to get cell.');
vertAlign := TsVertAlignment(col);
if vertAlign = vaDefault then vertAlign := vaBottom;
CheckEquals(vertAlign = MyCell^.VertAlignment, true,
CheckEquals(true, vertAlign = MyCell^.VertAlignment,
'Test saved vertical alignment mismatch, cell '+CellNotation(MyWorksheet,Row,Col));
horAlign := TsHorAlignment(row);
CheckEquals(horAlign = MyCell^.HorAlignment, true,
CheckEquals(true, horAlign = MyCell^.HorAlignment,
'Test saved horizontal alignment mismatch, cell '+CellNotation(MyWorksheet,Row,Col));
end;
MyWorkbook.Free;
@ -471,21 +485,24 @@ begin
DeleteFile(TempFile);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF2_Alignment;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF2_Alignment;
begin
TestWriteReadAlignment(sfExcel2);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_Alignment;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF5_Alignment;
begin
TestWriteReadAlignment(sfExcel5);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_Alignment;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF8_Alignment;
begin
TestWriteReadAlignment(sfExcel8);
end;
{ --- Border on/off tests --- }
procedure TSpreadWriteReadFormatTests.TestWriteReadBorder(AFormat: TsSpreadsheetFormat);
const
row = 0;
@ -531,7 +548,7 @@ begin
fail('Error in test code. Failed to get cell');
current := GetEnumName(TypeInfo(TsCellBorders), byte(MyCell^.Border));
expected := GetEnumName(TypeInfo(TsCellBorders), byte(SollBorders[col]));
CheckEquals(current, expected,
CheckEquals(expected, current,
'Test saved border mismatch, cell ' + CellNotation(MyWorksheet, row, col));
end;
// Finalization
@ -540,21 +557,29 @@ begin
DeleteFile(TempFile);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF2_Border;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF2_Border;
begin
TestWriteReadBorder(sfExcel2);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_Border;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF5_Border;
begin
TestWriteReadBorder(sfExcel5);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_Border;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF8_Border;
begin
TestWriteReadBorder(sfExcel8);
end;
procedure TSpreadWriteReadFormatTests.TestWriteRead_ODS_Border;
begin
TestWriteReadBorder(sfOpenDocument);
end;
{ --- BorderStyle tests --- }
procedure TSpreadWriteReadFormatTests.TestWriteReadBorderStyles(AFormat: TsSpreadsheetFormat);
{ This test paints 10x10 cells with all borders, each separated by an empty
column and an empty row. The border style varies from border to border
@ -623,11 +648,11 @@ begin
for b in TsCellBorder do begin
current := ord(MyCell^.BorderStyles[b].LineStyle);
expected := ord(SollBorderLineStyles[ls]);
CheckEquals(current, expected,
CheckEquals(expected, current,
'Test saved border line style mismatch, cell ' + CellNotation(MyWorksheet, row*2, col*2));
current := MyCell^.BorderStyles[b].Color;
expected := SollBorderColors[c];
CheckEquals(current, expected,
CheckEquals(expected, current,
'Test saved border color mismatch, cell ' + CellNotation(MyWorksheet, row*2, col*2));
inc(ls);
if ls > High(SollBorderLineStyles) then begin
@ -646,16 +671,24 @@ begin
DeleteFile(TempFile);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_BorderStyles;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF5_BorderStyles;
begin
TestWriteReadBorderStyles(sfExcel5);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_BorderStyles;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF8_BorderStyles;
begin
TestWriteReadBorderStyles(sfExcel8);
end;
procedure TSpreadWriteReadFormatTests.TestWriteRead_ODS_BorderStyles;
begin
TestWriteReadBorderStyles(sfOpenDocument);
end;
{ --- Column widths tests --- }
procedure TSpreadWriteReadFormatTests.TestWriteReadColWidths(AFormat: TsSpreadsheetFormat);
var
MyWorksheet: TsWorksheet;
@ -704,21 +737,24 @@ begin
DeleteFile(TempFile);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF2_ColWidths;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF2_ColWidths;
begin
TestWriteReadColWidths(sfExcel2);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_ColWidths;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF5_ColWidths;
begin
TestWriteReadColWidths(sfExcel5);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_ColWidths;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF8_ColWidths;
begin
TestWriteReadColWidths(sfExcel8);
end;
{ --- Row height tests --- }
procedure TSpreadWriteReadFormatTests.TestWriteReadRowHeights(AFormat: TsSpreadsheetFormat);
var
MyWorksheet: TsWorksheet;
@ -766,21 +802,24 @@ begin
DeleteFile(TempFile);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF2_RowHeights;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF2_RowHeights;
begin
TestWriteReadRowHeights(sfExcel2);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_RowHeights;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF5_RowHeights;
begin
TestWriteReadRowHeights(sfExcel5);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_RowHeights;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF8_RowHeights;
begin
TestWriteReadRowHeights(sfExcel8);
end;
{ --- Text rotation tests --- }
procedure TSpreadWriteReadFormatTests.TestWriteReadTextRotation(AFormat: TsSpreadsheetFormat);
const
col = 0;
@ -834,16 +873,19 @@ begin
DeleteFile(TempFile);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_TextRotation;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF5_TextRotation;
begin
TestWriteReadTextRotation(sfExcel5);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_TextRotation;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF8_TextRotation;
begin
TestWriteReadTextRotation(sfExcel8);
end;
{ --- Wordwrap tests --- }
procedure TSpreadWriteReadFormatTests.TestWriteReadWordWrap(AFormat: TsSpreadsheetFormat);
const
LONGTEXT = 'This is a very, very, very, very long text.';
@ -867,13 +909,13 @@ begin
MyCell := MyWorksheet.FindCell(0, 0);
if MyCell = nil then
fail('Error in test code. Failed to get word-wrapped cell.');
CheckEquals((uffWordWrap in MyCell^.UsedFormattingFields), true, 'Test unsaved word wrap mismatch cell ' + CellNotation(MyWorksheet,0,0));
CheckEquals(true, (uffWordWrap in MyCell^.UsedFormattingFields), 'Test unsaved word wrap mismatch cell ' + CellNotation(MyWorksheet,0,0));
MyWorksheet.WriteUTF8Text(1, 0, LONGTEXT);
MyWorksheet.WriteUsedFormatting(1, 0, []);
MyCell := MyWorksheet.FindCell(1, 0);
if MyCell = nil then
fail('Error in test code. Failed to get word-wrapped cell.');
CheckEquals((uffWordWrap in MyCell^.UsedFormattingFields), false, 'Test unsaved non-wrapped cell mismatch, cell ' + CellNotation(MyWorksheet,0,0));
CheckEquals(false, (uffWordWrap in MyCell^.UsedFormattingFields), 'Test unsaved non-wrapped cell mismatch, cell ' + CellNotation(MyWorksheet,0,0));
MyWorkBook.WriteToFile(TempFile, AFormat, true);
MyWorkbook.Free;
@ -889,26 +931,32 @@ begin
MyCell := MyWorksheet.FindCell(0, 0);
if MyCell = nil then
fail('Error in test code. Failed to get word-wrapped cell.');
CheckEquals((uffWordWrap in MyCell^.UsedFormattingFields), true, 'failed to return correct word-wrap flag, cell ' + CellNotation(MyWorksheet,0,0));
CheckEquals(true, (uffWordWrap in MyCell^.UsedFormattingFields), 'failed to return correct word-wrap flag, cell ' + CellNotation(MyWorksheet,0,0));
MyCell := MyWorksheet.FindCell(1, 0);
if MyCell = nil then
fail('Error in test code. Failed to get non-wrapped cell.');
CheckEquals((uffWordWrap in MyCell^.UsedFormattingFields), false, 'failed to return correct word-wrap flag, cell ' + CellNotation(MyWorksheet,0,0));
CheckEquals(false, (uffWordWrap in MyCell^.UsedFormattingFields), 'failed to return correct word-wrap flag, cell ' + CellNotation(MyWorksheet,0,0));
MyWorkbook.Free;
DeleteFile(TempFile);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF5_Wordwrap;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF5_Wordwrap;
begin
TestWriteReadWordwrap(sfExcel5);
end;
procedure TSpreadWriteReadFormatTests.TestWriteReadBIFF8_Wordwrap;
procedure TSpreadWriteReadFormatTests.TestWriteRead_BIFF8_Wordwrap;
begin
TestWriteReadWordwrap(sfExcel8);
end;
procedure TSpreadWriteReadFormatTests.TestWriteRead_ODS_Wordwrap;
begin
TestWriteReadWordwrap(sfOpenDocument);
end;
initialization
RegisterTest(TSpreadWriteReadFormatTests);
InitSollFmtData;