在poi里面 已经设置好了excel 头部名与列名!怎么设置边框与颜色!

在poi里面 已经设置好了excel 头部名与列名!怎么设置边框与颜色!,第1张

给段代码参考一下:

//设置字体

HSSFFont font = workbook.createFont()

font.setFontName("Arial Narrow")

font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD)

font.setFontHeightInPoints((short) 12)

HSSFCellStyle style1 = workbook.createCellStyle()//设置样式

// 设置边框

style1.setBorderRight(HSSFCellStyle.BORDER_MEDIUM)

style1.setFont(font)// 设置字体

cell1.setCellStyle(style1)//使用样式设置

在样式里可以设置边框和背景色,自己试试,找需要的吧

//poi-3.7.jar

/**

* 合并单元格处理--加入list

*

* @param sheet

* @return

*/

public void getCombineCell(HSSFSheet sheet, List<CellRangeAddress>list) {

// 获得一个 sheet 中合并单元格的数量

int sheetmergerCount = sheet.getNumMergedRegions()

// 遍历合并单元格

for (int i = 0i <sheetmergerCounti++) {

// 获得合并单元格加入list中

CellRangeAddress ca = sheet.getMergedRegion(i)

list.add(ca)

}

}

/**

* 判断单元格是否为合并单元格

*

* @param listCombineCell

* 存放合并单元格的list

* @param cell

* 需要判断的单元格

* @param sheet

* sheet

* @return

*/

public static Boolean isCombineCell(List<CellRangeAddress>listCombineCell,

HSSFCell cell, HSSFSheet sheet) {

int firstC = 0

int lastC = 0

int firstR = 0

int lastR = 0

for (CellRangeAddress ca : listCombineCell) {

// 获得合并单元格的起始行, 结束行, 起始列, 结束列

firstC = ca.getFirstColumn()

lastC = ca.getLastColumn()

firstR = ca.getFirstRow()

lastR = ca.getLastRow()

if (cell.getColumnIndex() <= lastC&&cell.getColumnIndex()>= firstC) {

if (cell.getRowIndex() <= lastR &&cell.getRowIndex() >= firstR) {

return true

}

}

}

return false

}

}

分享


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11595065.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存