ASF Bugzilla – Attachment 34042 Details for
Bug 59740
[PATCH] Sheet.shiftRows incorrectly shifts merged region on exists merged region
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch, tests and updated javadoc
patch.txt (text/plain), 6.99 KB, created by
Daniil Lopatin
on 2016-07-15 16:40:33 UTC
(
hide
)
Description:
patch, tests and updated javadoc
Filename:
MIME Type:
Creator:
Daniil Lopatin
Created:
2016-07-15 16:40:33 UTC
Size:
6.99 KB
patch
obsolete
>Index: src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (revision 1752837) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (working copy) >@@ -1509,7 +1509,8 @@ > * Code ensures that rows don't wrap around<p> > * > * Additionally shifts merged regions that are completely defined in these >- * rows (ie. merged 2 cells on a row to be shifted).<p> >+ * rows (ie. merged 2 cells on a row to be shifted). All merged regions are completely >+ * overlaid by shifting will be deleted.<p> > * > * TODO Might want to add bounds checking here > * >Index: src/java/org/apache/poi/ss/usermodel/Sheet.java >=================================================================== >--- src/java/org/apache/poi/ss/usermodel/Sheet.java (revision 1752837) >+++ src/java/org/apache/poi/ss/usermodel/Sheet.java (working copy) >@@ -696,7 +696,8 @@ > * > * <p> > * Additionally shifts merged regions that are completely defined in these >- * rows (ie. merged 2 cells on a row to be shifted). >+ * rows (ie. merged 2 cells on a row to be shifted). All merged regions are completely >+ * overlaid by shifting will be deleted. > * <p> > * @param startRow the row to start shifting > * @param endRow the row to end shifting >Index: src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java >=================================================================== >--- src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java (revision 1752837) >+++ src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java (working copy) >@@ -44,12 +44,13 @@ > } > > /** >- * Shifts, grows, or shrinks the merged regions due to a row shift >+ * Shifts, grows, or shrinks the merged regions due to a row shift. >+ * Merged regions are completely overlaid by shifting will be deleted. > * > * @param startRow the row to start shifting > * @param endRow the row to end shifting > * @param n the number of rows to shift >- * @return an array of affected merged regions >+ * @return an array of affected merged regions, doesn't contain deleted ones > */ > public List<CellRangeAddress> shiftMergedRegions(int startRow, int endRow, int n) { > List<CellRangeAddress> shiftedRegions = new ArrayList<CellRangeAddress>(); >@@ -59,6 +60,12 @@ > for (int i = 0; i < size; i++) { > CellRangeAddress merged = sheet.getMergedRegion(i); > >+ // remove merged region that overlaps shifting >+ if (startRow + n <= merged.getFirstRow() && endRow + n >= merged.getLastRow()) { >+ removedIndices.add(i); >+ continue; >+ } >+ > boolean inStart = (merged.getFirstRow() >= startRow || merged.getLastRow() >= startRow); > boolean inEnd = (merged.getFirstRow() <= endRow || merged.getLastRow() <= endRow); > >Index: src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (revision 1752837) >+++ src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (working copy) >@@ -996,7 +996,8 @@ > * > * <p> > * Additionally shifts merged regions that are completely defined in these >- * rows (ie. merged 2 cells on a row to be shifted). >+ * rows (ie. merged 2 cells on a row to be shifted). All merged regions are completely >+ * overlaid by shifting will be deleted. > * <p> > * @param startRow the row to start shifting > * @param endRow the row to end shifting >Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (revision 1752837) >+++ src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (working copy) >@@ -2913,7 +2913,8 @@ > * > * <p> > * Additionally shifts merged regions that are completely defined in these >- * rows (ie. merged 2 cells on a row to be shifted). >+ * rows (ie. merged 2 cells on a row to be shifted). All merged regions are completely >+ * overlaid by shifting will be deleted. > * <p> > * @param startRow the row to start shifting > * @param endRow the row to end shifting >Index: src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java >=================================================================== >--- src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java (revision 1752837) >+++ src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java (working copy) >@@ -634,7 +634,67 @@ > > wb.close(); > } >- >+ >+ @Test >+ public void shiftMergedRowsToMergedRowsUp() throws IOException { >+ Workbook wb = _testDataProvider.createWorkbook(); >+ Sheet sheet = wb.createSheet("test"); >+ >+ // populate sheet cells >+ for (int i = 0; i < 2; i++) { >+ Row row = sheet.createRow(i); >+ for (int j = 0; j < 5; j++) { >+ Cell cell = row.createCell(j); >+ cell.setCellValue(i + "x" + j); >+ } >+ } >+ >+ CellRangeAddress A1_E1 = new CellRangeAddress(0, 0, 0, 4); >+ CellRangeAddress A2_C2 = new CellRangeAddress(1, 1, 0, 2); >+ >+ sheet.addMergedRegion(A1_E1); >+ sheet.addMergedRegion(A2_C2); >+ >+ // A1:E1 should be removed >+ // A2:C2 will be A1:C1 >+ sheet.shiftRows(1, sheet.getLastRowNum(), -1); >+ >+ assertEquals(1, sheet.getNumMergedRegions()); >+ assertEquals(CellRangeAddress.valueOf("A1:C1"), sheet.getMergedRegion(0)); >+ >+ wb.close(); >+ } >+ >+ @Test >+ public void shiftMergedRowsToMergedRowsDown() throws IOException { >+ Workbook wb = _testDataProvider.createWorkbook(); >+ Sheet sheet = wb.createSheet("test"); >+ >+ // populate sheet cells >+ for (int i = 0; i < 2; i++) { >+ Row row = sheet.createRow(i); >+ for (int j = 0; j < 5; j++) { >+ Cell cell = row.createCell(j); >+ cell.setCellValue(i + "x" + j); >+ } >+ } >+ >+ CellRangeAddress A1_E1 = new CellRangeAddress(0, 0, 0, 4); >+ CellRangeAddress A2_C2 = new CellRangeAddress(1, 1, 0, 2); >+ >+ sheet.addMergedRegion(A1_E1); >+ sheet.addMergedRegion(A2_C2); >+ >+ // A1:E1 should be moved to A2:E2 >+ // A2:C2 will be removed >+ sheet.shiftRows(0, 0, 1); >+ >+ assertEquals(1, sheet.getNumMergedRegions()); >+ assertEquals(CellRangeAddress.valueOf("A2:E2"), sheet.getMergedRegion(0)); >+ >+ wb.close(); >+ } >+ > private void createHyperlink(CreationHelper helper, Cell cell, int linkType, String ref) { > cell.setCellValue(ref); > Hyperlink link = helper.createHyperlink(linkType);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 59740
:
33971
| 34042