List of usage examples for org.apache.poi.ss.util RegionUtil setBorderRight
public static void setBorderRight(BorderStyle border, CellRangeAddress region, Sheet sheet)
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;/*from w w w. j a v a 2 s .c o m*/ 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:generate.XGenerator.java
public static void doMerge(Sheet worksheet, int rowIndex, int columnIndex, int rowSpan, int columnSpan, boolean border) { range = new CellRangeAddress(rowIndex, rowIndex + rowSpan - 1, columnIndex, columnIndex + columnSpan - 1); Cell cell = worksheet.getRow(rowIndex).getCell(columnIndex); if (CopyRow.getNbOfMergedRegions(worksheet, rowIndex + rowSpan - 1) <= 0) { worksheet.addMergedRegion(range); }/*from w w w .j a v a 2s. c o m*/ if (border == true) { RegionUtil.setBorderTop(CellStyle.BORDER_THIN, range, worksheet); RegionUtil.setBorderLeft(CellStyle.BORDER_THIN, range, worksheet); RegionUtil.setBorderRight(CellStyle.BORDER_THIN, range, worksheet); RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range, worksheet); } }
From source file:org.haplo.jsinterface.generate.KGenerateXLS.java
License:Mozilla Public License
private void styleBorder(SheetStyleInstruction i) { CellRangeAddress region = styleInstructionCellRangeAddress(i); // Border//from w ww. ja v a 2s . co m RegionUtil.setBorderBottom(BorderStyle.MEDIUM, region, this.sheet); RegionUtil.setBorderTop(BorderStyle.MEDIUM, region, this.sheet); RegionUtil.setBorderLeft(BorderStyle.MEDIUM, region, this.sheet); RegionUtil.setBorderRight(BorderStyle.MEDIUM, region, this.sheet); // Colour short colindex = styleFindColour(IndexedColors.BLACK.getIndex(), i.colour); RegionUtil.setBottomBorderColor(colindex, region, this.sheet); RegionUtil.setTopBorderColor(colindex, region, this.sheet); RegionUtil.setLeftBorderColor(colindex, region, this.sheet); RegionUtil.setRightBorderColor(colindex, region, this.sheet); }