org.apache.poi.ss.usermodel.BorderStyle Java Examples

The following examples show how to use org.apache.poi.ss.usermodel.BorderStyle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PropertyTemplate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Draws the outside borders for a range of cells.
 * </p>
 *
 * @param range
 *            - {@link CellRangeAddress} range of cells on which borders are
 *            drawn.
 * @param borderType
 *            - Type of border to draw. {@link BorderStyle}.
 * @param extent
 *            - {@link BorderExtent} of the borders to be
 *            applied. Valid Values are:
 *            <ul>
 *            <li>BorderExtent.ALL</li>
 *            <li>BorderExtent.HORIZONTAL</li>
 *            <li>BorderExtent.VERTICAL</li>
 *            </ul>
 */
private void drawOutsideBorders(CellRangeAddress range,
        BorderStyle borderType, BorderExtent extent) {
    switch (extent) {
    case ALL:
    case HORIZONTAL:
    case VERTICAL:
        if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) {
            drawTopBorder(range, borderType);
            drawBottomBorder(range, borderType);
        }
        if (extent == BorderExtent.ALL || extent == BorderExtent.VERTICAL) {
            drawLeftBorder(range, borderType);
            drawRightBorder(range, borderType);
        }
        break;
    default:
        throw new IllegalArgumentException(
                "Unsupported PropertyTemplate.Extent, valid Extents are ALL, HORIZONTAL, and VERTICAL");
    }
}
 
Example #2
Source File: WorkbookContext.java    From Octopus with MIT License 6 votes vote down vote up
private void setStyleBorder(CellStyle style, BorderStyle[] border) {
    if (border != null) {
        if (border[0] != null) {
            style.setBorderTop(border[0]);
        }
        if (border[1] != null) {
            style.setBorderRight(border[1]);
        }
        if (border[2] != null) {
            style.setBorderBottom(border[2]);
        }
        if (border[3] != null) {
            style.setBorderLeft(border[3]);
        }
    }
}
 
Example #3
Source File: SpreadsheetCellStyleTest.java    From taro with MIT License 6 votes vote down vote up
@Test
public void apply_OverwritesNonNullProperties() {
    SpreadsheetCellStyle src = new SpreadsheetCellStyle().withBold(true).withLeftBorder(BorderStyle.THIN);
    SpreadsheetCellStyle dest = new SpreadsheetCellStyle().withIndention(1).withLeftBorder(BorderStyle.MEDIUM);

    assertThat(src.getBold(), is(true));
    assertThat(src.getLeftBorder(), is(BorderStyle.THIN));
    assertThat(src.getIndention(), nullValue());

    assertThat(dest.getBold(), nullValue());
    assertThat(dest.getLeftBorder(), is(BorderStyle.MEDIUM));
    assertThat(dest.getIndention(), is(1));

    // Method Under Test
    SpreadsheetCellStyle applied = dest.apply(src);

    // src was set, so overwrite the null value on dest
    assertThat(applied.getBold(), is(true));

    // src was set, so overwrite the previously set value on dest
    assertThat(applied.getLeftBorder(), is(BorderStyle.THIN));

    // src was not set, so do not overwrite the existing set value on dest
    assertThat(applied.getIndention(), is(1));
}
 
Example #4
Source File: ExportTimetableXLS.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected CellStyle getGridNameStyle(P p) {
	String styleId = "grid-name";
	CellStyle style = iStyles.get(styleId);
	if (style == null) {
		style = iWorkbook.createCellStyle();
        style.setBorderLeft(BorderStyle.THIN);
        style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderTop(BorderStyle.THIN);
        style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setFont(getFont(p));
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.TOP);
        style.setWrapText(true);
        iStyles.put(styleId, style);
	}
	return style;
}
 
