Java Code Examples for org.apache.poi.xssf.usermodel.XSSFCellStyle#setBorderBottom()

The following examples show how to use org.apache.poi.xssf.usermodel.XSSFCellStyle#setBorderBottom() . 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: ExcelUtils.java    From mySpringBoot with Apache License 2.0 5 votes vote down vote up
/**
 * 设置边框
 *
 * @param style
 * @param border
 * @param color
 */
private static void setBorder(XSSFCellStyle style, BorderStyle border, XSSFColor color) {
    style.setBorderTop(border);
    style.setBorderLeft(border);
    style.setBorderRight(border);
    style.setBorderBottom(border);
    style.setBorderColor(BorderSide.TOP, color);
    style.setBorderColor(BorderSide.LEFT, color);
    style.setBorderColor(BorderSide.RIGHT, color);
    style.setBorderColor(BorderSide.BOTTOM, color);
}
 
Example 2
Source File: FileUtil.java    From JavaWeb with Apache License 2.0 5 votes vote down vote up
public static XSSFCellStyle setStyle(XSSFWorkbook workbook) {  
    //设置字体;  
    XSSFFont font = workbook.createFont();  
    //设置字体大小;  
    font.setFontHeightInPoints((short) 20);  
    //设置字体名字;  
    font.setFontName("Courier New");  
    //font.setItalic(true);  
    //font.setStrikeout(true);  
    //设置样式;  
    XSSFCellStyle style = workbook.createCellStyle();  
    //设置底边框;  
    style.setBorderBottom(XSSFCellStyle.BORDER_THIN);  
    //设置底边框颜色;  
    style.setBottomBorderColor(new XSSFColor(Color.BLACK));  
    //设置左边框;  
    style.setBorderLeft(XSSFCellStyle.BORDER_THIN);  
    //设置左边框颜色;  
    style.setLeftBorderColor(new XSSFColor(Color.BLACK));  
    //设置右边框;  
    style.setBorderRight(XSSFCellStyle.BORDER_THIN);  
    //设置右边框颜色;  
    style.setRightBorderColor(new XSSFColor(Color.BLACK));  
    //设置顶边框;  
    style.setBorderTop(XSSFCellStyle.BORDER_THIN);  
    //设置顶边框颜色;  
    style.setTopBorderColor(new XSSFColor(Color.BLACK));  
    //在样式用应用设置的字体;  
    style.setFont(font);  
    //设置自动换行;  
    style.setWrapText(false);  
    //设置水平对齐的样式为居中对齐;  
    style.setAlignment(XSSFCellStyle.ALIGN_CENTER);  
    //设置垂直对齐的样式为居中对齐;  
    style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);  
    return style;  
}
 
Example 3
Source File: FileUtil.java    From JavaWeb with Apache License 2.0 5 votes vote down vote up
public static XSSFCellStyle setStyle(XSSFWorkbook workbook) {  
    //设置字体;  
    XSSFFont font = workbook.createFont();  
    //设置字体大小;  
    font.setFontHeightInPoints((short) 20);  
    //设置字体名字;  
    font.setFontName("Courier New");  
    //font.setItalic(true);  
    //font.setStrikeout(true);  
    //设置样式;  
    XSSFCellStyle style = workbook.createCellStyle();  
    //设置底边框;  
    style.setBorderBottom(XSSFCellStyle.BORDER_THIN);  
    //设置底边框颜色;  
    style.setBottomBorderColor(new XSSFColor(Color.BLACK));  
    //设置左边框;  
    style.setBorderLeft(XSSFCellStyle.BORDER_THIN);  
    //设置左边框颜色;  
    style.setLeftBorderColor(new XSSFColor(Color.BLACK));  
    //设置右边框;  
    style.setBorderRight(XSSFCellStyle.BORDER_THIN);  
    //设置右边框颜色;  
    style.setRightBorderColor(new XSSFColor(Color.BLACK));  
    //设置顶边框;  
    style.setBorderTop(XSSFCellStyle.BORDER_THIN);  
    //设置顶边框颜色;  
    style.setTopBorderColor(new XSSFColor(Color.BLACK));  
    //在样式用应用设置的字体;  
    style.setFont(font);  
    //设置自动换行;  
    style.setWrapText(false);  
    //设置水平对齐的样式为居中对齐;  
    style.setAlignment(XSSFCellStyle.ALIGN_CENTER);  
    //设置垂直对齐的样式为居中对齐;  
    style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);  
    return style;  
}
 
