protected XSSFCellStyle createStyle(XSSFColor color) { XSSFCellStyle style = workbook.createCellStyle(); if (color != null) { style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFillForegroundColor(color); } style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); return style; }
style.setVerticalAlignment(VerticalAlignment.TOP); }else if(valign.equals(Alignment.middle)){ style.setVerticalAlignment(VerticalAlignment.CENTER); }else if(valign.equals(Alignment.bottom)){ style.setVerticalAlignment(VerticalAlignment.BOTTOM);
protected XSSFCellStyle createStyle(XSSFColor color) { XSSFCellStyle style = workbook.createCellStyle(); if (color != null) { style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFillForegroundColor(color); } style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); return style; }
private static int writeRowsToExcel(XSSFWorkbook wb, Sheet sheet, List<List<Object>> rows, int rowIndex) { int colIndex = 0; Font dataFont = wb.createFont(); dataFont.setFontName("simsun"); // dataFont.setFontHeightInPoints((short) 14); dataFont.setColor(IndexedColors.BLACK.index); XSSFCellStyle dataStyle = wb.createCellStyle(); dataStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); dataStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); dataStyle.setFont(dataFont); setBorder(dataStyle, BorderStyle.THIN, new XSSFColor(new Color(0, 0, 0))); for (List<Object> rowData : rows) { Row dataRow = sheet.createRow(rowIndex); // dataRow.setHeightInPoints(25); colIndex = 0; for (Object cellData : rowData) { Cell cell = dataRow.createCell(colIndex); if (cellData != null) { cell.setCellValue(cellData.toString()); } else { cell.setCellValue(""); } cell.setCellStyle(dataStyle); colIndex++; } rowIndex++; } return rowIndex; }
private static int writeTitlesToExcel(XSSFWorkbook wb, Sheet sheet, List<String> titles) { int rowIndex = 0; int colIndex = 0; Font titleFont = wb.createFont(); titleFont.setFontName("simsun"); titleFont.setBold(true); // titleFont.setFontHeightInPoints((short) 14); titleFont.setColor(IndexedColors.BLACK.index); XSSFCellStyle titleStyle = wb.createCellStyle(); titleStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); titleStyle.setFillForegroundColor(new XSSFColor(new Color(182, 184, 192))); titleStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); titleStyle.setFont(titleFont); setBorder(titleStyle, BorderStyle.THIN, new XSSFColor(new Color(0, 0, 0))); Row titleRow = sheet.createRow(rowIndex); // titleRow.setHeightInPoints(25); colIndex = 0; for (String field : titles) { Cell cell = titleRow.createCell(colIndex); cell.setCellValue(field); cell.setCellStyle(titleStyle); colIndex++; } rowIndex++; return rowIndex; }
cellStyle.setVerticalAlignment(valign);
style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFont(titleFont); styles.put("title", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(new XSSFColor(new java.awt.Color(39, 51, 89), wb.getStylesSource().getIndexedColors())); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 232, 243), wb.getStylesSource().getIndexedColors())); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 232, 243), wb.getStylesSource().getIndexedColors())); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setVerticalAlignment(VerticalAlignment.TOP); style.setBorderLeft(BorderStyle.THIN); style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 255), wb.getStylesSource().getIndexedColors())); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 255), wb.getStylesSource().getIndexedColors())); style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
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; }
styleNew.setIndention(styleOld.getIndention()); styleNew.setLocked(styleOld.getLocked()); styleNew.setVerticalAlignment(styleOld.getVerticalAlignment()); styleNew.setWrapText(styleOld.getWrapText()); this.styleMap.put(hash, styleNew);
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 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); } }
style.setVerticalAlignment(VerticalAlignment.TOP); }else if(valign.equals(Alignment.middle)){ style.setVerticalAlignment(VerticalAlignment.CENTER); }else if(valign.equals(Alignment.bottom)){ style.setVerticalAlignment(VerticalAlignment.BOTTOM);