easyexcel poi 指定行指定列设置样式

easyexcel poi 指定行指定列设置样式

  • 1.给指定行指定列设置字体及居中
  • 2.给指定行指定列设置边框

1.给指定行指定列设置字体及居中

/**
* 给指定行指定列设置字体及居中
* @param workbook
* @param rowIndex 第几行
* @param columnIndex 第几列
*/
private void setFontAlign(Workbook workbook,int rowIndex,int columnIndex){
    Sheet sheet = workbook.getSheet("sheet1");
    CellStyle cellStyle = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setBold(true);
    cellStyle.setFont(font);
    cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平对齐居中
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直对齐在单元格的高度上居中

    Row row = sheet.getRow(rowIndex);
    Cell cell = row.getCell(columnIndex);
    cell.setCellStyle(cellStyle);
}

2.给指定行指定列设置边框

/**
 * 给指定行指定列设置边框
 * @param workbook
 * @param rowIndex 第几行
* @param columnIndex 第几列
*/
private void setBorder(Workbook workbook,int rowIndex,int columnIndex){
    Sheet sheet = workbook.getSheet("sheet1");

    CellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平对齐居中
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直对齐在单元格的高度上居中
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setBorderTop(BorderStyle.THIN);

    Row row = sheet.getRow(rowIndex);
    Cell cell = row.getCell(columnIndex);
    cell.setCellStyle(cellStyle);
}

你可能感兴趣的:(easyexcel,spring,boot,java,spring,excel,easyui)