Some reformatting only.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352965 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6d73597035
commit
04e78aae67
@ -223,77 +223,78 @@ public class TestHSSFSheet
|
|||||||
*
|
*
|
||||||
* Shawn Laubach (slaubach at apache dot org)
|
* Shawn Laubach (slaubach at apache dot org)
|
||||||
*/
|
*/
|
||||||
public void testShiftRows() throws Exception {
|
public void testShiftRows() throws Exception
|
||||||
|
{
|
||||||
// Read initial file in
|
// Read initial file in
|
||||||
String filename = System.getProperty("HSSF.testdata.path");
|
String filename = System.getProperty( "HSSF.testdata.path" );
|
||||||
filename = filename + "/SimpleMultiCell.xls";
|
filename = filename + "/SimpleMultiCell.xls";
|
||||||
FileInputStream fin = new FileInputStream(filename);
|
FileInputStream fin = new FileInputStream( filename );
|
||||||
HSSFWorkbook wb = new HSSFWorkbook(fin);
|
HSSFWorkbook wb = new HSSFWorkbook( fin );
|
||||||
fin.close();
|
fin.close();
|
||||||
HSSFSheet s = wb.getSheetAt(0);
|
HSSFSheet s = wb.getSheetAt( 0 );
|
||||||
|
|
||||||
// Shift the second row down 1 and write to temp file
|
// Shift the second row down 1 and write to temp file
|
||||||
s.shiftRows(1, 1, 1);
|
s.shiftRows( 1, 1, 1 );
|
||||||
File tempFile = File.createTempFile("shift", "test.xls");
|
File tempFile = File.createTempFile( "shift", "test.xls" );
|
||||||
FileOutputStream fout = new FileOutputStream(tempFile);
|
FileOutputStream fout = new FileOutputStream( tempFile );
|
||||||
wb.write(fout);
|
wb.write( fout );
|
||||||
fout.close();
|
fout.close();
|
||||||
|
|
||||||
// Read from temp file and check the number of cells in each
|
// Read from temp file and check the number of cells in each
|
||||||
// row (in original file each row was unique)
|
// row (in original file each row was unique)
|
||||||
fin = new FileInputStream(tempFile);
|
fin = new FileInputStream( tempFile );
|
||||||
wb = new HSSFWorkbook(fin);
|
wb = new HSSFWorkbook( fin );
|
||||||
fin.close();
|
fin.close();
|
||||||
s = wb.getSheetAt(0);
|
s = wb.getSheetAt( 0 );
|
||||||
|
|
||||||
assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 1);
|
assertEquals( s.getRow( 0 ).getPhysicalNumberOfCells(), 1 );
|
||||||
assertTrue(s.getRow(1) == null || s.getRow(1).getPhysicalNumberOfCells() == 0);
|
assertTrue( s.getRow( 1 ) == null || s.getRow( 1 ).getPhysicalNumberOfCells() == 0 );
|
||||||
assertEquals(s.getRow(2).getPhysicalNumberOfCells(), 2);
|
assertEquals( s.getRow( 2 ).getPhysicalNumberOfCells(), 2 );
|
||||||
assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 4);
|
assertEquals( s.getRow( 3 ).getPhysicalNumberOfCells(), 4 );
|
||||||
assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5);
|
assertEquals( s.getRow( 4 ).getPhysicalNumberOfCells(), 5 );
|
||||||
|
|
||||||
// Shift rows 1-3 down 3 in the current one. This tests when
|
// Shift rows 1-3 down 3 in the current one. This tests when
|
||||||
// 1 row is blank. Write to a another temp file
|
// 1 row is blank. Write to a another temp file
|
||||||
s.shiftRows(0, 2, 3);
|
s.shiftRows( 0, 2, 3 );
|
||||||
tempFile = File.createTempFile("shift", "test.xls");
|
tempFile = File.createTempFile( "shift", "test.xls" );
|
||||||
fout = new FileOutputStream(tempFile);
|
fout = new FileOutputStream( tempFile );
|
||||||
wb.write(fout);
|
wb.write( fout );
|
||||||
fout.close();
|
fout.close();
|
||||||
|
|
||||||
// Read and ensure things are where they should be
|
// Read and ensure things are where they should be
|
||||||
fin = new FileInputStream(tempFile);
|
fin = new FileInputStream( tempFile );
|
||||||
wb = new HSSFWorkbook(fin);
|
wb = new HSSFWorkbook( fin );
|
||||||
fin.close();
|
fin.close();
|
||||||
s = wb.getSheetAt(0);
|
s = wb.getSheetAt( 0 );
|
||||||
assertTrue(s.getRow(0) == null || s.getRow(0).getPhysicalNumberOfCells() == 0);
|
assertTrue( s.getRow( 0 ) == null || s.getRow( 0 ).getPhysicalNumberOfCells() == 0 );
|
||||||
assertTrue(s.getRow(1) == null || s.getRow(1).getPhysicalNumberOfCells() == 0);
|
assertTrue( s.getRow( 1 ) == null || s.getRow( 1 ).getPhysicalNumberOfCells() == 0 );
|
||||||
assertTrue(s.getRow(2) == null || s.getRow(2).getPhysicalNumberOfCells() == 0);
|
assertTrue( s.getRow( 2 ) == null || s.getRow( 2 ).getPhysicalNumberOfCells() == 0 );
|
||||||
assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 1);
|
assertEquals( s.getRow( 3 ).getPhysicalNumberOfCells(), 1 );
|
||||||
assertTrue(s.getRow(4) == null || s.getRow(4).getPhysicalNumberOfCells() == 0);
|
assertTrue( s.getRow( 4 ) == null || s.getRow( 4 ).getPhysicalNumberOfCells() == 0 );
|
||||||
assertEquals(s.getRow(5).getPhysicalNumberOfCells(), 2);
|
assertEquals( s.getRow( 5 ).getPhysicalNumberOfCells(), 2 );
|
||||||
|
|
||||||
// Read the first file again
|
// Read the first file again
|
||||||
fin = new FileInputStream(filename);
|
fin = new FileInputStream( filename );
|
||||||
wb = new HSSFWorkbook(fin);
|
wb = new HSSFWorkbook( fin );
|
||||||
fin.close();
|
fin.close();
|
||||||
s = wb.getSheetAt(0);
|
s = wb.getSheetAt( 0 );
|
||||||
|
|
||||||
// Shift rows 3 and 4 up and write to temp file
|
// Shift rows 3 and 4 up and write to temp file
|
||||||
s.shiftRows(2, 3, -2);
|
s.shiftRows( 2, 3, -2 );
|
||||||
tempFile = File.createTempFile("shift", "test.xls");
|
tempFile = File.createTempFile( "shift", "test.xls" );
|
||||||
fout = new FileOutputStream(tempFile);
|
fout = new FileOutputStream( tempFile );
|
||||||
wb.write(fout);
|
wb.write( fout );
|
||||||
fout.close();
|
fout.close();
|
||||||
|
|
||||||
// Read file and test
|
// Read file and test
|
||||||
fin = new FileInputStream(tempFile);
|
fin = new FileInputStream( tempFile );
|
||||||
wb = new HSSFWorkbook(fin);
|
wb = new HSSFWorkbook( fin );
|
||||||
fin.close();
|
fin.close();
|
||||||
s = wb.getSheetAt(0);
|
s = wb.getSheetAt( 0 );
|
||||||
assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 3);
|
assertEquals( s.getRow( 0 ).getPhysicalNumberOfCells(), 3 );
|
||||||
assertEquals(s.getRow(1).getPhysicalNumberOfCells(), 4);
|
assertEquals( s.getRow( 1 ).getPhysicalNumberOfCells(), 4 );
|
||||||
assertTrue(s.getRow(2) == null || s.getRow(2).getPhysicalNumberOfCells() == 0);
|
assertTrue( s.getRow( 2 ) == null || s.getRow( 2 ).getPhysicalNumberOfCells() == 0 );
|
||||||
assertTrue(s.getRow(3) == null || s.getRow(3).getPhysicalNumberOfCells() == 0);
|
assertTrue( s.getRow( 3 ) == null || s.getRow( 3 ).getPhysicalNumberOfCells() == 0 );
|
||||||
assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5);
|
assertEquals( s.getRow( 4 ).getPhysicalNumberOfCells(), 5 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user