Example #5
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setPen(JRPen pen) {
	if (
		borderStyle[TOP] == BorderStyle.NONE
		&& borderStyle[LEFT] == BorderStyle.NONE
		&& borderStyle[BOTTOM] == BorderStyle.NONE
		&& borderStyle[RIGHT] == BorderStyle.NONE
		) {
		BorderStyle style = JRXlsMetadataExporter.getBorderStyle(pen);
		short colour = JRXlsMetadataExporter.this.getWorkbookColor(pen.getLineColor()).getIndex();

		borderStyle[TOP] = style;
		borderStyle[BOTTOM] = style;
		borderStyle[LEFT] = style;
		borderStyle[RIGHT] = style;

		borderColour[TOP] = colour;
		borderColour[BOTTOM] = colour;
		borderColour[LEFT] = colour;
		borderColour[RIGHT] = colour;
	}

	hash = computeHash();
}
 
Example #6
Source File: JRXlsExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setPen(JRPen pen)
{
	if (
		borderStyle[TOP] == BorderStyle.NONE
		&& borderStyle[LEFT] == BorderStyle.NONE
		&& borderStyle[BOTTOM] == BorderStyle.NONE
		&& borderStyle[RIGHT] == BorderStyle.NONE
		)
	{
		BorderStyle style = JRXlsExporter.getBorderStyle(pen);
		short colour = JRXlsExporter.this.getWorkbookColor(pen.getLineColor()).getIndex();

		borderStyle[TOP] = style;
		borderStyle[BOTTOM] = style;
		borderStyle[LEFT] = style;
		borderStyle[RIGHT] = style;

		borderColour[TOP] = colour;
		borderColour[BOTTOM] = colour;
		borderColour[LEFT] = colour;
		borderColour[RIGHT] = colour;
	}

	hash = computeHash();
}
 
Example #7
Source File: ExcelCellStyleBuilderTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testXls_BackgroundStyle() {
  when( workbook.createCellStyle() ).thenReturn( xlsStyle );
  ExcelCellStyleBuilder builder = new ExcelCellStyleBuilder( workbook );

  CellBackground bg = getBackground();
  HSSFCellStyleProducer.HSSFCellStyleKey styleKey = getXlsKey();

  builder.xls_backgroundStyle( bg, styleKey );

  verify( xlsStyle, times( 1 ) ).setBorderBottom( eq( BorderStyle.MEDIUM_DASH_DOT ) );
  verify( xlsStyle, times( 1 ) ).setBottomBorderColor( eq( (short) 116 ) );
  verify( xlsStyle, times( 1 ) ).setBorderTop( eq( BorderStyle.MEDIUM_DASHED ) );
  verify( xlsStyle, times( 1 ) ).setTopBorderColor( eq( (short) 118 ) );
  verify( xlsStyle, times( 1 ) ).setBorderLeft( eq( BorderStyle.MEDIUM_DASH_DOT_DOT ) );
  verify( xlsStyle, times( 1 ) ).setLeftBorderColor( eq( (short) 120 ) );
  verify( xlsStyle, times( 1 ) ).setBorderRight( eq( BorderStyle.MEDIUM ) );
  verify( xlsStyle, times( 1 ) ).setRightBorderColor( eq( (short) 122 ) );
  verify( xlsStyle, times( 1 ) ).setFillForegroundColor( eq( (short) 123 ) );
  verify( xlsStyle, times( 1 ) ).setFillPattern( eq( FillPatternType.SOLID_FOREGROUND ) );
}
 
Example #8
Source File: Style.java    From java-master with Apache License 2.0 6 votes vote down vote up
Style(String fontName, int fontColor, boolean fontBold, int fontUnderline, boolean fontItalic, int fontHeightInPoints,
      int foregroundColor, int backgroundColor, boolean needLeftBorder, boolean needRightBorder, boolean needTopBorder,
      boolean needBottomBorder, int borderColor, BorderStyle borderWeight, boolean autoLineFeed, HorizontalAlignment alignment,
      VerticalAlignment verticalAlignment, String datePattern, String decimalPattern) {
    this.fontName = fontName;
    this.fontColor = fontColor;
    this.fontBold = fontBold;
    this.fontUnderline = fontUnderline;
    this.fontItalic = fontItalic;
    this.fontHeightInPoints = fontHeightInPoints;
    this.foregroundColor = foregroundColor;
    this.backgroundColor = backgroundColor;
    this.needLeftBorder = needLeftBorder;
    this.needRightBorder = needRightBorder;
    this.needTopBorder = needTopBorder;
    this.needBottomBorder = needBottomBorder;
    this.borderColor = borderColor;
    this.borderWeight = borderWeight;
    this.autoLineFeed = autoLineFeed;
    this.alignment = alignment;
    this.verticalAlignment = verticalAlignment;
    this.datePattern = datePattern;
    this.decimalPattern = decimalPattern;
}
 
