ASF Bugzilla – Attachment 3377 Details for
Bug 13332
[Patch] Ability to shift rows
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Updated patch file.
patch.txt (text/plain), 15.78 KB, created by
Shawn Laubach
on 2002-10-07 16:04:07 UTC
(
hide
)
Description:
Updated patch file.
Filename:
MIME Type:
Creator:
Shawn Laubach
Created:
2002-10-07 16:04:07 UTC
Size:
15.78 KB
patch
obsolete
>? tools/cents/forrest.cent/legal >? tools/cents/forrest.cent/tasks.properties >? tools/cents/forrest.cent/xbuild.xml >? tools/cents/forrest.cent/conf/cocoon.xconf >? tools/cents/forrest.cent/conf/sitemap.xmap >? tools/cents/forrest.cent/lib/avalon-excalibur-4.1.jar >? tools/cents/forrest.cent/lib/avalon-framework-4.1.2.jar >? tools/cents/forrest.cent/lib/avalon-scratchpad-20020212.jar >? tools/cents/forrest.cent/lib/cocoon-scratchpad-part.jar >? tools/cents/forrest.cent/lib/cocoon.jar >? tools/cents/forrest.cent/lib/commons-collections-1.0.jar >? tools/cents/forrest.cent/lib/commons-httpclient-20011012.jar >? tools/cents/forrest.cent/lib/jakarta-regexp-1.2.jar >? tools/cents/forrest.cent/lib/logkit-1.0.1.jar >? tools/cents/forrest.cent/lib/resolver-20020130.jar >? tools/cents/forrest.cent/resources/library/xslt/changes2document.xsl >? tools/cents/forrest.cent/resources/library/xslt/copyover.xsl >? tools/cents/forrest.cent/resources/library/xslt/doclist.xsl >? tools/cents/forrest.cent/resources/library/xslt/doclist2document.xsl >? tools/cents/forrest.cent/resources/library/xslt/faq2document.xsl >? tools/cents/forrest.cent/resources/library/xslt/filterlinks.xsl >? tools/cents/forrest.cent/resources/library/xslt/todo2document.xsl >? tools/cents/forrest.cent/resources/resources/images >? tools/cents/forrest.cent/resources/resources/schema/CatalogManager.properties >? tools/cents/forrest.cent/resources/resources/schema/README >? tools/cents/forrest.cent/resources/resources/schema/catalog >? tools/cents/forrest.cent/resources/resources/schema/catalog.xcat >? tools/cents/forrest.cent/resources/resources/schema/dtd/book-cocoon-v10.dtd >? tools/cents/forrest.cent/resources/resources/schema/dtd/changes-v11.dtd >? tools/cents/forrest.cent/resources/resources/schema/dtd/document-v11.dtd >? tools/cents/forrest.cent/resources/resources/schema/dtd/faq-v11.dtd >? tools/cents/forrest.cent/resources/resources/schema/dtd/javadoc-v04draft.dtd >? tools/cents/forrest.cent/resources/resources/schema/dtd/project.dtd >? tools/cents/forrest.cent/resources/resources/schema/dtd/specification-v11.dtd >? tools/cents/forrest.cent/resources/resources/schema/dtd/todo-v11.dtd >? tools/cents/forrest.cent/resources/resources/schema/dtd/xgump.dtd >? tools/cents/forrest.cent/resources/resources/schema/entity/ISOdia.pen >? tools/cents/forrest.cent/resources/resources/schema/entity/ISOgrk1.pen >? tools/cents/forrest.cent/resources/resources/schema/entity/ISOlat1.pen >? tools/cents/forrest.cent/resources/resources/schema/entity/ISOnum.pen >? tools/cents/forrest.cent/resources/resources/schema/entity/ISOpub.pen >? tools/cents/forrest.cent/resources/resources/schema/entity/ISOtech.pen >? tools/cents/forrest.cent/resources/skins/avalon-site >? tools/cents/forrest.cent/resources/skins/basic >? tools/cents/forrest.cent/resources/skins/forrest-site >? tools/cents/forrest.cent/resources/skins/scarab-site2 >? tools/cents/forrest.cent/resources/skins/xml-apache-site >? tools/cents/forrest.cent/resources/skins/jakarta-site/images/add.jpg >? tools/cents/forrest.cent/resources/skins/jakarta-site/images/ant_logo_medium.gif >? tools/cents/forrest.cent/resources/skins/jakarta-site/images/built-with-cocoon.gif >? tools/cents/forrest.cent/resources/skins/jakarta-site/images/favicon.ico >? tools/cents/forrest.cent/resources/skins/jakarta-site/images/krysalis-compatible.jpg >? tools/cents/forrest.cent/resources/skins/jakarta-site/images/note.gif >? tools/cents/forrest.cent/resources/skins/jakarta-site/images/remove.jpg >? tools/cents/forrest.cent/resources/skins/jakarta-site/images/update.jpg >? tools/cents/forrest.cent/resources/skins/jakarta-site/images/void.gif >? tools/cents/forrest.cent/resources/skins/jakarta-site/xslt/html/book2menu.xsl >? tools/cents/forrest.cent/resources/skins/jakarta-site/xslt/html/document2html.xsl >? tools/cents/forrest.cent/resources/skins/jakarta-site/xslt/html/site2xhtml.xsl >? tools/cents/forrest.cent/resources/skins/scarab-site/css/compact.css >? tools/cents/forrest.cent/resources/skins/scarab-site/css/main.css >? tools/cents/forrest.cent/resources/skins/scarab-site/css/ns4_toxins.css >? tools/cents/forrest.cent/resources/skins/scarab-site/css/print.css >? tools/cents/forrest.cent/resources/skins/scarab-site/images/add.jpg >? tools/cents/forrest.cent/resources/skins/scarab-site/images/ant_logo_medium.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/built-with-cocoon.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/favicon.ico >? tools/cents/forrest.cent/resources/skins/scarab-site/images/grn_alert.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_alert.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_alertsml.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_confirmsml.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_downarrow.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_downarrow_off.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_downarrow_on.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_help.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_infosml.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_uparrow.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_uparrow_off.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/icon_uparrow_on.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/krysalis-compatible.jpg >? tools/cents/forrest.cent/resources/skins/scarab-site/images/note.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/nw_min.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/remove.jpg >? tools/cents/forrest.cent/resources/skins/scarab-site/images/se_min.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/seperator.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/seperator2.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/seperator3.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/strich.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/sw_min.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/up_pointer.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/images/update.jpg >? tools/cents/forrest.cent/resources/skins/scarab-site/images/void.gif >? tools/cents/forrest.cent/resources/skins/scarab-site/xslt/html/book2menu.xsl >? tools/cents/forrest.cent/resources/skins/scarab-site/xslt/html/document2html.xsl >? tools/cents/forrest.cent/resources/skins/scarab-site/xslt/html/site2xhtml.xsl >? tools/cents/junit.cent/legal >? tools/cents/junit.cent/lib >? tools/cents/junit.cent/tasks.properties >? tools/cents/junit.cent/xbuild.xml >Index: src/documentation/xdocs/hssf/quick-guide.xml >=================================================================== >RCS file: /home/cvs/jakarta-poi/src/documentation/xdocs/hssf/quick-guide.xml,v >retrieving revision 1.9 >diff -u -r1.9 quick-guide.xml >--- src/documentation/xdocs/hssf/quick-guide.xml 30 Sep 2002 23:20:54 -0000 1.9 >+++ src/documentation/xdocs/hssf/quick-guide.xml 7 Oct 2002 15:28:49 -0000 >@@ -32,6 +32,7 @@ > <li><link href="#DataFormats">Create user defined data formats.</link></li> > <li><link href="#PrintArea">Set print area for a sheet.</link></li> > <li><link href="#FooterPageNumbers">Set page numbers on the footer of a sheet.</link></li> >+ <li><link href="#ShiftRows">Shift rows.</link></li> > </ul> > </section> > <section title="Features"> >@@ -446,6 +447,23 @@ > fileOut.close(); > </source> > </section> >+ >+ <anchor id="ShiftRows"/> >+ <section title="Shift rows up or down on a sheet"> >+ <source> >+ HSSFWorkbook wb = new HSSFWorkbook(); >+ HSSFSheet sheet = wb.createSheet("row sheet"); >+ >+ // Create various cells and rows for spreadsheet. >+ >+ // Shift rows 6 - 11 on the spreadsheet to the top (rows 0 - 5) >+ sheet.shiftRows(5, 10, -5); >+ >+ FileOutputStream fileOut = new FileOutputStream("workbook.xls"); >+ wb.write(fileOut); >+ fileOut.close(); >+ </source> >+ </section> > </section> > </section> > </body> >Index: src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java >=================================================================== >RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java,v >retrieving revision 1.13 >diff -u -r1.13 HSSFSheet.java >--- src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java 5 Oct 2002 02:38:07 -0000 1.13 >+++ src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java 7 Oct 2002 15:28:50 -0000 >@@ -829,4 +829,51 @@ > public void setMargin(short margin, double size) { > getSheet().setMargin(margin, size); > } >+ >+ /** >+ * Shifts rows between startRow and endRow n number of rows. >+ * If you use a negative number, it will shift rows up. >+ * Code ensures that rows don't wrap around >+ * >+ * @param startRow the row to start shifting >+ * @param endRow the row to end shifting >+ * @param n the number of rows to shift >+ */ >+ public void shiftRows(int startRow, int endRow, int n) { >+ int s, e, inc; >+ if (n < 0) { >+ s = startRow; >+ e = endRow; >+ inc = 1; >+ } else { >+ s = endRow; >+ e = startRow; >+ inc = -1; >+ } >+ for (int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum+=inc) { >+ HSSFRow row = getRow(rowNum); >+ HSSFRow row2Replace = getRow(rowNum + n); >+ if (row2Replace == null) >+ row2Replace = createRow(rowNum + n); >+ >+ HSSFCell cell; >+ for (short col = row2Replace.getFirstCellNum(); col <= row2Replace.getLastCellNum(); col++) { >+ cell = row2Replace.getCell(col); >+ if (cell != null) >+ row2Replace.removeCell(cell); >+ } >+ for (short col = row.getFirstCellNum(); col <= row.getLastCellNum(); col++) { >+ cell = row.getCell(col); >+ if (cell != null) { >+ row.removeCell(cell); >+ CellValueRecordInterface cellRecord = cell.getCellValueRecord(); >+ cellRecord.setRow(rowNum + n); >+ row2Replace.createCellFromRecord(cellRecord); >+ sheet.addValueRecord(rowNum + n, cellRecord); >+ } >+ } >+ } >+ if (endRow == lastrow || endRow + n > lastrow) lastrow = Math.min(endRow + n, 65535); >+ if (startRow == firstrow || startRow + n < firstrow) firstrow = Math.max(startRow + n, 0); >+ } > } >Index: src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java >=================================================================== >RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java,v >retrieving revision 1.6 >diff -u -r1.6 TestHSSFSheet.java >--- src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java 5 Sep 2002 00:26:28 -0000 1.6 >+++ src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java 7 Oct 2002 15:28:54 -0000 >@@ -199,20 +199,101 @@ > sheet.removeRow(row); > } > >- public void testCloneSheet() { >- HSSFWorkbook workbook = new HSSFWorkbook(); >- HSSFSheet sheet = workbook.createSheet("Test Clone"); >- HSSFRow row = sheet.createRow((short) 0); >- HSSFCell cell = row.createCell((short) 0); >- cell.setCellValue("clone_test"); >- HSSFSheet cloned = workbook.cloneSheet(0); >- >- //Check for a good clone >- assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test"); >- >- //Check that the cells are not somehow linked >- cell.setCellValue("Difference Check"); >- assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test"); >- } >- >+ public void testCloneSheet() { >+ HSSFWorkbook workbook = new HSSFWorkbook(); >+ HSSFSheet sheet = workbook.createSheet("Test Clone"); >+ HSSFRow row = sheet.createRow((short) 0); >+ HSSFCell cell = row.createCell((short) 0); >+ cell.setCellValue("clone_test"); >+ HSSFSheet cloned = workbook.cloneSheet(0); >+ >+ //Check for a good clone >+ assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test"); >+ >+ //Check that the cells are not somehow linked >+ cell.setCellValue("Difference Check"); >+ assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test"); >+ } >+ >+ /** >+ * Tests the shiftRows function. Does three different shifts. >+ * After each shift, writes the workbook to file and reads back to >+ * check. This ensures that if some changes code that breaks >+ * writing or what not, they realize it. >+ * >+ * Shawn Laubach (slaubach at apache dot org) >+ */ >+ public void testShiftRows() throws Exception { >+ // Read initial file in >+ String filename = System.getProperty("HSSF.testdata.path"); >+ filename = filename + "/SimpleMultiCell.xls"; >+ FileInputStream fin = new FileInputStream(filename); >+ HSSFWorkbook wb = new HSSFWorkbook(fin); >+ fin.close(); >+ HSSFSheet s = wb.getSheetAt(0); >+ >+ // Shift the second row down 1 and write to temp file >+ s.shiftRows(1, 1, 1); >+ File tempFile = File.createTempFile("shift", "test.xls"); >+ FileOutputStream fout = new FileOutputStream(tempFile); >+ wb.write(fout); >+ fout.close(); >+ >+ // Read from temp file and check the number of cells in each >+ // row (in original file each row was unique) >+ fin = new FileInputStream(tempFile); >+ wb = new HSSFWorkbook(fin); >+ fin.close(); >+ s = wb.getSheetAt(0); >+ >+ assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 1); >+ assertTrue(s.getRow(1) == null || s.getRow(1).getPhysicalNumberOfCells() == 0); >+ assertEquals(s.getRow(2).getPhysicalNumberOfCells(), 2); >+ assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 4); >+ assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5); >+ >+ // Shift rows 1-3 down 3 in the current one. This tests when >+ // 1 row is blank. Write to a another temp file >+ s.shiftRows(0, 2, 3); >+ tempFile = File.createTempFile("shift", "test.xls"); >+ fout = new FileOutputStream(tempFile); >+ wb.write(fout); >+ fout.close(); >+ >+ // Read and ensure things are where they should be >+ fin = new FileInputStream(tempFile); >+ wb = new HSSFWorkbook(fin); >+ fin.close(); >+ s = wb.getSheetAt(0); >+ assertTrue(s.getRow(0) == null || s.getRow(0).getPhysicalNumberOfCells() == 0); >+ assertTrue(s.getRow(1) == null || s.getRow(1).getPhysicalNumberOfCells() == 0); >+ assertTrue(s.getRow(2) == null || s.getRow(2).getPhysicalNumberOfCells() == 0); >+ assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 1); >+ assertTrue(s.getRow(4) == null || s.getRow(4).getPhysicalNumberOfCells() == 0); >+ assertEquals(s.getRow(5).getPhysicalNumberOfCells(), 2); >+ >+ // Read the first file again >+ fin = new FileInputStream(filename); >+ wb = new HSSFWorkbook(fin); >+ fin.close(); >+ s = wb.getSheetAt(0); >+ >+ // Shift rows 3 and 4 up and write to temp file >+ s.shiftRows(2, 3, -2); >+ tempFile = File.createTempFile("shift", "test.xls"); >+ fout = new FileOutputStream(tempFile); >+ wb.write(fout); >+ fout.close(); >+ >+ // Read file and test >+ fin = new FileInputStream(tempFile); >+ wb = new HSSFWorkbook(fin); >+ fin.close(); >+ s = wb.getSheetAt(0); >+ assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 3); >+ assertEquals(s.getRow(1).getPhysicalNumberOfCells(), 4); >+ assertTrue(s.getRow(2) == null || s.getRow(2).getPhysicalNumberOfCells() == 0); >+ assertTrue(s.getRow(3) == null || s.getRow(3).getPhysicalNumberOfCells() == 0); >+ assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5); >+ } > }
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 13332
:
3362
| 3377