fpspreadsheet: Fix OOXML writer using incorrect color if palette index is >63. Activate color count error test for ooxml and ods.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3472 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-08-12 09:05:19 +00:00
parent 495499a9e2
commit f35eae9379
3 changed files with 33 additions and 24 deletions

View File

@ -1178,8 +1178,8 @@ resourcestring
'file format does not support more than %d rows.'; 'file format does not support more than %d rows.';
lpMaxColsExceeded = 'This workbook contains %d columns, but the selected ' + lpMaxColsExceeded = 'This workbook contains %d columns, but the selected ' +
'file format does not support more than %d columns.'; 'file format does not support more than %d columns.';
lpTooManyPaletteColors = 'This workbook contains more colors (%d) than are ' + lpTooManyPaletteColors = 'This workbook contains more colors (%d) than ' +
'supported by the file format (%d). The redundant colors are replaced by '+ 'supported by the file format (%d). The additional colors are replaced by '+
'the best-matching palette colors.'; 'the best-matching palette colors.';
lpInvalidFontIndex = 'Invalid font index'; lpInvalidFontIndex = 'Invalid font index';
lpInvalidNumberFormat = 'Trying to use an incompatible number format.'; lpInvalidNumberFormat = 'Trying to use an incompatible number format.';

View File

@ -66,6 +66,7 @@ var
TempFile: String; TempFile: String;
ErrList: TStringList; ErrList: TStringList;
newColor: TsColor; newColor: TsColor;
expected: integer;
begin begin
formula.FormulaStr := '=A1'; formula.FormulaStr := '=A1';
formula.DoubleValue := 0.0; formula.DoubleValue := 0.0;
@ -119,7 +120,6 @@ begin
end; end;
// Test 3: Too many colors // Test 3: Too many colors
if (TTestFormat(AFormat) in [sfExcel2, sfExcel5, sfExcel8]) then begin
MyWorkbook := TsWorkbook.Create; MyWorkbook := TsWorkbook.Create;
try try
// Prepare a full palette // Prepare a full palette
@ -135,12 +135,17 @@ begin
TempFile:=NewTempFile; TempFile:=NewTempFile;
MyWorkBook.WriteToFile(TempFile, AFormat, true); MyWorkBook.WriteToFile(TempFile, AFormat, true);
ErrList.Text := MyWorkbook.ErrorMsg; ErrList.Text := MyWorkbook.ErrorMsg;
CheckEquals(1, ErrList.Count, 'Error count mismatch in test 3'); // Palette usage in biff --> expecting error due to too large palette
if (TTestFormat(AFormat) in [sfExcel2, sfExcel5, sfExcel8]) then
expected := 1
else
// no palette in xml --> no error expected
expected := 0;
CheckEquals(expected, ErrList.Count, 'Error count mismatch in test 3');
finally finally
MyWorkbook.Free; MyWorkbook.Free;
DeleteFile(TempFile); DeleteFile(TempFile);
end; end;
end;
// Test 4: Too long cell label // Test 4: Too long cell label
if MAX_CELL_LEN[TTestFormat(AFormat)] <> Cardinal(-1) then begin if MAX_CELL_LEN[TTestFormat(AFormat)] <> Cardinal(-1) then begin

View File

@ -1754,6 +1754,7 @@ var
i: Integer; i: Integer;
font: TsFont; font: TsFont;
s: String; s: String;
rgb: TsColorValue;
begin begin
AppendToStream(FSStyles, Format( AppendToStream(FSStyles, Format(
'<fonts count="%d">', [Workbook.GetFontCount])); '<fonts count="%d">', [Workbook.GetFontCount]));
@ -1774,9 +1775,12 @@ begin
if (fssStrikeout in font.Style) then if (fssStrikeout in font.Style) then
s := s + '<strike />'; s := s + '<strike />';
if font.Color <> scBlack then begin if font.Color <> scBlack then begin
s := s + Format('<color indexed="%d" />', [font.Color]); if font.Color < 64 then
// rgb := Workbook.GetPaletteColor(font.Color); s := s + Format('<color indexed="%d" />', [font.Color])
// s := s + Format('<color rgb="%s" />', [Copy(ColorToHTMLColorStr(rgb), 2, 255)]); else begin
rgb := Workbook.GetPaletteColor(font.Color);
s := s + Format('<color rgb="%s" />', [Copy(ColorToHTMLColorStr(rgb), 2, 255)]);
end;
end; end;
AppendToStream(AStream, AppendToStream(AStream,
'<font>', s, '</font>'); '<font>', s, '</font>');