/** * Set the type of border to use for the top border of the cell * * @param border the type of border to use */ public void setBorderTop(BorderStyle border) { setBorderTop((short)border.ordinal()); }
XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderTop(XSSFBorderFormatting.BORDER_MEDIUM);
XSSFCellStyle style = workbook.createCellStyle(); style.setBorderTop((short) 6); // double lines border style.setBorderBottom((short) 1); // single line border XSSFFont font = workbook.createFont(); font.setFontHeightInPoints((short) 15); font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); Row row = sheet.createRow(0); Cell cell0 = row.createCell(0); cell0.setCellValue("Nav Value"); cell0.setCellStyle(style); for(int j = 0; j<=3; j++) row.getCell(j).setCellStyle(style);
private void putBorders(XSSFCellStyle cs) { cs.setBorderLeft(BorderStyle.THIN); cs.setBorderTop(BorderStyle.THIN); cs.setBorderRight(BorderStyle.THIN); cs.setBorderBottom(BorderStyle.THIN); }
private static void addBordersToCellStyle(final XSSFCellStyle currentCellStyle, final BorderStyle borderStyle) { currentCellStyle.setBorderTop(borderStyle); currentCellStyle.setBorderBottom(borderStyle); currentCellStyle.setBorderLeft(borderStyle); currentCellStyle.setBorderRight(borderStyle); }
@Test public void testXlsx_BackgroundStyle() { when( workbook.createCellStyle() ).thenReturn( xlsxStyle ); ExcelCellStyleBuilder builder = new ExcelCellStyleBuilder( workbook ); CellBackground bg = getBackground(); HSSFCellStyleProducer.HSSFCellStyleKey styleKey = getXlsxKey(); builder.withBackgroundStyle( bg, styleKey ); verify( xlsxStyle, times( 1 ) ).setBorderBottom( eq( BorderStyle.DASH_DOT ) ); verify( xlsxStyle, times( 1 ) ) .setBorderColor( eq( XSSFCellBorder.BorderSide.BOTTOM ), notNull( XSSFColor.class ) ); verify( xlsxStyle, times( 1 ) ).setBorderTop( eq( BorderStyle.DOTTED ) ); verify( xlsxStyle, times( 1 ) ).setBorderColor( eq( XSSFCellBorder.BorderSide.TOP ), notNull( XSSFColor.class ) ); verify( xlsxStyle, times( 1 ) ).setBorderLeft( eq( BorderStyle.DASH_DOT_DOT ) ); verify( xlsxStyle, times( 1 ) ).setBorderColor( eq( XSSFCellBorder.BorderSide.LEFT ), notNull( XSSFColor.class ) ); verify( xlsxStyle, times( 1 ) ).setBorderRight( eq( BorderStyle.DASHED ) ); verify( xlsxStyle, times( 1 ) ).setBorderColor( eq( XSSFCellBorder.BorderSide.RIGHT ), notNull( XSSFColor.class ) ); verify( xlsxStyle, times( 1 ) ).setFillForegroundColor( notNull( XSSFColor.class ) ); verify( xlsxStyle, times( 1 ) ).setFillPattern( eq( FillPatternType.SOLID_FOREGROUND ) ); }
XSSFColor borderColor=buildXSSFColor(topBorder.getColor()); style.setTopBorderColor(borderColor); style.setBorderTop(borderStyle);
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); } }
@Override public void prepareColumn(TableModel tableModel, XSSFSheet sheet, int col) { XSSFWorkbook wb = sheet.getWorkbook(); XSSFDataFormat df = wb.createDataFormat(); cellStyle = wb.createCellStyle(); XSSFFont f = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setBold(true); f.setColor(IndexedColors.BLACK.getIndex()); cellStyle.setFont(f); cellStyle.setDataFormat(df.getFormat("text")); cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setBorderColor(BorderSide.TOP, new XSSFColor(new Color(0, 0, 0))); cellStyle.setBorderRight(CellStyle.BORDER_THIN); cellStyle.setBorderColor(BorderSide.RIGHT, new XSSFColor(new Color(0, 0, 0))); cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBorderColor(BorderSide.BOTTOM, new XSSFColor(new Color(0, 0, 0))); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setBorderColor(BorderSide.LEFT, new XSSFColor(new Color(0, 0, 0))); }
private static void appendMentoringTotalRow(XSSFWorkbook wb, XSSFSheet sheet, int rowNum, int start, int end) { Font boldFont = wb.createFont(); boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD); boldFont.setColor((short) 0x0); XSSFCellStyle commentCell = wb.createCellStyle(); commentCell.setBorderTop(CellStyle.BORDER_THIN); XSSFCellStyle totalCell = wb.createCellStyle(); totalCell.setBorderTop(CellStyle.BORDER_THIN); totalCell.setFont(boldFont); XSSFCellStyle totalCellRight = wb.createCellStyle(); totalCellRight.setBorderTop(CellStyle.BORDER_THIN); totalCellRight.setAlignment(HorizontalAlignment.RIGHT); totalCellRight.setFont(boldFont); XSSFRow row = sheet.createRow(rowNum); XSSFCell t1 = row.createCell(0); t1.setCellValue("Total:"); t1.setCellStyle(totalCellRight); XSSFCell t2 = row.createCell(1); t2.setCellFormula("SUM(B" + start + ":B" + end + ")"); t2.setCellStyle(totalCell); XSSFCell t3 = row.createCell(2); t3.setCellStyle(totalCell); XSSFCell t4 = row.createCell(3); t4.setCellStyle(commentCell); }
private static void appendTotalRow(XSSFWorkbook wb, XSSFSheet sheet, int rowNum) { Font boldFont = wb.createFont(); boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD); boldFont.setColor((short) 0x0); XSSFCellStyle commentCell = wb.createCellStyle(); commentCell.setBorderTop(CellStyle.BORDER_THIN); XSSFCellStyle totalCell = wb.createCellStyle(); totalCell.setBorderTop(CellStyle.BORDER_THIN); totalCell.setFont(boldFont); XSSFCellStyle totalCellRight = wb.createCellStyle(); totalCellRight.setBorderTop(CellStyle.BORDER_THIN); totalCellRight.setAlignment(HorizontalAlignment.RIGHT); totalCellRight.setFont(boldFont); XSSFRow row = sheet.createRow(rowNum); XSSFCell t1 = row.createCell(0); t1.setCellValue("Total:"); t1.setCellStyle(totalCellRight); XSSFCell t2 = row.createCell(1); t2.setCellFormula("SUM(B1:B" + rowNum + ")*" + TEST_PADDING); t2.setCellStyle(totalCell); XSSFCell t3 = row.createCell(2); t3.setCellStyle(totalCell); XSSFCell t4 = row.createCell(3); t4.setCellValue("Total with Testing & App Migration Factors"); t4.setCellStyle(commentCell); }
public static XSSFCellStyle getHeadCellStyle(XSSFWorkbook wb, XSSFFont font) { XSSFCellStyle headCellStyle = wb.createCellStyle(); headCellStyle.setFont(font); headCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); headCellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); headCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headCellStyle.setWrapText(false); headCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return headCellStyle; }
private static XSSFCellStyle getHeadCellStyle(XSSFWorkbook wb, XSSFFont font) {//用到 XSSFCellStyle headCellStyle = wb.createCellStyle(); headCellStyle.setFont(font); headCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); headCellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); headCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headCellStyle.setWrapText(false); headCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return headCellStyle; }
public CellStyle getHeaderCellStyle(SXSSFWorkbook workbook) { if (headCellStyle == null) { headCellStyle = workbook.getXSSFWorkbook().createCellStyle(); headCellStyle.setBorderTop(BorderStyle.NONE); headCellStyle.setBorderRight(BorderStyle.NONE); headCellStyle.setBorderBottom(BorderStyle.NONE); headCellStyle.setBorderLeft(BorderStyle.NONE); headCellStyle.setAlignment(HorizontalAlignment.CENTER); headCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); XSSFColor color = new XSSFColor(new java.awt.Color(217, 217, 217)); headCellStyle.setFillForegroundColor(color); headCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font font = workbook.createFont(); font.setFontName("微软雅黑"); font.setColor(IndexedColors.ROYAL_BLUE.index); font.setBold(true); headCellStyle.setFont(font); headCellStyle.setDataFormat(workbook.createDataFormat().getFormat("@")); } return headCellStyle; } }
XSSFCellStyle styleSubHeader = (XSSFCellStyle) wb.createCellStyle(); styleSubHeader.setFont(fontBold); styleSubHeader.setVerticalAlignment(CellStyle.VERTICAL_CENTER); styleSubHeader.setAlignment(CellStyle.ALIGN_CENTER); styleSubHeader.setFillForegroundColor(COLOR_ORANGE); styleSubHeader.setFillPattern(CellStyle.SOLID_FOREGROUND); styleSubHeader.setBorderBottom(CellStyle.BORDER_THIN); styleSubHeader.setBottomBorderColor(COLOR_GREY); styleSubHeader.setBorderLeft(CellStyle.BORDER_THIN); styleSubHeader.setLeftBorderColor(COLOR_GREY); styleSubHeader.setBorderRight(CellStyle.BORDER_THIN); styleSubHeader.setRightBorderColor(COLOR_GREY); styleSubHeader.setBorderTop(CellStyle.BORDER_THIN); styleSubHeader.setTopBorderColor(COLOR_GREY);
private static void appendMentoringTitleRow(XSSFWorkbook wb, XSSFSheet sheet, int rowNum) { XSSFCellStyle titleCell = wb.createCellStyle(); Color titleCellGrey = new Color(0xECECEC); XSSFColor color = new XSSFColor(titleCellGrey); titleCell.setFillForegroundColor(color); titleCell.setBorderBottom(CellStyle.BORDER_MEDIUM); titleCell.setBorderTop(CellStyle.BORDER_MEDIUM); titleCell.setFillPattern(CellStyle.SOLID_FOREGROUND); Font titleFormat = wb.createFont(); titleFormat.setBoldweight(Font.BOLDWEIGHT_BOLD); titleFormat.setColor((short) 0x0); titleCell.setFont(titleFormat); XSSFRow row = sheet.createRow(rowNum); XSSFCell t1 = row.createCell(0); t1.setCellValue("Migration Service Estimate"); t1.setCellStyle(titleCell); XSSFCell t2 = row.createCell(1); t2.setCellStyle(titleCell); XSSFCell t3 = row.createCell(2); t3.setCellStyle(titleCell); XSSFCell t4 = row.createCell(3); t4.setCellStyle(titleCell); }
private CellStyle backgroundStyle(SXSSFWorkbook workbook, Integer rgb, Font font) { XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle(); if (rgb != null) { IndexedColorMap indexedColors = workbook.getXSSFWorkbook().getStylesSource().getIndexedColors(); XSSFColor color = new XSSFColor(convertRGB(rgb), indexedColors); style.setFillForegroundColor(color); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); } style.setBorderBottom(BorderStyle.THIN); style.setBorderTop(BorderStyle.THIN); style.setBorderLeft(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN); if (font != null) { style.setFont(font); } style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); return style; }
private void fillHeaderRow(XSSFWorkbook workbook, XSSFSheet sheet, Locale locale) { XSSFRow header = sheet.createRow(3); Font font = createFontArialNormal(workbook); XSSFCellStyle style = workbook.createCellStyle(); style.setFont(font); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setWrapText(true); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); for (int i = 0; i < TrackingOperationProductInComponentAdditionalInformationReportColumns.ALL_COLUMNS.length; i++) { String column = TrackingOperationProductInComponentAdditionalInformationReportColumns.ALL_COLUMNS[i]; XSSFCell headerCell = header.createCell(i); headerCell.setCellValue(translationService.translate(column, locale)); headerCell.setCellStyle(style); } }
cellStyle.setLeftBorderColor(HTMLToExcelStyleCoverter.getXSSFLeftBorderColor(style, xssfWorkbook)); cellStyle.setBorderTop(HTMLToExcelStyleCoverter.getBorderTop(style)); cellStyle.setBorderRight(HTMLToExcelStyleCoverter.getBorderRight(style)); cellStyle.setBorderBottom(HTMLToExcelStyleCoverter.getBorderBottom(style));
cellStyle.setLeftBorderColor(HTMLToExcelStyleCoverter.getXSSFLeftBorderColor(style)); cellStyle.setBorderTop(HTMLToExcelStyleCoverter.getBorderTop(style)); cellStyle.setBorderRight(HTMLToExcelStyleCoverter.getBorderRight(style)); cellStyle.setBorderBottom(HTMLToExcelStyleCoverter.getBorderBottom(style));