Example #9
Source File: ExportTimetableXLS.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected CellStyle getHeaderIntervalStyle(P p) {
	String styleId = "header-interval";
	CellStyle style = iStyles.get(styleId);
	if (style == null) {
		style = iWorkbook.createCellStyle();
        style.setBorderLeft(BorderStyle.THIN);
        style.setLeftBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
        style.setBorderTop(BorderStyle.THIN);
        style.setTopBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
        if (p.getWidth() == 1) {
        	style.setBorderRight(BorderStyle.THIN);
        	style.setRightBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
        }
        style.setFont(getFont(p));
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.TOP);
        style.setWrapText(true);
        iStyles.put(styleId, style);
	}
	return style;
}
 
Example #10
Source File: AnnoFormulaTest.java    From xlsmapper with Apache License 2.0 6 votes vote down vote up
@XlsPostSave
public void handlePostSave(final Sheet sheet) {

    if(!name.equals("平均")) {
        return;
    }

    final Workbook book = sheet.getWorkbook();

    for(Point address : positions.values()) {
        Cell cell = POIUtils.getCell(sheet, address);

        CellStyle style = book.createCellStyle();
        style.cloneStyleFrom(cell.getCellStyle());

        // 塗りつぶし
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        // 罫線の上部を変更
        style.setBorderTop(BorderStyle.DOUBLE);

        cell.setCellStyle(style);
    }

}
 
Example #11
Source File: BorderLeftTest.java    From excel-io with MIT License 5 votes vote down vote up
/**
 * Add left border to cell.
 * @throws IOException If fails
 */
@Test
public void addsLeftBorderToCell() throws IOException {
    try (final Workbook wbook = new XSSFWorkbook()) {
        final CellStyle style = wbook.createCellStyle();
        new BorderLeft(BorderStyle.DASH_DOT).accept(style);
        MatcherAssert.assertThat(
            style.getBorderLeftEnum(),
            Matchers.equalTo(BorderStyle.DASH_DOT)
        );
    }
}
 
Example #12
Source File: StyleUtil.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
/**
 * @param workbook
 * @return
 */
public static CellStyle buildDefaultCellStyle(Workbook workbook) {
    CellStyle newCellStyle = workbook.createCellStyle();
    newCellStyle.setWrapText(true);
    newCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    newCellStyle.setAlignment(HorizontalAlignment.CENTER);
    newCellStyle.setLocked(true);
    newCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    newCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    newCellStyle.setBorderTop(BorderStyle.THIN);
    newCellStyle.setBorderBottom(BorderStyle.THIN);
    newCellStyle.setBorderLeft(BorderStyle.THIN);
    newCellStyle.setBorderRight(BorderStyle.THIN);
    return newCellStyle;
}
 
Example #13
Source File: BorderRightTest.java    From excel-io with MIT License 5 votes vote down vote up
/**
 * Add right border to cell.
 * @throws IOException If fails
 */
@Test
public void addsRightBorderToCell() throws IOException {
    try (final Workbook wbook = new XSSFWorkbook()) {
        final CellStyle style = wbook.createCellStyle();
        new BorderRight(BorderStyle.DASH_DOT).accept(style);
        MatcherAssert.assertThat(
            style.getBorderRightEnum(),
            Matchers.equalTo(BorderStyle.DASH_DOT)
        );
    }
}
 
Example #14
Source File: BorderTopTest.java    From excel-io with MIT License 5 votes vote down vote up
/**
 * Add top border to cell.
 * @throws IOException If fails
 */
@Test
public void addsTopBorderToCell() throws IOException {
    try (final Workbook wbook = new XSSFWorkbook()) {
        final CellStyle style = wbook.createCellStyle();
        new BorderTop(BorderStyle.DASH_DOT).accept(style);
        MatcherAssert.assertThat(
            style.getBorderTopEnum(),
            Matchers.equalTo(BorderStyle.DASH_DOT)
        );
    }
}
 