Example 4
Source File: StyleManagerXUtils.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void applyBorderStyle(Workbook workbook, CellStyle style, BorderSide side, CSSValue colour, CSSValue borderStyle, CSSValue width) {
	if( ( colour != null ) || ( borderStyle != null ) || ( width != null ) ) {
		String colourString = colour == null ? "rgb(0,0,0)" : colour.getCssText();
		String borderStyleString = borderStyle == null ? "solid" : borderStyle.getCssText();
		String widthString = width == null ? "medium" : width.getCssText();
		
		if( style instanceof XSSFCellStyle ) {
			XSSFCellStyle xStyle = (XSSFCellStyle)style;
			
			BorderStyle xBorderStyle = poiBorderStyleFromBirt(borderStyleString, widthString);
			XSSFColor xBorderColour = getXColour(colourString);
			if(xBorderStyle != BorderStyle.NONE) {
				switch( side ) {
				case TOP:
					xStyle.setBorderTop(xBorderStyle);
					xStyle.setTopBorderColor(xBorderColour);
					// log.debug( "Top border: " + xStyle.getBorderTop() + " / " + xStyle.getTopBorderXSSFColor().getARGBHex() );
					break;
				case LEFT:
					xStyle.setBorderLeft(xBorderStyle);
					xStyle.setLeftBorderColor(xBorderColour);
					// log.debug( "Left border: " + xStyle.getBorderLeft() + " / " + xStyle.getLeftBorderXSSFColor().getARGBHex() );
					break;
				case RIGHT:
					xStyle.setBorderRight(xBorderStyle);
					xStyle.setRightBorderColor(xBorderColour);
					// log.debug( "Right border: " + xStyle.getBorderRight() + " / " + xStyle.getRightBorderXSSFColor().getARGBHex() );
					break;
				case BOTTOM:
					xStyle.setBorderBottom(xBorderStyle);
					xStyle.setBottomBorderColor(xBorderColour);
					// log.debug( "Bottom border: " + xStyle.getBorderBottom() + " / " + xStyle.getBottomBorderXSSFColor().getARGBHex() );
					break;
				}
			}
		}
	}
}
 
Example 5
Source File: PdcaReportExcelCommand.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
private int createPdcaItem(XSSFWorkbook wb, XSSFSheet sh, int row, XSSFCellStyle cellNormalStyle, List<PdcaItemVO> items, PdcaAuditVO audit) throws Exception {
	
	XSSFColor fnColor = new XSSFColor( SimpleUtils.getColorRGB4POIColor("#000000"), null );		
	XSSFColor bgLabelColor = new XSSFColor( SimpleUtils.getColorRGB4POIColor("#F2F2F2"), null );
	
	XSSFCellStyle cellLabelStyle = wb.createCellStyle();
	cellLabelStyle.setFillForegroundColor( bgLabelColor );
	cellLabelStyle.setFillPattern( FillPatternType.SOLID_FOREGROUND );				
	
	XSSFFont cellLabelFont = wb.createFont();
	cellLabelFont.setBold(true);
	cellLabelFont.setColor(fnColor);
	cellLabelStyle.setFont(cellLabelFont);		
	cellLabelStyle.setBorderBottom(BorderStyle.THIN);
	cellLabelStyle.setBorderTop(BorderStyle.THIN);
	cellLabelStyle.setBorderRight(BorderStyle.THIN);
	cellLabelStyle.setBorderLeft(BorderStyle.THIN);
	cellLabelStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	cellLabelStyle.setAlignment(HorizontalAlignment.CENTER);
	cellLabelStyle.setWrapText(true);			
	
	Map<String, String> pdcaTypeMap = PdcaType.getDataMap(false);
	
	for (PdcaItemVO item : items) {
		
		Row labelRow = sh.createRow(row);
		Cell labelCell_6_1 = labelRow.createCell(0);	
		labelCell_6_1.setCellValue( pdcaTypeMap.get(item.getType()) );
		labelCell_6_1.setCellStyle(cellLabelStyle);				
		
		Cell labelCell_6_2 = labelRow.createCell(1);	
		labelCell_6_2.setCellValue( item.getTitle() + ( !StringUtils.isBlank(item.getDescription()) ? "\n\n" + item.getDescription() : "" ) );
		labelCell_6_2.setCellStyle(cellNormalStyle);	
		
		Cell labelCell_6_3 = labelRow.createCell(2);	
		labelCell_6_3.setCellValue( item.getEmployeeAppendNames() );
		labelCell_6_3.setCellStyle(cellNormalStyle);
		
		Cell labelCell_6_4 = labelRow.createCell(3);	
		labelCell_6_4.setCellValue( item.getStartDateDisplayValue() + " ~ " + item.getEndDateDisplayValue() );
		labelCell_6_4.setCellStyle(cellNormalStyle);	
		
		Cell labelCell_6_5 = labelRow.createCell(4);	
		labelCell_6_5.setCellValue( (audit != null ? audit.getEmpId() : " ") );
		labelCell_6_5.setCellStyle(cellNormalStyle);	
		
		Cell labelCell_6_6 = labelRow.createCell(5);	
		labelCell_6_6.setCellValue( (audit != null ? audit.getConfirmDateDisplayValue() : " ") );
		labelCell_6_6.setCellStyle(cellNormalStyle);
		
		
		row++;
		
	}
	
	return row;
}
 
