You've already forked lazarus-ccr
fpspreadsheet: Fix crash when reading xlsx with unexpected formatting of column width node. Add "inlineStr" data type to xlsx reader.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4250 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -556,9 +556,10 @@ var
|
|||||||
addr, s: String;
|
addr, s: String;
|
||||||
rowIndex, colIndex: Cardinal;
|
rowIndex, colIndex: Cardinal;
|
||||||
cell, sharedformulabase: PCell;
|
cell, sharedformulabase: PCell;
|
||||||
datanode: TDOMNode;
|
datanode, tnode: TDOMNode;
|
||||||
dataStr: String;
|
dataStr: String;
|
||||||
formulaStr: String;
|
formulaStr: String;
|
||||||
|
nodeName: String;
|
||||||
sstIndex: Integer;
|
sstIndex: Integer;
|
||||||
number: Double;
|
number: Double;
|
||||||
fmt: TsCellFormat;
|
fmt: TsCellFormat;
|
||||||
@ -600,10 +601,21 @@ begin
|
|||||||
formulaStr := '';
|
formulaStr := '';
|
||||||
while Assigned(datanode) do
|
while Assigned(datanode) do
|
||||||
begin
|
begin
|
||||||
if datanode.NodeName = 'v' then
|
nodeName := datanode.NodeName;
|
||||||
|
if nodeName = 'v' then
|
||||||
dataStr := GetNodeValue(datanode)
|
dataStr := GetNodeValue(datanode)
|
||||||
else
|
else
|
||||||
if (boReadFormulas in FWorkbook.Options) and (datanode.NodeName = 'f') then
|
if nodeName = 'is' then
|
||||||
|
begin
|
||||||
|
tnode := datanode.FirstChild;
|
||||||
|
while Assigned(tnode) do begin
|
||||||
|
nodename := tnode.NodeName;
|
||||||
|
if nodename = 't' then
|
||||||
|
dataStr := dataStr + GetNodeValue(tnode);
|
||||||
|
tnode := tnode.NextSibling;
|
||||||
|
end;
|
||||||
|
end else
|
||||||
|
if (boReadFormulas in FWorkbook.Options) and (nodeName = 'f') then
|
||||||
begin
|
begin
|
||||||
// Formula to cell
|
// Formula to cell
|
||||||
formulaStr := GetNodeValue(datanode);
|
formulaStr := GetNodeValue(datanode);
|
||||||
@ -685,7 +697,7 @@ begin
|
|||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
end else
|
end else
|
||||||
if s = 'str' then
|
if (s = 'str') or (s = 'inlineStr') then
|
||||||
// literal string
|
// literal string
|
||||||
AWorksheet.WriteUTF8Text(cell, datastr)
|
AWorksheet.WriteUTF8Text(cell, datastr)
|
||||||
else
|
else
|
||||||
@ -960,23 +972,28 @@ var
|
|||||||
col, col1, col2: Cardinal;
|
col, col1, col2: Cardinal;
|
||||||
w: Double;
|
w: Double;
|
||||||
s: String;
|
s: String;
|
||||||
|
nodeName: String;
|
||||||
begin
|
begin
|
||||||
if ANode = nil then
|
if ANode = nil then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
colNode := ANode.FirstChild;
|
colNode := ANode.FirstChild;
|
||||||
while Assigned(colNode) do begin
|
while Assigned(colNode) do begin
|
||||||
s := GetAttrValue(colNode, 'customWidth');
|
nodeName := colNode.NodeName;
|
||||||
if s = '1' then begin
|
if nodename = 'col' then
|
||||||
s := GetAttrValue(colNode, 'min');
|
begin
|
||||||
if s <> '' then col1 := StrToInt(s)-1 else col1 := 0;
|
s := GetAttrValue(colNode, 'customWidth');
|
||||||
s := GetAttrValue(colNode, 'max');
|
if s = '1' then begin
|
||||||
if s <> '' then col2 := StrToInt(s)-1 else col2 := col1;
|
s := GetAttrValue(colNode, 'min');
|
||||||
s := GetAttrValue(colNode, 'width');
|
if s <> '' then col1 := StrToInt(s)-1 else col1 := 0;
|
||||||
if (s <> '') and TryStrToFloat(s, w, FPointSeparatorSettings) then
|
s := GetAttrValue(colNode, 'max');
|
||||||
if not SameValue(w, AWorksheet.DefaultColWidth, EPS) then
|
if s <> '' then col2 := StrToInt(s)-1 else col2 := col1;
|
||||||
for col := col1 to col2 do
|
s := GetAttrValue(colNode, 'width');
|
||||||
AWorksheet.WriteColWidth(col, w);
|
if (s <> '') and TryStrToFloat(s, w, FPointSeparatorSettings) then
|
||||||
|
if not SameValue(w, AWorksheet.DefaultColWidth, EPS) then
|
||||||
|
for col := col1 to col2 do
|
||||||
|
AWorksheet.WriteColWidth(col, w);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
colNode := colNode.NextSibling;
|
colNode := colNode.NextSibling;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user