diff options
author | Gülşah Köse <gulsah.kose@collabora.com> | 2019-02-20 19:06:33 +0300 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2019-02-21 22:31:55 +0100 |
commit | 6676952d319e032a631bfe9d8ce23ebcb4c92f5b (patch) | |
tree | f74cfe15789f971ce7f5b931493a292159acb506 /oox | |
parent | Don't use the non-public fdatasync() API when sandboxed on macOS (diff) | |
download | core-6676952d319e032a631bfe9d8ce23ebcb4c92f5b.tar.gz core-6676952d319e032a631bfe9d8ce23ebcb4c92f5b.zip |
tdf#123090 Handle removed column with gridSpan.
This is a combination of 3 commits.
(cherry picked from commit 48ef20f2039d1a300a4324072e9b712c9994b406)
(cherry picked from commit 00e89430a2f8cd1f9ec702a7583a1e4c886a2b46)
(cherry picked from commit 1f0206d940cd8f7fb627a59cfe4165c0bfebaf46)
Change-Id: Ic6fa6f335623e2114fc8bea76dc54833284d2a02
Reviewed-on: https://gerrit.libreoffice.org/68154
Tested-by: Jenkins
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/table/tableproperties.cxx | 77 |
1 files changed, 60 insertions, 17 deletions
diff --git a/oox/source/drawingml/table/tableproperties.cxx b/oox/source/drawingml/table/tableproperties.cxx index 5f1495166b39..128668f012c4 100644 --- a/oox/source/drawingml/table/tableproperties.cxx +++ b/oox/source/drawingml/table/tableproperties.cxx @@ -273,33 +273,76 @@ const TableStyle& TableProperties::getUsedTableStyle( const ::oox::core::XmlFilt return *pTableStyle; } -void TableProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBase, - const Reference < XPropertySet >& xPropSet, const TextListStylePtr& pMasterTextListStyle ) +void TableProperties::pushToPropSet(const ::oox::core::XmlFilterBase& rFilterBase, + const Reference<XPropertySet>& xPropSet, + const TextListStylePtr& pMasterTextListStyle) { - uno::Reference< XColumnRowRange > xColumnRowRange( - xPropSet->getPropertyValue("Model"), uno::UNO_QUERY_THROW ); + uno::Reference<XColumnRowRange> xColumnRowRange(xPropSet->getPropertyValue("Model"), + uno::UNO_QUERY_THROW); - CreateTableColumns( xColumnRowRange->getColumns(), mvTableGrid ); - CreateTableRows( xColumnRowRange->getRows(), mvTableRows ); + CreateTableColumns(xColumnRowRange->getColumns(), mvTableGrid); + CreateTableRows(xColumnRowRange->getRows(), mvTableRows); TableStyle* pTableStyleToDelete = nullptr; - const TableStyle& rTableStyle( getUsedTableStyle( rFilterBase, pTableStyleToDelete ) ); + const TableStyle& rTableStyle(getUsedTableStyle(rFilterBase, pTableStyleToDelete)); sal_Int32 nRow = 0; - for (auto & tableRow : mvTableRows) + + for (auto& tableRow : mvTableRows) { sal_Int32 nColumn = 0; - for (auto & tableCell : tableRow.getTableCells()) + sal_Int32 nColumnSize = tableRow.getTableCells().size(); + sal_Int32 nRemovedColumn = 0; // + + for (sal_Int32 nColIndex = 0; nColIndex < nColumnSize; nColIndex++) { - TableCell& rTableCell(tableCell); - if ( !rTableCell.getvMerge() && !rTableCell.gethMerge() ) + TableCell& rTableCell(tableRow.getTableCells().at(nColIndex)); + + if (!rTableCell.getvMerge() && !rTableCell.gethMerge()) { - uno::Reference< XTable > xTable( xColumnRowRange, uno::UNO_QUERY_THROW ); - if ( ( rTableCell.getRowSpan() > 1 ) || ( rTableCell.getGridSpan() > 1 ) ) - MergeCells( xTable, nColumn, nRow, rTableCell.getGridSpan(), rTableCell.getRowSpan() ); + uno::Reference<XTable> xTable(xColumnRowRange, uno::UNO_QUERY_THROW); + bool bMerged = false; - Reference< XCellRange > xCellRange( xTable, UNO_QUERY_THROW ); - rTableCell.pushToXCell( rFilterBase, pMasterTextListStyle, xCellRange->getCellByPosition( nColumn, nRow ), *this, rTableStyle, - nColumn, tableRow.getTableCells().size()-1, nRow, mvTableRows.size()-1 ); + if ((rTableCell.getRowSpan() > 1) || (rTableCell.getGridSpan() > 1)) + { + MergeCells(xTable, nColumn, nRow, rTableCell.getGridSpan(), + rTableCell.getRowSpan()); + + if (rTableCell.getGridSpan() > 1) + { + nRemovedColumn = (rTableCell.getGridSpan() - 1); + // MergeCells removes columns. Our loop does not know about those + // removed columns and we skip handling those removed columns. + nColIndex += nRemovedColumn; + // It will adjust new column number after push current column's + // props with pushToXCell. + bMerged = true; + } + } + + Reference<XCellRange> xCellRange(xTable, UNO_QUERY_THROW); + Reference<XCell> xCell; + + if (nRemovedColumn) + { + try + { + xCell = xCellRange->getCellByPosition(nColumn, nRow); + } + // Exception can come from TableModel::getCellByPosition when a column + // is removed while merging columns. So adjust again here. + catch (Exception&) + { + xCell = xCellRange->getCellByPosition(nColumn - nRemovedColumn, nRow); + } + } + else + xCell = xCellRange->getCellByPosition(nColumn, nRow); + + rTableCell.pushToXCell(rFilterBase, pMasterTextListStyle, xCell, *this, rTableStyle, + nColumn, tableRow.getTableCells().size() - 1, nRow, + mvTableRows.size() - 1); + if (bMerged) + nColumn += nRemovedColumn; } ++nColumn; } |