Example #15
Source File: LinkDefaultCellStyle.java    From myexcel with Apache License 2.0 5 votes vote down vote up
@Override
public CellStyle supply(Workbook workbook) {
    CellStyle linkStyle = workbook.createCellStyle();
    Font linkFont = workbook.createFont();
    linkFont.setUnderline(Font.U_SINGLE);
    linkFont.setColor(IndexedColors.BLUE.getIndex());
    linkStyle.setFont(linkFont);
    linkStyle.setAlignment(HorizontalAlignment.CENTER);
    linkStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    linkStyle.setBorderBottom(BorderStyle.THIN);
    linkStyle.setBorderRight(BorderStyle.THIN);
    linkStyle.setBorderLeft(BorderStyle.THIN);
    linkStyle.setBorderTop(BorderStyle.THIN);
    return linkStyle;
}
 
Example #16
Source File: HSSFCellStyle.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * set the type of border to use for the top border of the cell
 * @param border type
 * @since POI 3.15
 */
@Override
public void setBorderTop(BorderStyle border)
{
    _format.setIndentNotParentBorder(true);
    _format.setBorderTop(border.getCode());
}
 
Example #17
Source File: ThDefaultCellStyle.java    From myexcel with Apache License 2.0 5 votes vote down vote up
@Override
public CellStyle supply(Workbook workbook) {
    CellStyle style = workbook.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setBorderBottom(BorderStyle.THIN);
    style.setBorderRight(BorderStyle.THIN);
    style.setBorderTop(BorderStyle.THIN);
    style.setBorderLeft(BorderStyle.THIN);
    Font font = workbook.createFont();
    font.setBold(true);
    style.setFont(font);
    return style;
}
 
Example #18
Source File: StyleManagerXUtils.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void applyBorderStyle(Workbook workbook, CellStyle style, BorderSide side, CSSValue colour, CSSValue borderStyle, CSSValue width) {
	if( ( colour != null ) || ( borderStyle != null ) || ( width != null ) ) {
		String colourString = colour == null ? "rgb(0,0,0)" : colour.getCssText();
		String borderStyleString = borderStyle == null ? "solid" : borderStyle.getCssText();
		String widthString = width == null ? "medium" : width.getCssText();
		
		if( style instanceof XSSFCellStyle ) {
			XSSFCellStyle xStyle = (XSSFCellStyle)style;
			
			BorderStyle xBorderStyle = poiBorderStyleFromBirt(borderStyleString, widthString);
			XSSFColor xBorderColour = getXColour(colourString);
			if(xBorderStyle != BorderStyle.NONE) {
				switch( side ) {
				case TOP:
					xStyle.setBorderTop(xBorderStyle);
					xStyle.setTopBorderColor(xBorderColour);
					// log.debug( "Top border: " + xStyle.getBorderTop() + " / " + xStyle.getTopBorderXSSFColor().getARGBHex() );
					break;
				case LEFT:
					xStyle.setBorderLeft(xBorderStyle);
					xStyle.setLeftBorderColor(xBorderColour);
					// log.debug( "Left border: " + xStyle.getBorderLeft() + " / " + xStyle.getLeftBorderXSSFColor().getARGBHex() );
					break;
				case RIGHT:
					xStyle.setBorderRight(xBorderStyle);
					xStyle.setRightBorderColor(xBorderColour);
					// log.debug( "Right border: " + xStyle.getBorderRight() + " / " + xStyle.getRightBorderXSSFColor().getARGBHex() );
					break;
				case BOTTOM:
					xStyle.setBorderBottom(xBorderStyle);
					xStyle.setBottomBorderColor(xBorderColour);
					// log.debug( "Bottom border: " + xStyle.getBorderBottom() + " / " + xStyle.getBottomBorderXSSFColor().getARGBHex() );
					break;
				}
			}
		}
	}
}
 
Example #19
Source File: RegionUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the top border style for a region of cells by manipulating the cell style of the individual
 * cells on the top
 * 
 * @param border The new border
 * @param region The region that should have the border
 * @param sheet The sheet that the region is on.
 * @since POI 3.16 beta 1
 */
