java鼠标变粗怎么办_java – 使用Apache POI使整行变粗

像这样的东西可以用你所拥有的东西:

public static void makeRowBold(Workbook wb,Row row){

CellStyle style = wb.createCellStyle();//Create style

Font font = wb.createFont();//Create font

font.setBold(true);//Make font bold

style.setFont(font);//set it to bold

for(int i = 0; i < row.getLastCellNum(); i++){//For each cell in the row

row.getCell(i).setCellStyle(style);//Set the style

}

}

它基本上遍历传入的行中的每个单元格,将样式设置为粗体.应该导致整行被设置为所需的样式.

祝好运!

编辑

一个更完整的例子:

public static void main(String[] args) {

Path myFile = Paths.get(System.getProperty("user.home"),"Desktop","tester.xlsx");

try {

XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(myFile.toFile()));

XSSFSheet sheet = wb.getSheetAt(0);

makeRowBold(wb,sheet.getRow(0));

wb.write(new FileOutputStream(myFile.toFile()));

} catch (IOException e) {

e.printStackTrace();

}

}

public static void makeRowBold(Workbook wb,Row row){

CellStyle style = wb.createCellStyle();//Create style

Font font = wb.createFont();//Create font

font.setBold(true);//Make font bold

style.setFont(font);//set it to bold

for(int i = 0; i < row.getLastCellNum(); i++){//For each cell in the row

row.getCell(i).setCellStyle(style);//Set the sty;e

}

}

这是在xlsx文件上测试的,数据在第1行,结果文件后面有粗体数据.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值