Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D8878200D40 for ; Sat, 4 Nov 2017 05:29:51 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D700B160BFC; Sat, 4 Nov 2017 04:29:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 00C47160BFB for ; Sat, 4 Nov 2017 05:29:50 +0100 (CET) Received: (qmail 22516 invoked by uid 500); 4 Nov 2017 04:29:50 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 22507 invoked by uid 99); 4 Nov 2017 04:29:49 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Nov 2017 04:29:49 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 36F633A0158 for ; Sat, 4 Nov 2017 04:29:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1814253 - /poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Date: Sat, 04 Nov 2017 04:29:45 -0000 To: commits@poi.apache.org From: onealj@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20171104042948.36F633A0158@svn01-us-west.apache.org> archived-at: Sat, 04 Nov 2017 04:29:52 -0000 Author: onealj Date: Sat Nov 4 04:29:45 2017 New Revision: 1814253 URL: http://svn.apache.org/viewvc?rev=1814253&view=rev Log: github-81: extract routines in HSSFRow#shiftRows Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=1814253&r1=1814252&r2=1814253&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Sat Nov 4 04:29:45 2017 @@ -1580,17 +1580,7 @@ public final class HSSFSheet implements // comments to the first or last row, rather than moving them out of // bounds or deleting them if (moveComments) { - final HSSFPatriarch patriarch = createDrawingPatriarch(); - for (final HSSFShape shape : patriarch.getChildren()) { - if (!(shape instanceof HSSFComment)) { - continue; - } - final HSSFComment comment = (HSSFComment) shape; - final int r = comment.getRow(); - if (startRow <= r && r <= endRow) { - comment.setRow(clip(r + n)); - } - } + moveCommentsForRowShift(startRow, endRow, n); } // Shift Merged Regions @@ -1600,17 +1590,7 @@ public final class HSSFSheet implements _sheet.getPageSettings().shiftRowBreaks(startRow, endRow, n); // Delete overwritten hyperlinks - final int firstOverwrittenRow = startRow + n; - final int lastOverwrittenRow = endRow + n; - for (HSSFHyperlink link : getHyperlinkList()) { - // If hyperlink is fully contained in the rows that will be overwritten, delete the hyperlink - final int firstRow = link.getFirstRow(); - final int lastRow = link.getLastRow(); - if (firstOverwrittenRow <= firstRow && firstRow <= lastOverwrittenRow && - lastOverwrittenRow <= lastRow && lastRow <= lastOverwrittenRow) { - removeHyperlink(link); - } - } + deleteOverwrittenHyperlinksForRowShift(startRow, endRow, n); for (int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc) { HSSFRow row = getRow(rowNum); @@ -1664,6 +1644,35 @@ public final class HSSFSheet implements } // Re-compute the first and last rows of the sheet as needed + recomputeFirstAndLastRowsForRowShift(startRow, endRow, n); + + // Update formulas that refer to rows that have been moved + updateFormulasForRowShift(startRow, endRow, n); + } + + private void updateFormulasForRowShift(int startRow, int endRow, int n) { + int sheetIndex = _workbook.getSheetIndex(this); + String sheetName = _workbook.getSheetName(sheetIndex); + short externSheetIndex = _book.checkExternSheet(sheetIndex); + FormulaShifter formulaShifter = FormulaShifter.createForRowShift( + externSheetIndex, sheetName, startRow, endRow, n, SpreadsheetVersion.EXCEL97); + // update formulas on this sheet that point to rows which have been moved + _sheet.updateFormulasAfterCellShift(formulaShifter, externSheetIndex); + + // update formulas on other sheets that point to rows that have been moved on this sheet + int nSheets = _workbook.getNumberOfSheets(); + for (int i = 0; i < nSheets; i++) { + InternalSheet otherSheet = _workbook.getSheetAt(i).getSheet(); + if (otherSheet == this._sheet) { + continue; + } + short otherExtSheetIx = _book.checkExternSheet(i); + otherSheet.updateFormulasAfterCellShift(formulaShifter, otherExtSheetIx); + } + _workbook.getWorkbook().updateNamesAfterCellShift(formulaShifter); + } + + private void recomputeFirstAndLastRowsForRowShift(int startRow, int endRow, int n) { if (n > 0) { // Rows are moving down if (startRow == _firstrow) { @@ -1696,26 +1705,36 @@ public final class HSSFSheet implements } } } + } - // Update any formulas on this sheet that point to - // rows which have been moved - int sheetIndex = _workbook.getSheetIndex(this); - String sheetName = _workbook.getSheetName(sheetIndex); - short externSheetIndex = _book.checkExternSheet(sheetIndex); - FormulaShifter shifter = FormulaShifter.createForRowShift( - externSheetIndex, sheetName, startRow, endRow, n, SpreadsheetVersion.EXCEL97); - _sheet.updateFormulasAfterCellShift(shifter, externSheetIndex); + private void deleteOverwrittenHyperlinksForRowShift(int startRow, int endRow, int n) { + final int firstOverwrittenRow = startRow + n; + final int lastOverwrittenRow = endRow + n; + for (HSSFHyperlink link : getHyperlinkList()) { + // If hyperlink is fully contained in the rows that will be overwritten, delete the hyperlink + final int firstRow = link.getFirstRow(); + final int lastRow = link.getLastRow(); + if (firstOverwrittenRow <= firstRow + && firstRow <= lastOverwrittenRow + && lastOverwrittenRow <= lastRow + && lastRow <= lastOverwrittenRow) { + removeHyperlink(link); + } + } + } - int nSheets = _workbook.getNumberOfSheets(); - for (int i = 0; i < nSheets; i++) { - InternalSheet otherSheet = _workbook.getSheetAt(i).getSheet(); - if (otherSheet == this._sheet) { + private void moveCommentsForRowShift(int startRow, int endRow, int n) { + final HSSFPatriarch patriarch = createDrawingPatriarch(); + for (final HSSFShape shape : patriarch.getChildren()) { + if (!(shape instanceof HSSFComment)) { continue; } - short otherExtSheetIx = _book.checkExternSheet(i); - otherSheet.updateFormulasAfterCellShift(shifter, otherExtSheetIx); + final HSSFComment comment = (HSSFComment) shape; + final int r = comment.getRow(); + if (startRow <= r && r <= endRow) { + comment.setRow(clip(r + n)); + } } - _workbook.getWorkbook().updateNamesAfterCellShift(shifter); } protected void insertChartRecords(List records) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org