1

使用Java和Hssf获取Excel数据,如何检查单元格是否加粗?我正在遍历 Excel 工作簿的所有工作表、所有行和所有单元格。如果单元格为粗体,我想执行一个操作。

//Iterate through excel sheets    
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
    HSSFSheet excelSheet = workbook.getSheetAt(i);
    HSSFRow row;
    Iterator rows = excelSheet.rowIterator();

    //Iterate through rows        
    while (rows.hasNext()) {
        row = (HSSFRow) rows.next();
        HSSFCell cell;
        Iterator cells = row.cellIterator();

        //Iterate through cells            
        while (cells.hasNext()) {
            cell = (HSSFCell) cells.next();

            //If cell contains all bolded text
            //DO Something
        }
    }
}
4

1 回答 1

1

好的,这就是你可以使用它的方式:

//Iterate through cells            
  while (cells.hasNext()) {
        cell = (HSSFCell) cells.next();
        HSSFCellStyle style = (HSSFCellStyle) cell.getCellStyle();
        HSSFFont font = style.getFont(workbook);
        boolean isBold = font.getBold();
        System.out.println("Cell value : " + cell + ". Is bold? - " + isBold);
  }
于 2016-05-22T23:28:02.457 回答