Example 6
Source File: KpiPeriodTrendsExcelCommand.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void putTables(XSSFWorkbook wb, XSSFSheet sh, Context context) throws Exception {
	
	XSSFCellStyle cellHeadStyle = wb.createCellStyle();
	cellHeadStyle.setFillForegroundColor( new XSSFColor( SimpleUtils.getColorRGB4POIColor( "#f5f5f5" ), null ) );
	cellHeadStyle.setFillPattern( FillPatternType.SOLID_FOREGROUND );	
	cellHeadStyle.setBorderBottom( BorderStyle.THIN );
	cellHeadStyle.setBorderTop( BorderStyle.THIN );
	cellHeadStyle.setBorderRight( BorderStyle.THIN );
	cellHeadStyle.setBorderLeft( BorderStyle.THIN );		
	XSSFFont cellHeadFont = wb.createFont();
	cellHeadFont.setBold(true);		
	cellHeadStyle.setFont( cellHeadFont );
	
	sh.setColumnWidth(0, 12000);
	
	int row = 0;
	
	Row nowRow = sh.createRow(row);
	Cell cell1 = nowRow.createCell(0);
	cell1.setCellStyle(cellHeadStyle);
	cell1.setCellValue( "KPI" );				
	Cell cell2 = nowRow.createCell(1);
	cell2.setCellStyle(cellHeadStyle);
	cell2.setCellValue( "Maximum" );									
	Cell cell3 = nowRow.createCell(2);
	cell3.setCellStyle(cellHeadStyle);
	cell3.setCellValue( "Target" );	
	Cell cell4 = nowRow.createCell(3);
	cell4.setCellStyle(cellHeadStyle);
	cell4.setCellValue( "Minimum" );								
	Cell cell5 = nowRow.createCell(4);
	cell5.setCellStyle(cellHeadStyle);
	cell5.setCellValue( "Current score" );			
	Cell cell6 = nowRow.createCell(5);
	cell6.setCellStyle(cellHeadStyle);
	cell6.setCellValue( "Previous score" );	
	Cell cell7 = nowRow.createCell(6);
	cell7.setCellStyle(cellHeadStyle);
	cell7.setCellValue( "Change(%)" );	
	
	row++;
	
	List<PeriodTrendsData<KpiVO>> periodDatas = (List<PeriodTrendsData<KpiVO>>)context.get("periodDatas");
	for (PeriodTrendsData<KpiVO> periodData : periodDatas) {
		nowRow = sh.createRow(row);

		cell1 = nowRow.createCell(0);
		cell1.setCellValue( periodData.getCurrent().getName() );				
		cell2 = nowRow.createCell(1);
		cell2.setCellValue( periodData.getCurrent().getMax() );									
		cell3 = nowRow.createCell(2);
		cell3.setCellValue( periodData.getCurrent().getTarget() );	
		cell4 = nowRow.createCell(3);
		cell4.setCellValue( periodData.getCurrent().getMin() );								
		cell5 = nowRow.createCell(4);
		cell5.setCellValue( BscReportSupportUtils.parse2( periodData.getCurrent().getScore() ) );			
		cell6 = nowRow.createCell(5);
		cell6.setCellValue( BscReportSupportUtils.parse2( periodData.getPrevious().getScore() ) );	
		cell7 = nowRow.createCell(6);
		cell7.setCellValue( BscReportSupportUtils.parse2( periodData.getChange() ) );			
		
		row++;
	}
	
	nowRow = sh.createRow(row);
	
	cell1 = nowRow.createCell(0);
	cell1.setCellValue( "Current period: " + (String)context.get("currentPeriodDateRange") + " , Previous period: " + (String)context.get("previousPeriodDateRange") );				
	
}
 
