Java Code Examples for org.apache.poi.hssf.usermodel.HSSFCellStyle#setBorderTop()
The following examples show how to use
org.apache.poi.hssf.usermodel.HSSFCellStyle#setBorderTop() .
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: POIUtils.java From ermasterr with Apache License 2.0 | 7 votes |
public static HSSFCellStyle copyCellStyle(final HSSFWorkbook workbook, final HSSFCellStyle style) { final HSSFCellStyle newCellStyle = workbook.createCellStyle(); newCellStyle.setAlignment(style.getAlignment()); newCellStyle.setBorderBottom(style.getBorderBottom()); newCellStyle.setBorderLeft(style.getBorderLeft()); newCellStyle.setBorderRight(style.getBorderRight()); newCellStyle.setBorderTop(style.getBorderTop()); newCellStyle.setBottomBorderColor(style.getBottomBorderColor()); newCellStyle.setDataFormat(style.getDataFormat()); newCellStyle.setFillBackgroundColor(style.getFillBackgroundColor()); newCellStyle.setFillForegroundColor(style.getFillForegroundColor()); newCellStyle.setFillPattern(style.getFillPattern()); newCellStyle.setHidden(style.getHidden()); newCellStyle.setIndention(style.getIndention()); newCellStyle.setLeftBorderColor(style.getLeftBorderColor()); newCellStyle.setLocked(style.getLocked()); newCellStyle.setRightBorderColor(style.getRightBorderColor()); newCellStyle.setRotation(style.getRotation()); newCellStyle.setTopBorderColor(style.getTopBorderColor()); newCellStyle.setVerticalAlignment(style.getVerticalAlignment()); newCellStyle.setWrapText(style.getWrapText()); final HSSFFont font = workbook.getFontAt(style.getFontIndex()); newCellStyle.setFont(font); return newCellStyle; }
Example 2
Source File: TableSheetGenerator.java From ermasterr with Apache License 2.0 | 6 votes |
private HSSFCellStyle createMatrixCellStyle(final HSSFWorkbook workbook, final HSSFCellStyle matrixHeaderTemplateCellStyle, final boolean top, final boolean right, final boolean bottom, final boolean left) { final HSSFCellStyle cellStyle = POIUtils.copyCellStyle(workbook, matrixHeaderTemplateCellStyle); if (top) { cellStyle.setBorderTop(CellStyle.BORDER_THIN); } if (right) { cellStyle.setBorderRight(CellStyle.BORDER_THIN); } if (bottom) { cellStyle.setBorderBottom(CellStyle.BORDER_THIN); } if (left) { cellStyle.setBorderLeft(CellStyle.BORDER_THIN); } return cellStyle; }
Example 3
Source File: ExcelTempletService.java From jeewx with Apache License 2.0 | 6 votes |
/** * exce表头单元格样式处理 * @param workbook * @return */ public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle titleStyle = workbook.createCellStyle(); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE); // 设置边框样式 titleStyle.setBorderLeft((short) 2); // 左边框 titleStyle.setBorderRight((short) 2); // 右边框 titleStyle.setBorderTop((short) 2); // 左边框 titleStyle.setBorderBottom((short) 2); // 右边框 titleStyle.setBorderTop(HSSFCellStyle.BORDER_DOUBLE); // 顶边框 titleStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index); // 填充的背景颜色 titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案 return titleStyle; }
Example 4
Source File: ExcelTempletService.java From jeecg with Apache License 2.0 | 6 votes |
/** * exce表头单元格样式处理 * @param workbook * @return */ public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle titleStyle = workbook.createCellStyle(); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE); // 设置边框样式 titleStyle.setBorderLeft((short) 2); // 左边框 titleStyle.setBorderRight((short) 2); // 右边框 titleStyle.setBorderTop((short) 2); // 左边框 titleStyle.setBorderBottom((short) 2); // 右边框 titleStyle.setBorderTop(HSSFCellStyle.BORDER_DOUBLE); // 顶边框 titleStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index); // 填充的背景颜色 titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案 return titleStyle; }
Example 5
Source File: TableSheetGenerator.java From ermaster-b with Apache License 2.0 | 6 votes |
private HSSFCellStyle createMatrixCellStyle(HSSFWorkbook workbook, HSSFCellStyle matrixHeaderTemplateCellStyle, boolean top, boolean right, boolean bottom, boolean left) { HSSFCellStyle cellStyle = POIUtils.copyCellStyle(workbook, matrixHeaderTemplateCellStyle); if (top) { cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); } if (right) { cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); } if (bottom) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); } if (left) { cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); } return cellStyle; }
Example 6
Source File: ExcelTempletService.java From jeecg with Apache License 2.0 | 5 votes |
public static HSSFCellStyle getOneStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle style = workbook.createCellStyle(); style.setBorderLeft((short) 1); // 左边框 style.setBorderRight((short) 1); // 右边框 style.setBorderBottom((short) 1); style.setBorderTop((short) 1); return style; }
Example 7
Source File: CommonExcelServiceImpl.java From jeecg with Apache License 2.0 | 5 votes |
public static HSSFCellStyle getOneStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle style = workbook.createCellStyle(); style.setBorderLeft((short) 1); // 左边框 style.setBorderRight((short) 1); // 右边框 style.setBorderBottom((short) 1); style.setBorderTop((short) 1); return style; }
Example 8
Source File: ExcelTempletService.java From jeecg with Apache License 2.0 | 5 votes |
public static HSSFCellStyle getTwoStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle style = workbook.createCellStyle(); style.setBorderLeft((short) 1); // 左边框 style.setBorderRight((short) 1); // 右边框 style.setBorderBottom((short) 1); style.setBorderTop((short) 1); style.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); // 填充的背景颜色 style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案 return style; }
Example 9
Source File: POIUtils.java From ermaster-b with Apache License 2.0 | 5 votes |
public static HSSFCellStyle copyCellStyle(HSSFWorkbook workbook, HSSFCellStyle style) { HSSFCellStyle newCellStyle = workbook.createCellStyle(); newCellStyle.setAlignment(style.getAlignment()); newCellStyle.setBorderBottom(style.getBorderBottom()); newCellStyle.setBorderLeft(style.getBorderLeft()); newCellStyle.setBorderRight(style.getBorderRight()); newCellStyle.setBorderTop(style.getBorderTop()); newCellStyle.setBottomBorderColor(style.getBottomBorderColor()); newCellStyle.setDataFormat(style.getDataFormat()); newCellStyle.setFillBackgroundColor(style.getFillBackgroundColor()); newCellStyle.setFillForegroundColor(style.getFillForegroundColor()); newCellStyle.setFillPattern(style.getFillPattern()); newCellStyle.setHidden(style.getHidden()); newCellStyle.setIndention(style.getIndention()); newCellStyle.setLeftBorderColor(style.getLeftBorderColor()); newCellStyle.setLocked(style.getLocked()); newCellStyle.setRightBorderColor(style.getRightBorderColor()); newCellStyle.setRotation(style.getRotation()); newCellStyle.setTopBorderColor(style.getTopBorderColor()); newCellStyle.setVerticalAlignment(style.getVerticalAlignment()); newCellStyle.setWrapText(style.getWrapText()); HSSFFont font = workbook.getFontAt(style.getFontIndex()); newCellStyle.setFont(font); return newCellStyle; }
Example 10
Source File: ExcelExportUtil.java From jeewx with Apache License 2.0 | 5 votes |
public static HSSFCellStyle getOneStyle(HSSFWorkbook workbook, boolean isWarp) { HSSFCellStyle style = workbook.createCellStyle(); style.setBorderLeft((short) 1); // 左边框 style.setBorderRight((short) 1); // 右边框 style.setBorderBottom((short) 1); style.setBorderTop((short) 1); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); if(isWarp){style.setWrapText(true);} return style; }
Example 11
Source File: ExcelExportUtil.java From jeewx with Apache License 2.0 | 5 votes |
public static HSSFCellStyle getTwoStyle(HSSFWorkbook workbook, boolean isWarp) { HSSFCellStyle style = workbook.createCellStyle(); style.setBorderLeft((short) 1); // 左边框 style.setBorderRight((short) 1); // 右边框 style.setBorderBottom((short) 1); style.setBorderTop((short) 1); style.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); // 填充的背景颜色 style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案 style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); if(isWarp){style.setWrapText(true);} return style; }
Example 12
Source File: CommonExcelServiceImpl.java From jeecg with Apache License 2.0 | 5 votes |
/** * exce表头单元格样式处理 * @param workbook * @return */ public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle titleStyle = workbook.createCellStyle(); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); // 左边框 titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); // 右边框 titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 底边框 titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); // 顶边框 titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); // 填充的背景颜色 titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案 return titleStyle; }
Example 13
Source File: CgReportExcelServiceImpl.java From jeewx with Apache License 2.0 | 5 votes |
public static HSSFCellStyle getTwoStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle style = workbook.createCellStyle(); style.setBorderLeft((short) 1); // 左边框 style.setBorderRight((short) 1); // 右边框 style.setBorderBottom((short) 1); style.setBorderTop((short) 1); style.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); // 填充的背景颜色 style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案 return style; }
Example 14
Source File: CgReportExcelServiceImpl.java From jeewx with Apache License 2.0 | 5 votes |
/** * exce表头单元格样式处理 * @param workbook * @return */ public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle titleStyle = workbook.createCellStyle(); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); // 左边框 titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); // 右边框 titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 底边框 titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); // 顶边框 titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); // 填充的背景颜色 titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案 return titleStyle; }
Example 15
Source File: ExcelTempletService.java From jeewx with Apache License 2.0 | 5 votes |
public static HSSFCellStyle getOneStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle style = workbook.createCellStyle(); style.setBorderLeft((short) 1); // 左边框 style.setBorderRight((short) 1); // 右边框 style.setBorderBottom((short) 1); style.setBorderTop((short) 1); return style; }
Example 16
Source File: ExcelTempletService.java From jeewx with Apache License 2.0 | 5 votes |
public static HSSFCellStyle getTwoStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle style = workbook.createCellStyle(); style.setBorderLeft((short) 1); // 左边框 style.setBorderRight((short) 1); // 右边框 style.setBorderBottom((short) 1); style.setBorderTop((short) 1); style.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); // 填充的背景颜色 style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案 return style; }
Example 17
Source File: CommonExcelServiceImpl.java From jeecg with Apache License 2.0 | 5 votes |
public static HSSFCellStyle getTwoStyle(HSSFWorkbook workbook) { // 产生Excel表头 HSSFCellStyle style = workbook.createCellStyle(); style.setBorderLeft((short) 1); // 左边框 style.setBorderRight((short) 1); // 右边框 style.setBorderBottom((short) 1); style.setBorderTop((short) 1); style.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); // 填充的背景颜色 style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案 return style; }
Example 18
Source File: PoiExport.java From hrms with Apache License 2.0 | 4 votes |
public InputStream exportExcel(String fileName, String[] headTitle, List<String> list) throws IOException { Workbook wb = new HSSFWorkbook(); //FileOutputStream fileOut = new FileOutputStream(fileName); HSSFCellStyle style = (HSSFCellStyle) wb.createCellStyle(); // 设置这些样式 style.setFillForegroundColor(HSSFColor.SKY_BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 生成一个字体 HSSFFont font = (HSSFFont) wb.createFont(); font.setColor(HSSFColor.VIOLET.index); font.setFontHeightInPoints((short) 12); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 把字体应用到当前的样式 style.setFont(font); // 创建工作簿 Sheet sheet = wb.createSheet("sheet1"); // sheet.setDefaultColumnWidth((short)15); // 创建头部 Row row = sheet.createRow((short) 0); for (int i = 0; i < headTitle.length; i++) { row.createCell(i).setCellValue(headTitle[i]); } // 填充数据 for (int i = 0; i < list.size(); i++) { Row r = sheet.createRow((short) (i + 1)); String[] strArray = list.get(i).split(","); for (int j = 0; j < headTitle.length; j++) { r.createCell(j).setCellValue(strArray[j]); if (strArray[j].length()>3) { sheet.setColumnWidth((short)j, 5000); } } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { wb.write(baos); } catch (IOException e) { e.printStackTrace(); } byte[] ba = baos.toByteArray(); ByteArrayInputStream excelStream = new ByteArrayInputStream(ba); return excelStream; }
Example 19
Source File: StyleManagerHUtils.java From birt with Eclipse Public License 1.0 | 4 votes |
@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 HSSFCellStyle ) { HSSFCellStyle hStyle = (HSSFCellStyle)style; short hBorderStyle = poiBorderStyleFromBirt(borderStyleString, widthString); short colourIndex = getHColour((HSSFWorkbook)workbook, colourString); if( colourIndex > 0 ) { if(hBorderStyle != CellStyle.BORDER_NONE) { switch( side ) { case TOP: hStyle.setBorderTop(hBorderStyle); hStyle.setTopBorderColor(colourIndex); // log.debug( "Top border: " + xStyle.getBorderTop() + " / " + xStyle.getTopBorderXSSFColor().getARGBHex() ); break; case LEFT: hStyle.setBorderLeft(hBorderStyle); hStyle.setLeftBorderColor(colourIndex); // log.debug( "Left border: " + xStyle.getBorderLeft() + " / " + xStyle.getLeftBorderXSSFColor().getARGBHex() ); break; case RIGHT: hStyle.setBorderRight(hBorderStyle); hStyle.setRightBorderColor(colourIndex); // log.debug( "Right border: " + xStyle.getBorderRight() + " / " + xStyle.getRightBorderXSSFColor().getARGBHex() ); break; case BOTTOM: hStyle.setBorderBottom(hBorderStyle); hStyle.setBottomBorderColor(colourIndex); // log.debug( "Bottom border: " + xStyle.getBorderBottom() + " / " + xStyle.getBottomBorderXSSFColor().getARGBHex() ); break; } } } } } }
Example 20
Source File: AbstractSheetGenerator.java From ermaster-b with Apache License 2.0 | 4 votes |
protected ColumnTemplate loadColumnTemplate(HSSFWorkbook workbook, HSSFSheet templateSheet, CellLocation location) { if (location == null) { return null; } ColumnTemplate columnTemplate = new ColumnTemplate(); HSSFRow row = templateSheet.getRow(location.r); HSSFRow bottomRow = templateSheet.getRow(location.r + 1); for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) { HSSFCell cell = row.getCell(colNum); if (cell != null) { columnTemplate.columnTemplateMap.put(colNum, cell .getRichStringCellValue().getString()); } } columnTemplate.topRowCellStyleList = POIUtils.copyCellStyle(workbook, row); columnTemplate.middleRowCellStyleList = POIUtils.copyCellStyle( workbook, row); columnTemplate.bottomRowCellStyleList = POIUtils.copyCellStyle( workbook, row); for (short i = 0; i < columnTemplate.middleRowCellStyleList.size(); i++) { HSSFCellStyle middleRowCellStyle = columnTemplate.middleRowCellStyleList .get(i); if (middleRowCellStyle != null) { HSSFCellStyle topRowCellStyle = columnTemplate.topRowCellStyleList .get(i); HSSFCellStyle bottomRowCellStyle = columnTemplate.bottomRowCellStyleList .get(i); HSSFCell bottomCell = bottomRow.getCell(row.getFirstCellNum() + i); topRowCellStyle.setBorderBottom(bottomCell.getCellStyle() .getBorderTop()); middleRowCellStyle.setBorderTop(bottomCell.getCellStyle() .getBorderTop()); middleRowCellStyle.setBorderBottom(bottomCell.getCellStyle() .getBorderTop()); bottomRowCellStyle.setBorderTop(bottomCell.getCellStyle() .getBorderTop()); bottomRowCellStyle.setBorderBottom(bottomCell.getCellStyle() .getBorderBottom()); } } return columnTemplate; }