public static void setBorderTop(BorderStyle border, CellRangeAddress region, Sheet sheet) {
    int colStart = region.getFirstColumn();
    int colEnd = region.getLastColumn();
    int rowIndex = region.getFirstRow();
    CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_TOP, border);
    Row row = CellUtil.getRow(rowIndex, sheet);
    for (int i = colStart; i <= colEnd; i++) {
        cps.setProperty(row, i);
    }
}
 
Example #20
Source File: AbstractConfigFactory.java    From Octopus with MIT License 5 votes vote down vote up
protected BorderStyle[] convertBorder(String border) {
    BorderStyle[] result = new BorderStyle[4];
    String[] split = border.split(",");
    for (int i = 0; i < split.length; i++) {
        short val = Short.parseShort(split[i]);
        BorderStyle style = BorderStyle.valueOf(val);
        result[i] = style;
    }
    return result;
}
 
Example #21
Source File: RegionUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the bottom border style for a region of cells by manipulating the cell style of the individual
 * cells on the bottom
 * 
 * @param border The new border
 * @param region The region that should have the border
 * @param sheet The sheet that the region is on.
 * @since POI 3.16 beta 1
 */
public static void setBorderBottom(BorderStyle border, CellRangeAddress region, Sheet sheet) {
    int colStart = region.getFirstColumn();
    int colEnd = region.getLastColumn();
    int rowIndex = region.getLastRow();
    CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_BOTTOM, border);
    Row row = CellUtil.getRow(rowIndex, sheet);
    for (int i = colStart; i <= colEnd; i++) {
        cps.setProperty(row, i);
    }
}
 
Example #22
Source File: PropertyTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Draws the top border for a range of cells
 * </p>
 * 
 * @param range
 *            - {@link CellRangeAddress} range of cells on which borders are
 *            drawn.
 * @param borderType
 *            - Type of border to draw. {@link BorderStyle}.
 */
private void drawTopBorder(CellRangeAddress range, BorderStyle borderType) {
    int row = range.getFirstRow();
    int firstCol = range.getFirstColumn();
    int lastCol = range.getLastColumn();
    for (int i = firstCol; i <= lastCol; i++) {
        addProperty(row, i, CellUtil.BORDER_TOP, borderType);
        if (borderType == BorderStyle.NONE && row > 0) {
            addProperty(row - 1, i, CellUtil.BORDER_BOTTOM, borderType);
        }
    }
}
 
Example #23
Source File: SpreadsheetCellStyleTest.java    From taro with MIT License 5 votes vote down vote up
@Test
public void SpreadsheetCellStyle_IsImmutable() {
    SpreadsheetCellStyle cellStyle = new SpreadsheetCellStyle();
    assertThat(cellStyle.withBold(true), is(not(cellStyle)));
    assertThat(cellStyle.withDoubleUnderline(true), is(not(cellStyle)));
    assertThat(cellStyle.withFontName("Courier"), is(not(cellStyle)));
    assertThat(cellStyle.withFontOffset(1), is(not(cellStyle)));
    assertThat(cellStyle.withFontSizeInPoints(14), is(not(cellStyle)));
    assertThat(cellStyle.withItalic(true), is(not(cellStyle)));
    assertThat(cellStyle.withStrikeout(true), is(not(cellStyle)));
    assertThat(cellStyle.withUnderline(true), is(not(cellStyle)));

    assertThat(cellStyle.withAlign(HorizontalAlignment.CENTER), is(not(cellStyle)));
    assertThat(cellStyle.withBackgroundColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withBottomBorder(BorderStyle.MEDIUM), is(not(cellStyle)));
    assertThat(cellStyle.withBottomBorderColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withLeftBorder(BorderStyle.MEDIUM), is(not(cellStyle)));
    assertThat(cellStyle.withLeftBorderColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withTopBorder(BorderStyle.MEDIUM), is(not(cellStyle)));
    assertThat(cellStyle.withTopBorderColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withRightBorder(BorderStyle.MEDIUM), is(not(cellStyle)));
    assertThat(cellStyle.withRightBorderColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withDataFormatString("0.00"), is(not(cellStyle)));
    assertThat(cellStyle.withIndention(1), is(not(cellStyle)));
    assertThat(cellStyle.withLocked(true), is(not(cellStyle)));
    assertThat(cellStyle.withRotation(1), is(not(cellStyle)));
    assertThat(cellStyle.withVerticalAlign(VerticalAlignment.TOP), is(not(cellStyle)));
    assertThat(cellStyle.withWrapText(true), is(not(cellStyle)));

    assertThat(cellStyle.copy(), not(sameInstance(cellStyle)));
    assertThat(cellStyle.apply(new SpreadsheetCellStyle()), not(sameInstance(cellStyle)));
}
 
