fpspreadsheet: Relax detection of boolean xml attributes for better reading of xlsx files written by LibreOffice Calc.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6585 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2018-08-10 14:21:10 +00:00
parent 1a0404f2ee
commit 1c7bd8d915

View File

@ -584,11 +584,11 @@ begin
nodeName := borderNode.NodeName; nodeName := borderNode.NodeName;
if nodeName = 'border' then begin if nodeName = 'border' then begin
borders := []; borders := [];
s := GetAttrValue(borderNode, 'diagonalUp'); s := Lowercase(GetAttrValue(borderNode, 'diagonalUp'));
if s = '1' then if (s = '1') or (s = 'true') then
Include(borders, cbDiagUp); Include(borders, cbDiagUp);
s := GetAttrValue(borderNode, 'diagonalDown'); s := LowerCase(GetAttrValue(borderNode, 'diagonalDown'));
if s = '1' then if (s = '1') or (s = 'true') then
Include(borders, cbDiagDown); Include(borders, cbDiagDown);
edgeNode := borderNode.FirstChild; edgeNode := borderNode.FirstChild;
while Assigned(edgeNode) do begin while Assigned(edgeNode) do begin
@ -995,11 +995,11 @@ begin
nodeName := childNode.NodeName; nodeName := childNode.NodeName;
if nodeName = 'protection' then if nodeName = 'protection' then
begin begin
s1 := GetAttrValue(childNode, 'locked'); s1 := LowerCase(GetAttrValue(childNode, 'locked'));
if (s1 = '0') then if (s1 = '0') or (s1 = 'false') then
Exclude(cp, cpLockCell); Exclude(cp, cpLockCell);
s1 := GetAttrValue(childNode, 'hidden'); s1 := Lowercase(GetAttrValue(childNode, 'hidden'));
if (s1= '1') then if (s1 = '1') or (s1 = 'true') then
Include(cp, cpHideFormulas); Include(cp, cpHideFormulas);
end; end;
childNode := childNode.NextSibling; childNode := childNode.NextSibling;
@ -1037,8 +1037,8 @@ var
begin begin
Assert(ANode <> nil); Assert(ANode <> nil);
s := GetAttrValue(ANode, 'auto'); s := Lowercase(GetAttrValue(ANode, 'auto'));
if s = '1' then begin if (s = '1') or (s = 'true') then begin
if ANode.NodeName = 'fgColor' then if ANode.NodeName = 'fgColor' then
Result := scBlack Result := scBlack
else else
@ -1136,8 +1136,8 @@ begin
s := GetAttrValue(colNode, 'max'); s := GetAttrValue(colNode, 'max');
if s <> '' then col2 := StrToInt(s)-1 else col2 := col1; if s <> '' then col2 := StrToInt(s)-1 else col2 := col1;
s := GetAttrValue(colNode, 'customWidth'); s := Lowercase(GetAttrValue(colNode, 'customWidth'));
if s = '1' then begin if (s = '1') or (s = 'true') then begin
s := GetAttrValue(colNode, 'width'); s := GetAttrValue(colNode, 'width');
if (s <> '') and TryStrToFloat(s, w, FPointSeparatorSettings) then if (s <> '') and TryStrToFloat(s, w, FPointSeparatorSettings) then
begin begin
@ -1222,8 +1222,8 @@ var
s: String; s: String;
begin begin
if Assigned(ANode) then begin if Assigned(ANode) then begin
s := GetAttrValue(ANode, 'date1904'); s := Lowercase(GetAttrValue(ANode, 'date1904'));
if s = '1' then FDateMode := dm1904 if (s = '1') or (s = 'true') then FDateMode := dm1904
end; end;
end; end;
@ -1589,12 +1589,12 @@ begin
if ANode = nil then if ANode = nil then
exit; exit;
s := GetAttrValue(ANode, 'differentOddEven'); s := Lowercase(GetAttrValue(ANode, 'differentOddEven'));
if s = '1' then if (s = '1') or (s = 'true') then
with sheet.PageLayout do Options := Options + [poDifferentOddEven]; with sheet.PageLayout do Options := Options + [poDifferentOddEven];
s := GetAttrValue(ANode, 'differentFirst'); s := Lowercase(GetAttrValue(ANode, 'differentFirst'));
if s = '1' then if (s = '1') or (s = 'true') then
with sheet.PageLayout do Options := Options + [poDifferentFirst]; with sheet.PageLayout do Options := Options + [poDifferentFirst];
node := ANode.FirstChild; node := ANode.FirstChild;
@ -1823,9 +1823,9 @@ begin
if s <> '' then if s <> '' then
sheet.PageLayout.StartPageNumber := StrToInt(s); sheet.PageLayout.StartPageNumber := StrToInt(s);
s := GetAttrValue(ANode, 'useFirstPageNumber'); s := Lowercase(GetAttrValue(ANode, 'useFirstPageNumber'));
with sheet.PageLayout do with sheet.PageLayout do
if s = '1' then if (s = '1') or (s = 'true') then
Options := Options + [poUseStartPageNumber] Options := Options + [poUseStartPageNumber]
else else
Options := Options - [poUseStartPageNumber]; Options := Options - [poUseStartPageNumber];
@ -1836,13 +1836,13 @@ begin
with sheet.PageLayout do Options := Options + [poPrintPagesByRows]; with sheet.PageLayout do Options := Options + [poPrintPagesByRows];
// Monochrome // Monochrome
s := GetAttrValue(ANode, 'blackAndWhite'); s := LowerCase(GetAttrValue(ANode, 'blackAndWhite'));
if s = '1' then if (s = '1') or (s = 'true') then
with sheet.PageLayout do Options := Options + [poMonochrome]; with sheet.PageLayout do Options := Options + [poMonochrome];
// Quality // Quality
s := GetAttrValue(ANode, 'draft'); s := Lowercase(GetAttrValue(ANode, 'draft'));
if s = '1' then if (s = '1') or (s = 'true') then
with sheet.PageLayout do Options := Options + [poDraftQuality]; with sheet.PageLayout do Options := Options + [poDraftQuality];
end; end;
@ -1904,12 +1904,12 @@ var
begin begin
if ANode = nil then if ANode = nil then
exit; exit;
s := GetAttrValue(ANode, 'headings'); s := Lowercase(GetAttrValue(ANode, 'headings'));
if (s = '1') then if (s = '1') or (s = 'true') then
with sheet.PageLayout do Options := Options + [poPrintHeaders]; with sheet.PageLayout do Options := Options + [poPrintHeaders];
s := GetAttrValue(ANode, 'gridLines'); s := Lowercase(GetAttrValue(ANode, 'gridLines'));
if (s = '1') then if (s = '1') or (s = 'true') then
with sheet.PageLayout do Options := Options + [poPrintGridLines]; with sheet.PageLayout do Options := Options + [poPrintGridLines];
end; end;
@ -1926,8 +1926,8 @@ begin
exit; exit;
{ Row height type } { Row height type }
s := GetAttrValue(ANode, 'customHeight'); s := Lowercase(GetAttrValue(ANode, 'customHeight'));
if s = '1' then if (s = '1') or (s = 'true') then
lRow.RowHeightType := rhtCustom lRow.RowHeightType := rhtCustom
else else
lRow.RowHeightType := rhtAuto; lRow.RowHeightType := rhtAuto;
@ -1951,8 +1951,8 @@ begin
{ Row format } { Row format }
lRow.FormatIndex := 0; // Default format lRow.FormatIndex := 0; // Default format
s := GetAttrValue(ANode, 'customFormat'); s := Lowercase(GetAttrValue(ANode, 'customFormat'));
if s = '1' then begin if (s = '1') or (s = 'true') then begin
s := GetAttrValue(ANode, 's'); s := GetAttrValue(ANode, 's');
if s <> '' then begin if s <> '' then begin
idx := FCellFormatList.FindIndexOfID(StrToInt(s)); idx := FCellFormatList.FindIndexOfID(StrToInt(s));
@ -2115,21 +2115,30 @@ begin
shp := DEFAULT_SHEET_PROTECTION; shp := DEFAULT_SHEET_PROTECTION;
// Attribute not found -> property = false // Attribute not found -> property = false
s := GetAttrValue(ANode, 'sheet'); s := LowerCase(GetAttrValue(ANode, 'sheet'));
if (s = '1') then Include(shp, spCells) else if (s = '1') or (s = 'true') then
if (s = '0') or (s = '') then Exclude(shp, spCells); Include(shp, spCells)
else if (s = '0') or (s = '') or (s = 'false') then
Exclude(shp, spCells);
s := GetAttrValue(ANode, 'selectLockedCells'); s := Lowercase(GetAttrValue(ANode, 'selectLockedCells'));
if (s = '1') then Include(shp, spSelectLockedCells) else if (s = '1') or (s = 'true') then
if (s = '0') or (s = '') then Exclude(shp, spSelectLockedCells); Include(shp, spSelectLockedCells)
else if (s = '0') or (s = '') or (s = 'false') then
Exclude(shp, spSelectLockedCells);
s := GetAttrValue(ANode, 'selectUnlockedCells'); s := LowerCase(GetAttrValue(ANode, 'selectUnlockedCells'));
if (s = '1') then Include(shp, spSelectUnlockedCells) else if (s = '1') or (s = 'true') then
if (s = '') or (s = '0') then Exclude(shp, spSelectUnlockedCells); Include(shp, spSelectUnlockedCells)
else if (s = '') or (s = '0') or (s = 'false') then
Exclude(shp, spSelectUnlockedCells);
s := GetAttrValue(ANode, 'objects'); s := Lowercase(GetAttrValue(ANode, 'objects'));
if (s = '1') then Include(shp, spObjects) else if (s = '1') or (s = 'true') then
if (s = '') or (s = '0') then Exclude(shp, spObjects); Include(shp, spObjects)
else
if (s = '') or (s = '0') or (s = 'false') then
Exclude(shp, spObjects);
// these options are currently not supported by fpspreadsheet // these options are currently not supported by fpspreadsheet
{ {
@ -2145,47 +2154,73 @@ begin
if (s = '') or (s = '1') then Include(shp, spAutoFilter); if (s = '') or (s = '1') then Include(shp, spAutoFilter);
} }
s := GetAttrValue(ANode, 'deleteColumns'); s := LowerCase(GetAttrValue(ANode, 'deleteColumns'));
if (s = '0') then Exclude(shp, spDeleteColumns) else if (s = '0') or (s = 'true') then
if (s = '') or (s = '1') then Include(shp, spDeleteColumns); Exclude(shp, spDeleteColumns)
else
if (s = '') or (s = '1') or (s = 'false') then
Include(shp, spDeleteColumns);
s := GetAttrValue(ANode, 'deleteRows'); s := Lowercase(GetAttrValue(ANode, 'deleteRows'));
if (s = '0') then Exclude(shp, spDeleteRows) else if (s = '0') or (s = 'false') then
if (s = '') or (s = '1') then Include(shp, spDeleteRows); Exclude(shp, spDeleteRows)
else
if (s = '') or (s = '1') or (s = 'true') then
Include(shp, spDeleteRows);
s := GetAttrValue(ANode, 'formatCells'); s := Lowercase(GetAttrValue(ANode, 'formatCells'));
if (s = '0') then Exclude(shp, spFormatCells) else if (s = '0') or (s = 'false') then
if (s = '') or (s = '1') then Include(shp, spFormatCells); Exclude(shp, spFormatCells)
else
if (s = '') or (s = '1') or (s = 'true') then
Include(shp, spFormatCells);
s := GetAttrValue(ANode, 'formatColumns'); s := Lowercase(GetAttrValue(ANode, 'formatColumns'));
if (s = '0') then Exclude(shp, spFormatColumns) else if (s = '0') or (s = 'false') then
if (s = '') or (s = '1') then Include(shp, spFormatColumns); Exclude(shp, spFormatColumns)
else
if (s = '') or (s = '1') or (s = 'true') then
Include(shp, spFormatColumns);
s := GetAttrValue(ANode, 'formatRows'); s := Lowercase(GetAttrValue(ANode, 'formatRows'));
if (s = '0') then Exclude(shp, spFormatRows) else if (s = '0') or (s = 'false') then
if (s = '') or (s = '1') then Include(shp, spFormatRows); Exclude(shp, spFormatRows)
else
if (s = '') or (s = '1') or (s = 'true') then
Include(shp, spFormatRows);
s := GetAttrValue(ANode, 'insertColumns'); s := Lowercase(GetAttrValue(ANode, 'insertColumns'));
if (s = '0') then Exclude(shp, spInsertColumns) else if (s = '0') or (s = 'false') then
if (s = '') or (s = '1') then Include(shp, spInsertColumns); Exclude(shp, spInsertColumns)
else
if (s = '') or (s = '1') or (s = 'true') then
Include(shp, spInsertColumns);
s := GetAttrValue(ANode, 'insertHyperlinks'); s := Lowercase(GetAttrValue(ANode, 'insertHyperlinks'));
if (s = '0') then Exclude(shp, spInsertHyperlinks) else if (s = '0') or (s = 'false') then
if (s = '') or (s = '1') then Include(shp, spInsertHyperlinks); Exclude(shp, spInsertHyperlinks)
else
if (s = '') or (s = '1') or (s = 'true') then
Include(shp, spInsertHyperlinks);
s := GetAttrValue(ANode, 'insertRows'); s := GetAttrValue(ANode, 'insertRows');
if (s = '0') then Exclude(shp, spInsertRows) else if (s = '0') then Exclude(shp, spInsertRows) else
if (s = '') or (s = '1') then Include(shp, spInsertRows); if (s = '') or (s = '1') then Include(shp, spInsertRows);
s := GetAttrValue(ANode, 'sort'); s := Lowercase(GetAttrValue(ANode, 'sort'));
if (s = '0') then Exclude(shp, spSort) else if (s = '0') or (s = 'false') then
if (s = '') or (s = '1') then Include(shp, spSort); Exclude(shp, spSort)
else
if (s = '') or (s = '1') or (s = 'true') then
Include(shp, spSort);
// Currently no pivottable support in fpspreadsheet // Currently no pivottable support in fpspreadsheet
{ {
s := GetAttrValue(ANode, 'pivotTables'); s := Lowercase(GetAttrValue(ANode, 'pivotTables'));
if (s = '0') then Exclude(shp, spPivotTables) else if (s = '0') or (s = 'false') then
if (s = '') or (s = '1') then Include(shp, spPivotTables); Exclude(shp, spPivotTables)
else if (s = '') or (s = '1') or (s = 'true') then
Include(shp, spPivotTables);
} }
with AWorksheet as TsWorksheet do begin with AWorksheet as TsWorksheet do begin
@ -2211,30 +2246,30 @@ begin
while Assigned(sheetViewNode) do begin while Assigned(sheetViewNode) do begin
nodeName := sheetViewNode.NodeName; nodeName := sheetViewNode.NodeName;
if nodeName = 'sheetView' then begin if nodeName = 'sheetView' then begin
s := GetAttrValue(sheetViewNode, 'showGridLines'); s := Lowercase(GetAttrValue(sheetViewNode, 'showGridLines'));
if s = '0' then if (s = '0') or (s = 'false') then
sheet.Options := AWorksheet.Options - [soShowGridLines]; sheet.Options := AWorksheet.Options - [soShowGridLines];
s := GetAttrValue(sheetViewNode, 'showRowColHeaders'); s := LowerCase(GetAttrValue(sheetViewNode, 'showRowColHeaders'));
if s = '0' then if (s = '0') or (s = 'false') then
sheet.Options := AWorksheet.Options - [soShowHeaders]; sheet.Options := AWorksheet.Options - [soShowHeaders];
s := GetAttrValue(sheetViewNode, 'tabSelected'); s := Lowercase(GetAttrValue(sheetViewNode, 'tabSelected'));
if s = '1' then if (s = '1') or (s = 'false') then
(FWorkbook as TsWorkbook).ActiveWorksheet := sheet; (FWorkbook as TsWorkbook).ActiveWorksheet := sheet;
s := GetAttrValue(sheetViewNode, 'windowProtection'); s := Lowercase(GetAttrValue(sheetViewNode, 'windowProtection'));
if s = '1' then if (s = '1') or (s = 'true') then
sheet.Options := sheet.Options + [soPanesProtection]; sheet.Options := sheet.Options + [soPanesProtection];
s := GetAttrValue(sheetViewNode, 'zoomScale'); s := GetAttrValue(sheetViewNode, 'zoomScale');
if s <> '' then if s <> '' then
sheet.ZoomFactor := StrToFloat(s, FPointSeparatorSettings) * 0.01; sheet.ZoomFactor := StrToFloat(s, FPointSeparatorSettings) * 0.01;
s := GetAttrValue(sheetViewNode, 'rightToLeft'); s := Lowercase(GetAttrValue(sheetViewNode, 'rightToLeft'));
if s = '0' then if (s = '0') or (s = 'false') then
sheet.BiDiMode := bdLTR sheet.BiDiMode := bdLTR
else if s = '1' then else if (s = '1') = (s = 'true') then
sheet.BiDiMode := bdRTL; sheet.BiDiMode := bdRTL;
childNode := sheetViewNode.FirstChild; childNode := sheetViewNode.FirstChild;
@ -2394,16 +2429,16 @@ begin
end; end;
Workbook.RevisionsCrypto := wbc; Workbook.RevisionsCrypto := wbc;
} }
s := GetAttrValue(ANode, 'lockStructure'); s := Lowercase(GetAttrValue(ANode, 'lockStructure'));
if (s = '1') then if (s = '1') or (s = 'true')then
Include(wbp, bpLockStructure); Include(wbp, bpLockStructure);
s := GetAttrValue(ANode, 'lockWindows'); s := Lowercase(GetAttrValue(ANode, 'lockWindows'));
if (s = '1') then if (s = '1') or (s = 'true') then
Include(wbp, bpLockWindows); Include(wbp, bpLockWindows);
s := GetAttrValue(ANode, 'lockRevision'); s := Lowercase(GetAttrValue(ANode, 'lockRevision'));
if (s = '1') then if (s = '1') or (s = 'true') then
Include(wbp, bpLockRevision); Include(wbp, bpLockRevision);
Workbook.Protection := wbp; Workbook.Protection := wbp;