Java Code Examples for org.apache.poi.ss.usermodel.CellStyle#getBorderBottom()

The following examples show how to use org.apache.poi.ss.usermodel.CellStyle#getBorderBottom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Borders4ReportTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that the borders for a given cell match the expected values.
 * This is complicated by the fact that POI will not always give a particular cell the borders that are seen in Excel
 * - neighbouring cells may override the values for the chosen cell.
 * I don't know how to tell which takes precedence, but the following works for the tests I've carried out.
 */
public static void assertBorder( Sheet sheet, int row, int col, short bottom, short left, short right, short top ) {
	
	Row curRow = sheet.getRow( row );
	Row prevRow = ( row > 0 ) ? sheet.getRow( row - 1 ) : null;
	Row nextRow = sheet.getRow( row + 1 );
	Cell cell = curRow.getCell(col);
	CellStyle style = cell.getCellStyle();
	
	Cell cellUp = ( prevRow == null ) ? null : prevRow.getCell( col );
	Cell cellDown = ( nextRow == null ) ? null : nextRow.getCell( col );
	Cell cellLeft = ( col == 0 ) ? null : curRow.getCell( col - 1 ); 
	Cell cellRight = curRow.getCell( col + 1 ); 
	
	CellStyle styleUp = ( cellUp == null ) ? null : cellUp.getCellStyle();
	CellStyle styleDown = ( cellDown == null ) ? null : cellDown.getCellStyle();
	CellStyle styleLeft = ( cellLeft == null ) ? null : cellLeft.getCellStyle();
	CellStyle styleRight = ( cellRight == null ) ? null : cellRight.getCellStyle();
	
	System.out.println( "style == " + style );
	System.out.println( "style == " + style );
	
	if( ( top != style.getBorderTop() ) && 
			( ( styleUp == null ) || ( top != styleUp.getBorderBottom() ) ) ) {
		assertEquals( top,    style.getBorderTop() );
	}
	if( ( bottom != style.getBorderBottom() ) && 
			( ( styleDown == null ) || ( bottom != styleDown.getBorderTop() ) ) ) {
		assertEquals( bottom, style.getBorderBottom() );
	}
	if( ( left != style.getBorderLeft() ) && 
			( ( styleLeft == null ) || ( left != styleLeft.getBorderRight() ) ) ) {
		assertEquals( left,   style.getBorderLeft() );
	}
	if( ( right != style.getBorderRight() ) && 
			( ( styleRight == null ) || ( right != styleRight.getBorderLeft() ) ) ) {
		assertEquals( right,  style.getBorderRight() );
	}
}
 
Example 2
Source File: Borders2ReportTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that the borders for a given cell match the expected values.
 * This is complicated by the fact that POI will not always give a particular cell the borders that are seen in Excel
 * - neighbouring cells may override the values for the chosen cell.
 * I don't know how to tell which takes precedence, but the following works for the tests I've carried out.
 */
public static void assertBorder( Sheet sheet, int row, int col, short bottom, short left, short right, short top ) {
	
	Row curRow = sheet.getRow( row );
	Row prevRow = ( row > 0 ) ? sheet.getRow( row - 1 ) : null;
	Row nextRow = sheet.getRow( row + 1 );
	Cell cell = curRow.getCell(col);
	CellStyle style = cell.getCellStyle();
	
	Cell cellUp = ( prevRow == null ) ? null : prevRow.getCell( col );
	Cell cellDown = ( nextRow == null ) ? null : nextRow.getCell( col );
	Cell cellLeft = ( col == 0 ) ? null : curRow.getCell( col - 1 ); 
	Cell cellRight = curRow.getCell( col + 1 ); 
	
	CellStyle styleUp = ( cellUp == null ) ? null : cellUp.getCellStyle();
	CellStyle styleDown = ( cellDown == null ) ? null : cellDown.getCellStyle();
	CellStyle styleLeft = ( cellLeft == null ) ? null : cellLeft.getCellStyle();
	CellStyle styleRight = ( cellRight == null ) ? null : cellRight.getCellStyle();
	
	System.out.println( "style == " + style );
	System.out.println( "style == " + style );
	
	if( ( top != style.getBorderTop() ) && 
			( ( styleUp == null ) || ( top != styleUp.getBorderBottom() ) ) ) {
		assertEquals( top,    style.getBorderTop() );
	}
	if( ( bottom != style.getBorderBottom() ) && 
			( ( styleDown == null ) || ( bottom != styleDown.getBorderTop() ) ) ) {
		assertEquals( bottom, style.getBorderBottom() );
	}
	if( ( left != style.getBorderLeft() ) && 
			( ( styleLeft == null ) || ( left != styleLeft.getBorderRight() ) ) ) {
		assertEquals( left,   style.getBorderLeft() );
	}
	if( ( right != style.getBorderRight() ) && 
			( ( styleRight == null ) || ( right != styleRight.getBorderLeft() ) ) ) {
		assertEquals( right,  style.getBorderRight() );
	}
}