Example #24
Source File: CellStyleContext.java    From ureport with Apache License 2.0 5 votes vote down vote up
private BorderStyle getBorderStyle(Border border){
	if(border.getStyle().equals(com.bstek.ureport.definition.BorderStyle.solid)){
		return BorderStyle.THIN;
	}else if(border.getStyle().equals(com.bstek.ureport.definition.BorderStyle.dashed)){
		return BorderStyle.DASHED;
	}else if(border.getStyle().equals(com.bstek.ureport.definition.BorderStyle.doublesolid)){
		return BorderStyle.DOUBLE;
	}
	return null;
}
 
Example #25
Source File: PropertyTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Draws the right border for a range of cells
 * </p>
 *
 * @param range
 *            - {@link CellRangeAddress} range of cells on which borders are
 *            drawn.
 * @param borderType
 *            - Type of border to draw. {@link BorderStyle}.
 */
private void drawRightBorder(CellRangeAddress range,
        BorderStyle borderType) {
    int firstRow = range.getFirstRow();
    int lastRow = range.getLastRow();
    int col = range.getLastColumn();
    for (int i = firstRow; i <= lastRow; i++) {
        addProperty(i, col, CellUtil.BORDER_RIGHT, borderType);
        if (borderType == BorderStyle.NONE
                && col < SpreadsheetVersion.EXCEL2007.getMaxColumns() - 1) {
            addProperty(i, col + 1, CellUtil.BORDER_LEFT, borderType);
        }
    }
}
 
Example #26
Source File: ExcelCellStyleBuilderTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private CellBackground getBackground() {
  CellBackground bg = mock( CellBackground.class );
  BorderEdge bEdge = new BorderEdge( org.pentaho.reporting.engine.classic.core.style.BorderStyle.WAVE, Color.BLACK, (long) 13 );
  when( bg.getBottom() ).thenReturn( bEdge );
  when( bg.getTop() ).thenReturn( bEdge );
  when( bg.getLeft() ).thenReturn( bEdge );
  when( bg.getRight() ).thenReturn( bEdge );
  when( bg.getBackgroundColor() ).thenReturn( Color.BLACK );
  return bg;
}
 
Example #27
Source File: RegionUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the right border style for a region of cells by manipulating the cell style of the individual
 * cells on the right
 * 
 * @param border The new border
 * @param region The region that should have the border
 * @param sheet The sheet that the region is on.
 * @since POI 3.16 beta 1
 */
public static void setBorderRight(BorderStyle border, CellRangeAddress region, Sheet sheet) {
    int rowStart = region.getFirstRow();
    int rowEnd = region.getLastRow();
    int column = region.getLastColumn();

    CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_RIGHT, border);
    for (int i = rowStart; i <= rowEnd; i++) {
        cps.setProperty(CellUtil.getRow(i, sheet), column);
    }
}
 
Example #28
Source File: PropertyTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <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);
    }
}
 
Example #29
Source File: PropertyTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <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);
    }
}
 
Example #30
Source File: RegionUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the left border style for a region of cells by manipulating the cell style of the individual
 * cells on the left
 * 
 * @param border The new border
 * @param region The region that should have the border
 * @param sheet The sheet that the region is on.
 * @since POI 3.16 beta 1
 */
public static void setBorderLeft(BorderStyle border, CellRangeAddress region, Sheet sheet) {
    int rowStart = region.getFirstRow();
    int rowEnd = region.getLastRow();
    int column = region.getFirstColumn();

    CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_LEFT, border);
    for (int i = rowStart; i <= rowEnd; i++) {
        cps.setProperty(CellUtil.getRow(i, sheet), column);
    }
}