List of usage examples for org.apache.poi.ss.usermodel BorderStyle THIN
BorderStyle THIN
To view the source code for org.apache.poi.ss.usermodel BorderStyle THIN.
Click Source Link
From source file:br.com.tecsinapse.dataio.style.CellStyleBorder.java
License:LGPL
public CellStyle toCellStyle(CellStyle cellStyle) { if (cellStyle == null || !left && !right && !bottom && !top) { return cellStyle; }/*from ww w . j a v a 2 s . c o m*/ if (left) { cellStyle.setBorderLeft(BorderStyle.THIN); if (cellStyle instanceof XSSFCellStyle) { ((XSSFCellStyle) cellStyle).setLeftBorderColor(new XSSFColor(toIndexedColorMap(borderColor))); } else { cellStyle.setLeftBorderColor(borderColor.getIndex()); } } if (right) { cellStyle.setBorderRight(BorderStyle.THIN); if (cellStyle instanceof XSSFCellStyle) { ((XSSFCellStyle) cellStyle).setRightBorderColor(new XSSFColor(toIndexedColorMap(borderColor))); } else { cellStyle.setRightBorderColor(borderColor.getIndex()); } } if (bottom) { cellStyle.setBorderBottom(BorderStyle.THIN); if (cellStyle instanceof XSSFCellStyle) { ((XSSFCellStyle) cellStyle).setBottomBorderColor(new XSSFColor(toIndexedColorMap(borderColor))); } else { cellStyle.setBottomBorderColor(borderColor.getIndex()); } } if (top) { cellStyle.setBorderTop(BorderStyle.THIN); if (cellStyle instanceof XSSFCellStyle) { ((XSSFCellStyle) cellStyle).setTopBorderColor(new XSSFColor(toIndexedColorMap(borderColor))); } else { cellStyle.setTopBorderColor(borderColor.getIndex()); } } return cellStyle; }
From source file:br.com.tecsinapse.dataio.util.WorkbookUtil.java
License:LGPL
public Workbook toWorkBook(Workbook wb, Table table) { List<List<TableCell>> matrix = table.getCells(); List<List<TableCell>> matrixFull = table.toTableCellMatrix(); replaceColorsPallete(table.getColorsReplaceMap(), wb); String sheetName = table.getTitle(); Sheet sheet = sheetName == null ? wb.createSheet() : wb.createSheet(sheetName); int titleRows = 0; int r = titleRows; int c = 0;/* w w w . j av a 2 s. c om*/ int maxColumns = -1; Map<Integer, Integer> defaultColumnWidth = new HashMap<>(); ExporterFormatter tableExporterFormatter = table.getExporterFormatter(); for (List<TableCell> row : matrix) { Row sheetRow = sheet.createRow(r); for (TableCell tableCell : row) { while (matrixFull.get(r - titleRows).get(c) == EmptyTableCell.EMPTY_CELL) { c++; if (c >= matrixFull.get(r - titleRows).size()) { c = 0; r++; } } Cell cell = sheetRow.createCell(c); if (c > maxColumns) { maxColumns = c; } if (tableCell.getRowspan() > 1 || tableCell.getColspan() > 1) { int rowStart = r; int rowEnd = rowStart + (tableCell.getRowspan() - 1); int colStart = c; int colEnd = colStart + (tableCell.getColspan() - 1); CellRangeAddress cellRange = new CellRangeAddress(rowStart, rowEnd, colStart, colEnd); sheet.addMergedRegion(cellRange); RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); } else if (!table.isAutoSizeColumnSheet()) { Integer maxColumnWidth = defaultColumnWidth.get(c); if (maxColumnWidth == null) { defaultColumnWidth.put(c, tableCell.getDefaultColumnWidth()); } else { int defaultWidth = tableCell.getDefaultColumnWidth(); if (defaultWidth > maxColumnWidth) { defaultColumnWidth.put(c, defaultWidth); } } } String format = setConvertedValue(cell, tableCell, tableExporterFormatter); setCellStyle(cell, tableCell, wb, format); c++; } r++; c = 0; } if (table.isAutoSizeColumnSheet()) { for (int i = 0; i <= maxColumns; ++i) { if (sheet instanceof SXSSFSheet) { ((SXSSFSheet) sheet).trackColumnForAutoSizing(i); } sheet.autoSizeColumn(i, true); } } else { for (int i = 0; i <= maxColumns; ++i) { if (defaultColumnWidth.get(i) == null) { if (sheet instanceof SXSSFSheet) { ((SXSSFSheet) sheet).trackColumnForAutoSizing(i); } sheet.autoSizeColumn(i, true); } else { int width = table.getMinOrMaxOrActualCellWidth(defaultColumnWidth.get(i)); sheet.setColumnWidth(i, width); } } } return wb; }
From source file:cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerBorderImpl.java
License:Apache License
@Override public CellStyle getHeaderStyle(short color) { CellStyle titleStyle = workbook.createCellStyle(); Font font = workbook.createFont(); font.setFontHeightInPoints((short) 12); titleStyle.setFont(font);//from w w w. j av a2 s .c o m titleStyle.setBorderLeft(BorderStyle.THIN); titleStyle.setBorderRight(BorderStyle.THIN); titleStyle.setBorderBottom(BorderStyle.THIN); titleStyle.setBorderTop(BorderStyle.THIN); titleStyle.setAlignment(HorizontalAlignment.CENTER); titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); return titleStyle; }
From source file:cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerBorderImpl.java
License:Apache License
@Override public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { CellStyle style = workbook.createCellStyle(); style.setBorderLeft(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN); style.setBorderBottom(BorderStyle.THIN); style.setBorderTop(BorderStyle.THIN); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setDataFormat(STRING_FORMAT);/* ww w .ja v a 2 s . c o m*/ if (isWarp) { style.setWrapText(true); } return style; }
From source file:cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerBorderImpl.java
License:Apache License
@Override public CellStyle getTitleStyle(short color) { CellStyle titleStyle = workbook.createCellStyle(); titleStyle.setBorderLeft(BorderStyle.THIN); titleStyle.setBorderRight(BorderStyle.THIN); titleStyle.setBorderBottom(BorderStyle.THIN); titleStyle.setBorderTop(BorderStyle.THIN); titleStyle.setAlignment(HorizontalAlignment.CENTER); titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); titleStyle.setWrapText(true);// w ww . j a v a2 s . com return titleStyle; }
From source file:cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerColorImpl.java
License:Apache License
@Override public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { CellStyle style = workbook.createCellStyle(); style.setBorderLeft(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN); style.setBorderBottom(BorderStyle.THIN); style.setBorderTop(BorderStyle.THIN); style.setFillForegroundColor((short) 41); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setDataFormat(STRING_FORMAT);//w ww . j a va2s.c om if (isWarp) { style.setWrapText(true); } return style; }
From source file:cn.afterturn.easypoi.excel.html.css.impl.BorderCssConverImpl.java
License:Apache License
@Override public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { if (style == null || style.getBorder() == null) { return;/* www . jav a 2 s. co m*/ } CellStyleBorderEntity border = style.getBorder(); for (String pos : new String[] { TOP, RIGHT, BOTTOM, LEFT }) { String posName = StringUtils.capitalize(pos.toLowerCase()); // color String colorAttr = null; try { colorAttr = (String) MethodUtils.invokeMethod(border, "getBorder" + posName + "Color"); } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } if (StringUtils.isNotEmpty(colorAttr)) { if (cell instanceof HSSFCell) { HSSFColor poiColor = PoiCssUtils.parseColor((HSSFWorkbook) cell.getSheet().getWorkbook(), colorAttr); if (poiColor != null) { try { MethodUtils.invokeMethod(cellStyle, "set" + posName + "BorderColor", poiColor.getIndex()); } catch (Exception e) { log.error("Set Border Color Error Caused.", e); } } } if (cell instanceof XSSFCell) { XSSFColor poiColor = PoiCssUtils.parseColor(colorAttr); if (poiColor != null) { try { MethodUtils.invokeMethod(cellStyle, "set" + posName + "BorderColor", poiColor); } catch (Exception e) { log.error("Set Border Color Error Caused.", e); } } } } // width int width = 0; try { String widthStr = (String) MethodUtils.invokeMethod(border, "getBorder" + posName + "Width"); if (PoiCssUtils.isNum(widthStr)) { width = Integer.parseInt(widthStr); } } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } String styleValue = null; try { styleValue = (String) MethodUtils.invokeMethod(border, "getBorder" + posName + "Style"); } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } BorderStyle shortValue = BorderStyle.NONE; // empty or solid if (StringUtils.isBlank(styleValue) || "solid".equals(styleValue)) { if (width > 2) { shortValue = BorderStyle.THICK; } else if (width > 1) { shortValue = BorderStyle.MEDIUM; } else { shortValue = BorderStyle.THIN; } } else if (ArrayUtils.contains(new String[] { NONE, HIDDEN }, styleValue)) { shortValue = BorderStyle.NONE; } else if (DOUBLE.equals(styleValue)) { shortValue = BorderStyle.DOUBLE; } else if (DOTTED.equals(styleValue)) { shortValue = BorderStyle.DOTTED; } else if (DASHED.equals(styleValue)) { if (width > 1) { shortValue = BorderStyle.MEDIUM_DASHED; } else { shortValue = BorderStyle.DASHED; } } // border style if (shortValue != BorderStyle.NONE) { try { MethodUtils.invokeMethod(cellStyle, "setBorder" + posName, shortValue); } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } } } }
From source file:com.catexpress.util.FormatosPOI.java
public CellStyle estiloColumnas(Workbook wb, int tipo) { CellStyle estiloCelda = wb.createCellStyle(); Font fuente = wb.createFont(); if (tipo == COLUMNA) { estiloCelda.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); fuente.setBold(true);/*from www.j a v a 2s. c om*/ } if (tipo == SURTIDO) { fuente.setColor(IndexedColors.WHITE.getIndex()); estiloCelda.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex()); estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); } fuente.setFontName("Calibri"); fuente.setFontHeightInPoints((short) 11); estiloCelda.setFont(fuente); estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER); estiloCelda.setAlignment(HorizontalAlignment.CENTER); if (tipo == COLUMNA) { estiloCelda.setBorderBottom(BorderStyle.MEDIUM); estiloCelda.setBorderTop(BorderStyle.MEDIUM); estiloCelda.setBorderLeft(BorderStyle.MEDIUM); estiloCelda.setBorderRight(BorderStyle.MEDIUM); } else { estiloCelda.setBorderBottom(BorderStyle.THIN); estiloCelda.setBorderTop(BorderStyle.THIN); estiloCelda.setBorderLeft(BorderStyle.THIN); estiloCelda.setBorderRight(BorderStyle.THIN); } return estiloCelda; }
From source file:com.catexpress.util.FormatosPOI.java
public CellStyle estiloCuadro(Workbook wb, int tipo) { CellStyle estiloCelda = wb.createCellStyle(); Font fuente = wb.createFont(); if (tipo == AMARILLO) { estiloCelda.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); }/* w ww . j a va 2 s .c o m*/ fuente.setFontName("Calibri"); fuente.setBold(true); fuente.setFontHeightInPoints((short) 12); estiloCelda.setFont(fuente); estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER); estiloCelda.setAlignment(HorizontalAlignment.CENTER); estiloCelda.setBorderBottom(BorderStyle.THIN); estiloCelda.setBorderTop(BorderStyle.THIN); estiloCelda.setBorderLeft(BorderStyle.THIN); estiloCelda.setBorderRight(BorderStyle.THIN); return estiloCelda; }
From source file:com.ferid.app.classroom.utility.ExcelStyleManager.java
License:Apache License
/** * Header cell style (dates)//from w w w. j ava2 s. c o m * @param wb Workbook * @return CellStyle */ public static CellStyle getHeaderCellStyle(Workbook wb) { CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HorizontalAlignment.CENTER); Font font = wb.createFont(); font.setFontHeightInPoints((short) 8); font.setBold(true); cellStyle.setFont(font); cellStyle.setWrapText(true); cellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE.getIndex()); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); return cellStyle; }