Example 7
Source File: PersonalReportExcelCommand.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
private void createFoot(XSSFWorkbook wb, XSSFSheet sh, int row, VisionVO vision, Context context) throws Exception {
	
	Row footRow=sh.createRow(row);
	Row footRowB=sh.createRow(row+1);
	XSSFCellStyle cellStyle=wb.createCellStyle();
	
	cellStyle.setFillForegroundColor( new XSSFColor(SimpleUtils.getColorRGB4POIColor("#FFFFFF"), null) );
	cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);		
	cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	cellStyle.setBorderBottom(BorderStyle.THIN);
	cellStyle.setBorderTop(BorderStyle.THIN);
	cellStyle.setBorderRight(BorderStyle.THIN);
	cellStyle.setBorderLeft(BorderStyle.THIN);					
	XSSFFont cellFont=wb.createFont();
	cellFont.setBold(true);
	cellStyle.setFont(cellFont);
	cellStyle.setWrapText(true);		
	
	Cell footCell1 = footRow.createCell(0);
	footCell1.setCellValue("assess:");
	footCell1.setCellStyle(cellStyle);			
	Cell footCell1B = footRowB.createCell(0);
	footCell1B.setCellValue("assess:");
	footCell1B.setCellStyle(cellStyle);		
	sh.addMergedRegion(new CellRangeAddress(row, row+1, 0, 0));					
	
	Cell footCell2 = footRow.createCell(1);
	footCell2.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() );
	footCell2.setCellStyle(cellStyle);					
	Cell footCell3 = footRow.createCell(2);
	footCell3.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() );
	footCell3.setCellStyle(cellStyle);			
	Cell footCell4 = footRow.createCell(3);
	footCell4.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() );
	footCell4.setCellStyle(cellStyle);			
	Cell footCell2B = footRowB.createCell(1);
	footCell2B.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() );
	footCell2B.setCellStyle(cellStyle);					
	Cell footCell3B = footRowB.createCell(2);
	footCell3B.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() );
	footCell3B.setCellStyle(cellStyle);			
	Cell footCell4B = footRowB.createCell(3);
	footCell4B.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() );
	footCell4B.setCellStyle(cellStyle);					
	sh.addMergedRegion(new CellRangeAddress(row, row+1, 1, 3));	
	
	Cell footCell5 = footRow.createCell(4);
	footCell5.setCellValue("Total");
	footCell5.setCellStyle(cellStyle);	
	
	float total = 0.0f;
	if ( context.get("total")!=null && context.get("total") instanceof Float ) {
		total = (Float)context.get("total");
	}
	
	Cell footCell6 = footRow.createCell(5);
	footCell6.setCellValue( BscReportSupportUtils.parse2(total) );
	footCell6.setCellStyle(cellStyle);			
	
	Cell footCell5b = footRowB.createCell(4);
	footCell5b.setCellValue("Class");
	footCell5b.setCellStyle(cellStyle);			
	
	Cell footCell6b = footRowB.createCell(5);
	footCell6b.setCellValue( "" );
	footCell6b.setCellStyle(cellStyle);				
	
}