You've already forked lazarus-ccr
fpspreadsheet: Read hidden state of row/column records in ODS format.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6636 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -390,6 +390,7 @@ type
|
|||||||
Col: Integer;
|
Col: Integer;
|
||||||
ColStyleIndex: integer; // index into FColumnStyleList of reader
|
ColStyleIndex: integer; // index into FColumnStyleList of reader
|
||||||
DefaultCellStyleIndex: Integer; // Index of default cell style in FCellStyleList of reader
|
DefaultCellStyleIndex: Integer; // Index of default cell style in FCellStyleList of reader
|
||||||
|
Hidden: Boolean; // Indicates that column is hidden
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Row style items stored in RowStyleList of the reader }
|
{ Row style items stored in RowStyleList of the reader }
|
||||||
@ -1118,7 +1119,11 @@ begin
|
|||||||
begin
|
begin
|
||||||
colData := TColumnData(FColumnList[i]);
|
colData := TColumnData(FColumnList[i]);
|
||||||
colIndex := colData.Col;
|
colIndex := colData.Col;
|
||||||
|
(*
|
||||||
|
writeLn('FColumnList[',i,']:');
|
||||||
|
WriteLn(' colIndex', colData.Col);
|
||||||
|
WriteLn(' hidden: ', colData.Hidden);
|
||||||
|
*)
|
||||||
// Skip column records beyond the last data column - there's a bug in OO/LO
|
// Skip column records beyond the last data column - there's a bug in OO/LO
|
||||||
// which adds column records up to the max column limit.
|
// which adds column records up to the max column limit.
|
||||||
if colIndex > lastOccCol then
|
if colIndex > lastOccCol then
|
||||||
@ -1146,6 +1151,10 @@ begin
|
|||||||
if (colWidthType = cwtCustom) then
|
if (colWidthType = cwtCustom) then
|
||||||
sheet.WriteColWidth(colIndex, colWidth, FWorkbook.Units);
|
sheet.WriteColWidth(colIndex, colWidth, FWorkbook.Units);
|
||||||
|
|
||||||
|
// Column visibility
|
||||||
|
if colData.Hidden then
|
||||||
|
sheet.HideCol(colIndex);
|
||||||
|
|
||||||
// Note: we don't store the column format index here; this is done in the
|
// Note: we don't store the column format index here; this is done in the
|
||||||
// row/cell reading method (ReadRowsAndCells).
|
// row/cell reading method (ReadRowsAndCells).
|
||||||
end;
|
end;
|
||||||
@ -1919,44 +1928,71 @@ var
|
|||||||
s: String;
|
s: String;
|
||||||
colStyleIndex: Integer;
|
colStyleIndex: Integer;
|
||||||
colData: TColumnData;
|
colData: TColumnData;
|
||||||
defCellStyleIndex: Integer;
|
defCellStyleIndex: Integer = -1;
|
||||||
colsRepeated: Integer;
|
colsRepeated: Integer;
|
||||||
j: Integer;
|
j: Integer;
|
||||||
|
isHidden: Boolean;
|
||||||
begin
|
begin
|
||||||
s := GetAttrValue(AColNode, 'table:style-name');
|
s := GetAttrValue(AColNode, 'table:style-name');
|
||||||
colStyleIndex := FindColStyleByName(s);
|
colStyleIndex := FindColStyleByName(s);
|
||||||
if colStyleIndex <> -1 then
|
if colStyleIndex <> -1 then
|
||||||
begin
|
begin
|
||||||
defCellStyleIndex := -1;
|
defCellStyleIndex := -1;
|
||||||
|
|
||||||
|
s := GetAttrValue(AColNode, 'table:visibility');
|
||||||
|
isHidden := (s = 'collapse');
|
||||||
|
|
||||||
s := GetAttrValue(AColNode, 'table:default-cell-style-name');
|
s := GetAttrValue(AColNode, 'table:default-cell-style-name');
|
||||||
if s <> '' then
|
if (s <> '') or isHidden then
|
||||||
begin
|
begin
|
||||||
defCellStyleIndex := FCellFormatList.FindIndexOfName(s); //FindCellStyleByName(s);
|
defCellStyleIndex := FCellFormatList.FindIndexOfName(s); //FindCellStyleByName(s);
|
||||||
colData := TColumnData.Create;
|
colData := TColumnData.Create;
|
||||||
colData.Col := col;
|
colData.Col := col;
|
||||||
colData.ColStyleIndex := colStyleIndex;
|
colData.ColStyleIndex := colStyleIndex;
|
||||||
colData.DefaultCellStyleIndex := defCellStyleIndex;
|
colData.DefaultCellStyleIndex := defCellStyleIndex;
|
||||||
|
colData.Hidden := isHidden;
|
||||||
FColumnList.Add(colData);
|
FColumnList.Add(colData);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
s := GetAttrValue(AColNode, 'table:number-columns-repeated');
|
s := GetAttrValue(AColNode, 'table:number-columns-repeated');
|
||||||
if s = '' then
|
if s = '' then
|
||||||
|
colsRepeated := 0
|
||||||
|
else
|
||||||
|
colsRepeated := StrToInt(s);
|
||||||
|
inc(col);
|
||||||
|
if (defCellStyleIndex > -1) or isHidden then begin
|
||||||
|
for j := 0 to colsRepeated-1 do
|
||||||
|
begin
|
||||||
|
coldata := TColumnData.Create;
|
||||||
|
colData.Col := col + j;
|
||||||
|
colData.ColStyleIndex := colStyleIndex;
|
||||||
|
colData.DefaultCellStyleIndex := defCellStyleIndex;
|
||||||
|
colData.Hidden := isHidden;
|
||||||
|
FColumnList.Add(colData);
|
||||||
|
inc(col);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
(*
|
||||||
|
|
||||||
|
if (s = '') and (not isHidden) then
|
||||||
inc(col)
|
inc(col)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
colsRepeated := StrToInt(s);
|
colsRepeated := StrToInt(s);
|
||||||
if defCellStyleIndex > -1 then begin
|
if (defCellStyleIndex > -1) or isHidden then begin
|
||||||
for j:=1 to colsRepeated-1 do
|
for j:=1 to colsRepeated-1 do
|
||||||
begin
|
begin
|
||||||
colData := TColumnData.Create;
|
colData := TColumnData.Create;
|
||||||
colData.Col := col + j;
|
colData.Col := col + j;
|
||||||
colData.ColStyleIndex := colStyleIndex;
|
colData.ColStyleIndex := colStyleIndex;
|
||||||
colData.DefaultCellStyleIndex := defCellStyleIndex;
|
colData.DefaultCellStyleIndex := defCellStyleIndex;
|
||||||
|
colData.Hidden := isHidden;
|
||||||
FColumnList.Add(colData);
|
FColumnList.Add(colData);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
inc(col, colsRepeated);
|
inc(col, colsRepeated);
|
||||||
end;
|
end;
|
||||||
|
*)
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2659,7 +2695,7 @@ begin
|
|||||||
ReadPrintRanges(TableNode, FWorksheet);
|
ReadPrintRanges(TableNode, FWorksheet);
|
||||||
// Apply table style
|
// Apply table style
|
||||||
ApplyTableStyle(FWorksheet, tablestylename);
|
ApplyTableStyle(FWorksheet, tablestylename);
|
||||||
// Handle columns and rows
|
// Handle columns
|
||||||
ApplyColWidths;
|
ApplyColWidths;
|
||||||
// Page layout
|
// Page layout
|
||||||
FixCols(FWorksheet);
|
FixCols(FWorksheet);
|
||||||
@ -3651,6 +3687,7 @@ var
|
|||||||
hasRowFormat: Boolean;
|
hasRowFormat: Boolean;
|
||||||
styleIndex: Integer;
|
styleIndex: Integer;
|
||||||
firstStyleIndex: Integer;
|
firstStyleIndex: Integer;
|
||||||
|
rowHidden: Boolean;
|
||||||
begin
|
begin
|
||||||
// Read rowstyle
|
// Read rowstyle
|
||||||
rowStyleName := GetAttrValue(ARowNode, 'table:style-name');
|
rowStyleName := GetAttrValue(ARowNode, 'table:style-name');
|
||||||
@ -3737,20 +3774,29 @@ var
|
|||||||
cellNode := cellNode.NextSibling;
|
cellNode := cellNode.NextSibling;
|
||||||
end; //while Assigned(cellNode)
|
end; //while Assigned(cellNode)
|
||||||
|
|
||||||
|
// Row visibility
|
||||||
|
rowHidden := GetAttrValue(ARowNode, 'table:visibility') = 'collapse';
|
||||||
|
if rowHidden then
|
||||||
|
TsWorksheet(FWorksheet).HideRow(row);
|
||||||
|
|
||||||
|
// Repeated rows
|
||||||
s := GetAttrValue(ARowNode, 'table:number-rows-repeated');
|
s := GetAttrValue(ARowNode, 'table:number-rows-repeated');
|
||||||
if s = '' then
|
if s = '' then
|
||||||
rowsRepeated := 1
|
rowsRepeated := 1
|
||||||
else
|
else
|
||||||
rowsRepeated := StrToInt(s);
|
rowsRepeated := StrToInt(s);
|
||||||
|
|
||||||
// Transfer non-default row heights to sheet's rows
|
// Transfer non-default row heights and row hidden status to sheet's rows
|
||||||
// This first "if" is a workaround for a bug of LO/OO whichs extends imported
|
// This first "if" is a workaround for a bug of LO/OO whichs extends imported
|
||||||
// xlsx files with blank rows up to their specification limit.
|
// xlsx files with blank rows up to their specification limit.
|
||||||
// Process some rows earlier because the added row range is sometimes split
|
// Process some rows earlier because the added row range is sometimes split
|
||||||
// into two parts.
|
// into two parts.
|
||||||
if row + rowsRepeated < LongInt(FLimitations.MaxRowCount) - 10 then
|
if row + rowsRepeated < LongInt(FLimitations.MaxRowCount) - 10 then
|
||||||
for i:=1 to rowsRepeated do
|
for i:=1 to rowsRepeated do begin
|
||||||
TsWorksheet(FWorksheet).WriteRowHeight(row + i - 1, rowHeight, FWorkbook.Units, rowHeightType);
|
TsWorksheet(FWorksheet).WriteRowHeight(row + i - 1, rowHeight, FWorkbook.Units, rowHeightType);
|
||||||
|
if rowHidden then
|
||||||
|
TsWorksheet(FWorksheet).HideRow(row + i - 1);
|
||||||
|
end;
|
||||||
|
|
||||||
// Prepare checking of column format
|
// Prepare checking of column format
|
||||||
if GetRowFormat then begin
|
if GetRowFormat then begin
|
||||||
@ -6148,7 +6194,7 @@ begin
|
|||||||
GetRowStyleAndHeight(ASheet, ARowIndex, stylename, h);
|
GetRowStyleAndHeight(ASheet, ARowIndex, stylename, h);
|
||||||
|
|
||||||
// Row hidden?
|
// Row hidden?
|
||||||
if (round(h) = 0) or row^.Hidden then
|
if (round(h) = 0) or (Assigned(row) and row^.Hidden) then
|
||||||
rowHiddenStr := ' table:visibility="collapse"'
|
rowHiddenStr := ' table:visibility="collapse"'
|
||||||
else
|
else
|
||||||
rowHiddenStr := '';
|
rowHiddenStr := '';
|
||||||
|
@ -380,6 +380,8 @@ begin
|
|||||||
break;
|
break;
|
||||||
if sheet.FindNextCellInCol(0, c) <> nil then
|
if sheet.FindNextCellInCol(0, c) <> nil then
|
||||||
break;
|
break;
|
||||||
|
if lCol.Hidden then
|
||||||
|
break;
|
||||||
sheet.RemoveCol(c);
|
sheet.RemoveCol(c);
|
||||||
dec(c);
|
dec(c);
|
||||||
end;
|
end;
|
||||||
@ -408,7 +410,7 @@ begin
|
|||||||
// ...and delete all column records with non-default format
|
// ...and delete all column records with non-default format
|
||||||
for c := sheet.Cols.Count-1 downto 0 do begin
|
for c := sheet.Cols.Count-1 downto 0 do begin
|
||||||
lCol := PCol(sheet.Cols[c]);
|
lCol := PCol(sheet.Cols[c]);
|
||||||
if lCol^.FormatIndex = 0 then sheet.RemoveCol(c);
|
if (lCol^.FormatIndex = 0) and (not lCol^.Hidden) then sheet.RemoveCol(c);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -455,7 +457,7 @@ begin
|
|||||||
// ... and delete all row records with default format.
|
// ... and delete all row records with default format.
|
||||||
for r := sheet.Rows.Count-1 downto 0 do begin
|
for r := sheet.Rows.Count-1 downto 0 do begin
|
||||||
lRow := PRow(sheet.Rows[r]);
|
lRow := PRow(sheet.Rows[r]);
|
||||||
if lRow^.FormatIndex = 0 then sheet.RemoveRow(r);
|
if (lRow^.FormatIndex = 0) and (not lRow^.Hidden) then sheet.RemoveRow(r);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user