diff --git a/src/Mod/Spreadsheet/App/PropertySheet.cpp b/src/Mod/Spreadsheet/App/PropertySheet.cpp index c536a925bf73..eeeb7b387227 100644 --- a/src/Mod/Spreadsheet/App/PropertySheet.cpp +++ b/src/Mod/Spreadsheet/App/PropertySheet.cpp @@ -567,8 +567,9 @@ class RewriteExpressionVisitor : public ExpressionVisitor { if (varExpr) { static const boost::regex e("(\\${0,1})([A-Za-z]+)(\\${0,1})([0-9]+)"); boost::cmatch cm; + std::string s = varExpr->name(); - if (boost::regex_match(varExpr->name().c_str(), cm, e)) { + if (boost::regex_match(s.c_str(), cm, e)) { const boost::sub_match colstr = cm[2]; const boost::sub_match rowstr = cm[4]; int thisRow, thisCol; @@ -590,11 +591,11 @@ class RewriteExpressionVisitor : public ExpressionVisitor { CellAddress to(r.to()); if (from.row() >= mRow || from.col() >= mCol) { - from = CellAddress(from.row() + mRowCount, from.col() + mColCount); + from = CellAddress(std::max(0, from.row() + mRowCount), std::max(0, from.col() + mColCount)); mChanged = true; } if (to.row() >= mRow || to.col() >= mCol) { - to = CellAddress(to.row() + mRowCount, to.col() + mColCount); + to = CellAddress(std::max(0, to.row() + mRowCount), std::max(0, to.col() + mColCount)); mChanged = true; } rangeExpr->setRange(Range(from, to)); @@ -667,7 +668,7 @@ void PropertySheet::removeRows(int row, int count) /* Sort them */ std::sort(keys.begin(), keys.end(), boost::bind(&PropertySheet::rowSortFunc, this, _1, _2)); - RewriteExpressionVisitor visitor(CellAddress(row + count, CellAddress::MAX_COLUMNS), -count, 0); + RewriteExpressionVisitor visitor(CellAddress(row + count - 1, CellAddress::MAX_COLUMNS), -count, 0); Signaller signaller(*this); for (std::vector::const_iterator i = keys.begin(); i != keys.end(); ++i) { @@ -753,7 +754,7 @@ void PropertySheet::removeColumns(int col, int count) /* Sort them */ std::sort(keys.begin(), keys.end(), boost::bind(&PropertySheet::colSortFunc, this, _1, _2)); - RewriteExpressionVisitor visitor(CellAddress(CellAddress::MAX_ROWS, col + count), 0, -count); + RewriteExpressionVisitor visitor(CellAddress(CellAddress::MAX_ROWS, col + count - 1), 0, -count); Signaller signaller(*this); for (std::vector::const_iterator i = keys.begin(); i != keys.end(); ++i) {