fpspreadsheet: Fix incorrect characters in label cells read from of ods files. Partial fix of negative values forgetting the red color in case of built-in format nfCurrencyRed.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3188 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-06-17 11:57:03 +00:00
parent 5a04bbbdda
commit 631881ca39
3 changed files with 40 additions and 8 deletions

View File

@ -19,7 +19,7 @@ var
MyDir: string;
number1, number2, number3, number4,
number5, number6, number7, number8: Double;
row: Integer;
row: Integer = 7;
begin
MyDir := ExtractFilePath(ParamStr(0));
number1 := 1.23456789;
@ -36,7 +36,7 @@ begin
MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet');
// Write some cells
//MyWorksheet.WriteNumber(0, 0, 1.0);// A1
MyWorksheet.WriteNumber(0, 0, 1.0);// A1
MyWorksheet.WriteNumber(0, 1, 2.0);// B1
MyWorksheet.WriteNumber(0, 2, 3.0);// C1
MyWorksheet.WriteNumber(0, 3, 4.0);// D1
@ -49,7 +49,6 @@ begin
MyWorksheet.WriteFont(0, 1, 'Times New Roman', 16, [], scRed);
// Show number formats
row := 7;
MyWorksheet.WriteUTF8Text(row, 0, 'Number formats:');
inc(row);
MyWorksheet.WriteUTF8Text(row, 0, 'nfGeneral');

View File

@ -1186,8 +1186,24 @@ procedure TsSpreadOpenDocReader.ReadLabel(ARow: Word; ACol: Word; ACellNode: TDO
var
cellText: String;
styleName: String;
childnode: TDOMNode;
begin
cellText := ACellNode.TextContent;
// cellText := ACellNode.TextContent;
{ We were forced to activate PreserveWhiteSpace in the DOMParser in order to
catch the spaces inserted in formatting texts. However, this adds lots of
garbage into the cellText if is is read by means of above statement. Done
like below is much better: }
cellText := '';
childnode := ACellNode.FirstChild;
while Assigned(childnode) do begin
case childnode.NodeType of
TEXT_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE: ; // ignored
else
cellText := cellText + childnode.TextContent;
end;
childnode := childnode.NextSibling;
end;
FWorkSheet.WriteUTF8Text(ARow, ACol, cellText);
styleName := GetAttrValue(ACellNode, 'table:style-name');
@ -1331,8 +1347,12 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
grouping: Boolean;
nex: Integer;
cs: String;
color: TsColorValue;
idx: Integer;
hasColor: Boolean;
begin
fmt := '';
hasColor := false;
node := ANumFormatNode.FirstChild;
while Assigned(node) do begin
nodeName := node.NodeName;
@ -1370,6 +1390,18 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
fmt := fmt + childNode.NodeValue;
childNode := childNode.NextSibling;
end;
end else
if nodeName = 'style:text-properties' then begin
s := GetAttrValue(node, 'fo:color');
color := HTMLColorStrToColor(s);
idx := FWorkbook.AddColorToPalette(color);
{
if idx < 8 then
fmt := Format('[%s]%s', [FWorkbook.GetColorName(idx), fmt])
else
fmt := Format('[Color%d]%s', [idx, fmt]);
}
hasColor := true;
end;
node := node.NextSibling;
end;
@ -1380,8 +1412,9 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
if ANumFormatNode.NodeName = 'number:percentage-style' then
nf := nfPercentage
else if ANumFormatNode.NodeName = 'number:currency-style' then
nf := nfCurrency;
else if ANumFormatNode.NodeName = 'number:currency-style' then begin
if hasColor then nf := nfCurrencyRed else nf := nfCurrency;
end;
NumFormatList.AddFormat(ANumFormatName, fmt, nf);
end;
@ -1602,7 +1635,6 @@ begin
//process each cell of the row
cellNode := rowNode.FindNode('table:table-cell');
while Assigned(cellNode) do begin
// These nodes occur due to indentation spaces which are not skipped
// automatically any more due to PreserveWhiteSpace option applied
// to ReadXMLFile

View File

@ -2631,7 +2631,8 @@ begin
if row <> nil then
Result := row^.Height
else
Result := CalcAutoRowHeight(ARow); //FWorkbook.DefaultRowHeight;
//Result := CalcAutoRowHeight(ARow);
Result := FWorkbook.DefaultRowHeight;
end;
procedure TsWorksheet.RemoveAllRows;