fpspreadsheet: Fix reverse order of rpn tokens when reading an xls file. Fix string formula reconstruction routine. Unit test passed again.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3298 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
428bf6bd93
commit
3020ad9261
@ -2265,7 +2265,12 @@ begin
|
|||||||
fs := Workbook.FormatSettings;
|
fs := Workbook.FormatSettings;
|
||||||
L := TStringList.Create;
|
L := TStringList.Create;
|
||||||
try
|
try
|
||||||
for i:=0 to Length(ACell^.RPNFormulaValue)-1 do begin
|
// We store the cell values and operation codes in a stringlist which serves
|
||||||
|
// as kind of stack. Therefore, we do not destroy the original formula array.
|
||||||
|
// We reverse the order of the items because in the next step stringlist
|
||||||
|
// items will subsequently be deleted, and this is much easier when going
|
||||||
|
// in reverse direction.
|
||||||
|
for i := Length(ACell^.RPNFormulaValue)-1 downto 0 do begin
|
||||||
elem := ACell^.RPNFormulaValue[i];
|
elem := ACell^.RPNFormulaValue[i];
|
||||||
ptr := Pointer(elem.ElementKind);
|
ptr := Pointer(elem.ElementKind);
|
||||||
case elem.ElementKind of
|
case elem.ElementKind of
|
||||||
@ -2288,6 +2293,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// Now we construct the string from the parts stored in the stringlist.
|
||||||
|
// Every item processed is deleted from the list for error detection.
|
||||||
|
// In order not to confuse mix up we start at the end of the list and
|
||||||
|
// work forward.
|
||||||
i := L.Count-1;
|
i := L.Count-1;
|
||||||
while (L.Count > 0) and (i >= 0) do begin
|
while (L.Count > 0) and (i >= 0) do begin
|
||||||
fek := TFEKind(PtrInt(L.Objects[i]));
|
fek := TFEKind(PtrInt(L.Objects[i]));
|
||||||
@ -2332,7 +2341,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
if fek >= fekAdd then begin
|
if fek >= fekAdd then begin
|
||||||
elem := ACell^.RPNFormulaValue[i];
|
elem := ACell^.RPNFormulaValue[Length(ACell^.RPNFormulaValue) - 1 - i];
|
||||||
s := '';
|
s := '';
|
||||||
for j:= i+elem.ParamsNum downto i+1 do begin
|
for j:= i+elem.ParamsNum downto i+1 do begin
|
||||||
if j < L.Count then begin
|
if j < L.Count then begin
|
||||||
|
@ -1458,7 +1458,12 @@ begin
|
|||||||
while (AStream.Position < p0 + n) and supported do begin
|
while (AStream.Position < p0 + n) and supported do begin
|
||||||
token := AStream.ReadByte;
|
token := AStream.ReadByte;
|
||||||
case token of
|
case token of
|
||||||
INT_EXCEL_TOKEN_TREFV, INT_EXCEL_TOKEN_TREFR:
|
INT_EXCEL_TOKEN_TREFV:
|
||||||
|
begin
|
||||||
|
ReadRPNCellAddress(AStream, r, c, flags);
|
||||||
|
rpnItem := RPNCellValue(r, c, flags, rpnItem);
|
||||||
|
end;
|
||||||
|
INT_EXCEL_TOKEN_TREFR:
|
||||||
begin
|
begin
|
||||||
ReadRPNCellAddress(AStream, r, c, flags);
|
ReadRPNCellAddress(AStream, r, c, flags);
|
||||||
rpnItem := RPNCellRef(r, c, flags, rpnItem);
|
rpnItem := RPNCellRef(r, c, flags, rpnItem);
|
||||||
@ -1540,7 +1545,7 @@ begin
|
|||||||
Result := false;
|
Result := false;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
AFormula := CreateRPNFormula(rpnItem);
|
AFormula := CreateRPNFormula(rpnItem, true); // true --> we have to flip the order of items!
|
||||||
Result := true;
|
Result := true;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user