summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGülşah Köse <gulsah.kose@collabora.com>2019-02-20 19:06:33 +0300
committerAndras Timar <andras.timar@collabora.com>2019-02-21 09:07:01 +0100
commit48ef20f2039d1a300a4324072e9b712c9994b406 (patch)
tree33ed89b2bbdc9186d9890a1f21fd7c3d622101b1
parentffc59a0c4fcc7f5486447c7132cf1133ba58e115 (diff)
tdf#123090 Handle removed column with gridSpan.
Change-Id: If477845972ce4c8e7bf09ea8718c58851a5b9740 Signed-off-by: Gülşah Köse <gulsah.kose@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/68102 Tested-by: Jenkins Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--oox/source/drawingml/table/tableproperties.cxx50
-rw-r--r--sd/qa/unit/import-tests.cxx2
-rw-r--r--svx/source/table/cellcursor.cxx1
-rw-r--r--svx/source/table/tablecontroller.cxx1
4 files changed, 48 insertions, 6 deletions
diff --git a/oox/source/drawingml/table/tableproperties.cxx b/oox/source/drawingml/table/tableproperties.cxx
index e0afeb7c8246..5bd61e8d97ae 100644
--- a/oox/source/drawingml/table/tableproperties.cxx
+++ b/oox/source/drawingml/table/tableproperties.cxx
@@ -282,21 +282,63 @@ void TableProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBa
std::unique_ptr<TableStyle> xTableStyleToDelete;
const TableStyle& rTableStyle( getUsedTableStyle( rFilterBase, xTableStyleToDelete ) );
sal_Int32 nRow = 0;
+
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);
+ TableCell& rTableCell(tableRow.getTableCells().at(nColIndex));
+
if ( !rTableCell.getvMerge() && !rTableCell.gethMerge() )
{
uno::Reference< XTable > xTable( xColumnRowRange, uno::UNO_QUERY_THROW );
+ bool bMerged = false;
+
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. So our loop don't know that removed column and we are skip the handlingthat removed column(s).
+ nColIndex += nRemovedColumn;
+ bMerged = true; // it will adjust new column number after push current column's props with pushToXCell.
+ }
+ }
+
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 );
+ Reference < XCell > xCell;
+
+ if(nRemovedColumn)
+ {
+ try
+ {
+ xCell = xCellRange->getCellByPosition( nColumn, nRow );
+ }
+ catch(Exception&) //Exception can come from TableModel::getCellByPosition when an column removed while merging columns. So adjust again here.
+ {
+ 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;
}
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 630856750799..a085a1ae09ce 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -2518,7 +2518,7 @@ void SdImportTest::testTdf119015()
uno::Reference<table::XTable> xTable(pTableObj->getTable());
// Test that we actually have three cells: this threw css.lang.IndexOutOfBoundsException
- uno::Reference<text::XTextRange> xTextRange(xTable->getCellByPosition(2, 0),
+ uno::Reference<text::XTextRange> xTextRange(xTable->getCellByPosition(1, 0),
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(OUString("A3"), xTextRange->getString());
diff --git a/svx/source/table/cellcursor.cxx b/svx/source/table/cellcursor.cxx
index bdd7156ef669..d77dbb3ffc59 100644
--- a/svx/source/table/cellcursor.cxx
+++ b/svx/source/table/cellcursor.cxx
@@ -251,6 +251,7 @@ void SAL_CALL CellCursor::merge( )
try
{
mxTable->merge( aStart.mnCol, aStart.mnRow, aEnd.mnCol - aStart.mnCol + 1, aEnd.mnRow - aStart.mnRow + 1 );
+ mxTable->optimize();
mxTable->setModified(true);
}
catch( Exception& )
diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx
index d79e094bf601..57b3171d7a82 100644
--- a/svx/source/table/tablecontroller.cxx
+++ b/svx/source/table/tablecontroller.cxx
@@ -1839,7 +1839,6 @@ void SvxTableController::MergeRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, s
}
xRange->merge();
- mxTable->optimize();
mbHasJustMerged = true;
setSelectedCells( maCursorFirstPos, maCursorFirstPos );