/** * Draws a group of cell borders for a cell range. The borders are not * applied to the cells at this time, just the template is drawn. To apply * the drawn borders to a sheet, use {@link #applyBorders}. * * @param range * - {@link CellRangeAddress} range of cells on which borders are * drawn. * @param borderType * - Type of border to draw. {@link BorderStyle}. * @param color * - Color index from {@link IndexedColors} used to draw the * borders. * @param extent * - {@link BorderExtent} of the borders to be * applied. */ public void drawBorders(CellRangeAddress range, BorderStyle borderType, short color, BorderExtent extent) { drawBorders(range, borderType, extent); if (borderType != BorderStyle.NONE) { drawBorderColors(range, color, extent); } }
/** * <p> * Sets the color of the top border for a range of cells. * </p> * * @param range * - {@link CellRangeAddress} range of cells on which colors are * set. * @param color * - Color index from {@link IndexedColors} used to draw the * borders. */ private void drawTopBorderColor(CellRangeAddress range, short color) { int row = range.getFirstRow(); int firstCol = range.getFirstColumn(); int lastCol = range.getLastColumn(); for (int i = firstCol; i <= lastCol; i++) { if (getBorderStyle(row, i, CellUtil.BORDER_TOP) == BorderStyle.NONE) { drawTopBorder(new CellRangeAddress(row, row, i, i), BorderStyle.THIN); } addProperty(row, i, CellUtil.TOP_BORDER_COLOR, color); } }
/** * Create a PropertyTemplate object from another PropertyTemplate * * @param template a PropertyTemplate object */ public PropertyTemplate(PropertyTemplate template) { this(); for(Map.Entry<CellAddress, Map<String, Object>> entry : template.getTemplate().entrySet()) { _propertyTemplate.put(new CellAddress(entry.getKey()), cloneCellProperties(entry.getValue())); } }
switch (extent) { case NONE: removeBorderColors(range); break; case ALL: drawHorizontalBorderColors(range, color, BorderExtent.ALL); drawVerticalBorderColors(range, color, BorderExtent.ALL); break; case INSIDE: drawHorizontalBorderColors(range, color, BorderExtent.INSIDE); drawVerticalBorderColors(range, color, BorderExtent.INSIDE); break; case OUTSIDE: drawOutsideBorderColors(range, color, BorderExtent.ALL); break; case TOP: drawTopBorderColor(range, color); break; case BOTTOM: drawBottomBorderColor(range, color); break; case LEFT: drawLeftBorderColor(range, color); break; case RIGHT: drawRightBorderColor(range, color); break; case HORIZONTAL: drawHorizontalBorderColors(range, color, BorderExtent.ALL);
case VERTICAL: if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) { drawTopBorder(range, borderType); drawBottomBorder(range, borderType); drawLeftBorder(range, borderType); drawRightBorder(range, borderType);
switch (extent) { case NONE: removeBorders(range); break; case ALL: drawHorizontalBorders(range, borderType, BorderExtent.ALL); drawVerticalBorders(range, borderType, BorderExtent.ALL); break; case INSIDE: drawHorizontalBorders(range, borderType, BorderExtent.INSIDE); drawVerticalBorders(range, borderType, BorderExtent.INSIDE); break; case OUTSIDE: drawOutsideBorders(range, borderType, BorderExtent.ALL); break; case TOP: drawTopBorder(range, borderType); break; case BOTTOM: drawBottomBorder(range, borderType); break; case LEFT: drawLeftBorder(range, borderType); break; case RIGHT: drawRightBorder(range, borderType); break; case HORIZONTAL: drawHorizontalBorders(range, borderType, BorderExtent.ALL);
case VERTICAL: if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) { drawTopBorderColor(range, color); drawBottomBorderColor(range, color); drawLeftBorderColor(range, color); drawRightBorderColor(range, color);
/** * <p> * Sets the color of the left border for a range of cells. * </p> * * @param range * - {@link CellRangeAddress} range of cells on which colors are * set. * @param color * - Color index from {@link IndexedColors} used to draw the * borders. */ private void drawLeftBorderColor(CellRangeAddress range, short color) { int firstRow = range.getFirstRow(); int lastRow = range.getLastRow(); int col = range.getFirstColumn(); for (int i = firstRow; i <= lastRow; i++) { if (getBorderStyle(i, col, CellUtil.BORDER_LEFT) == BorderStyle.NONE) { drawLeftBorder(new CellRangeAddress(i, i, col, col), BorderStyle.THIN); } addProperty(i, col, CellUtil.LEFT_BORDER_COLOR, color); } }
/** * <p> * Sets the color of the bottom border for a range of cells. * </p> * * @param range * - {@link CellRangeAddress} range of cells on which colors are * set. * @param color * - Color index from {@link IndexedColors} used to draw the * borders. */ private void drawBottomBorderColor(CellRangeAddress range, short color) { int row = range.getLastRow(); int firstCol = range.getFirstColumn(); int lastCol = range.getLastColumn(); for (int i = firstCol; i <= lastCol; i++) { if (getBorderStyle(row, i, CellUtil.BORDER_BOTTOM) == BorderStyle.NONE) { drawBottomBorder(new CellRangeAddress(row, row, i, i), BorderStyle.THIN); } addProperty(row, i, CellUtil.BOTTOM_BORDER_COLOR, color); } }
/** * <p> * Sets the color of the right border for a range of cells. If the border is * not drawn, it defaults to BORDER_THIN * </p> * * @param range * - {@link CellRangeAddress} range of cells on which colors are * set. * @param color * - Color index from {@link IndexedColors} used to draw the * borders. */ private void drawRightBorderColor(CellRangeAddress range, short color) { int firstRow = range.getFirstRow(); int lastRow = range.getLastRow(); int col = range.getLastColumn(); for (int i = firstRow; i <= lastRow; i++) { if (getBorderStyle(i, col, CellUtil.BORDER_RIGHT) == BorderStyle.NONE) { drawRightBorder(new CellRangeAddress(i, i, col, col), BorderStyle.THIN); } addProperty(i, col, CellUtil.RIGHT_BORDER_COLOR, color); } }
PropertyTemplate pt = new PropertyTemplate(); pt.drawBorders(new CellRangeAddress(1, 3, 1, 3), BorderStyle.MEDIUM, BorderExtent.ALL); pt.drawBorders(new CellRangeAddress(5, 7, 1, 3), BorderStyle.MEDIUM, BorderExtent.OUTSIDE); pt.drawBorders(new CellRangeAddress(5, 7, 1, 3), BorderStyle.THIN, BorderExtent.INSIDE); pt.drawBorders(new CellRangeAddress(9, 11, 1, 3), BorderStyle.MEDIUM, IndexedColors.RED.getIndex(), BorderExtent.OUTSIDE); pt.drawBorders(new CellRangeAddress(9, 11, 1, 3), BorderStyle.MEDIUM, IndexedColors.BLUE.getIndex(), BorderExtent.INSIDE_VERTICAL); pt.drawBorders(new CellRangeAddress(9, 11, 1, 3), BorderStyle.MEDIUM, IndexedColors.GREEN.getIndex(), BorderExtent.INSIDE_HORIZONTAL); pt.drawBorders(new CellRangeAddress(10, 10, 2, 2), BorderStyle.NONE, BorderExtent.ALL); pt.applyBorders(sh1); pt.applyBorders(sh2);
/** * Adds a property to this {@link PropertyTemplate} for a given cell * * @param row * @param col * @param property * @param value */ private void addProperty(int row, int col, String property, short value) { addProperty(row, col, property, Short.valueOf(value)); }
lastCol); if (extent == BorderExtent.ALL || i > firstRow) { drawTopBorderColor(row, color); drawBottomBorderColor(row, color);
lastCol); if (extent == BorderExtent.ALL || i > firstRow) { drawTopBorder(row, borderType); drawBottomBorder(row, borderType);
i, i); if (extent == BorderExtent.ALL || i > firstCol) { drawLeftBorderColor(row, color); drawRightBorderColor(row, color);
i, i); if (extent == BorderExtent.ALL || i > firstCol) { drawLeftBorder(row, borderType); drawRightBorder(row, borderType);
switch (extent) { case NONE: removeBorderColors(range); break; case ALL: drawHorizontalBorderColors(range, color, BorderExtent.ALL); drawVerticalBorderColors(range, color, BorderExtent.ALL); break; case INSIDE: drawHorizontalBorderColors(range, color, BorderExtent.INSIDE); drawVerticalBorderColors(range, color, BorderExtent.INSIDE); break; case OUTSIDE: drawOutsideBorderColors(range, color, BorderExtent.ALL); break; case TOP: drawTopBorderColor(range, color); break; case BOTTOM: drawBottomBorderColor(range, color); break; case LEFT: drawLeftBorderColor(range, color); break; case RIGHT: drawRightBorderColor(range, color); break; case HORIZONTAL: drawHorizontalBorderColors(range, color, BorderExtent.ALL);
switch (extent) { case NONE: removeBorders(range); break; case ALL: drawHorizontalBorders(range, borderType, BorderExtent.ALL); drawVerticalBorders(range, borderType, BorderExtent.ALL); break; case INSIDE: drawHorizontalBorders(range, borderType, BorderExtent.INSIDE); drawVerticalBorders(range, borderType, BorderExtent.INSIDE); break; case OUTSIDE: drawOutsideBorders(range, borderType, BorderExtent.ALL); break; case TOP: drawTopBorder(range, borderType); break; case BOTTOM: drawBottomBorder(range, borderType); break; case LEFT: drawLeftBorder(range, borderType); break; case RIGHT: drawRightBorder(range, borderType); break; case HORIZONTAL: drawHorizontalBorders(range, borderType, BorderExtent.ALL);
case VERTICAL: if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) { drawTopBorder(range, borderType); drawBottomBorder(range, borderType); drawLeftBorder(range, borderType); drawRightBorder(range, borderType);
case VERTICAL: if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) { drawTopBorderColor(range, color); drawBottomBorderColor(range, color); drawLeftBorderColor(range, color); drawRightBorderColor(range, color);