How to check a cell text is strikethrough or not in .xlsx file using apache poi

十年热恋 提交于 2019-12-03 08:59:26

Finally I found a way to do this, code as follow

//Using workbook
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("abc.xlsx")));
//Getting first sheet
XSSFSheet sheet = workbook.getSheetAt(0);
//Checking A1 cell that strikethrough or not
boolean strikeOutStatus=sheet.getRow(0).getCell(0).getCellStyle().getFont().getStrikeout();
System.out.println(strikeOutStatus); 

Like this:

  1. Get the XSSFRichTextString from the cell using XSSFCell#getRichStringCellValue()
  2. Get the XSSFFont at a specific position using XSSFRichTextString#getFontAtIndex(int index)
  3. Check the font using XSSFFont#getStrikeout()

Not sure how you get a reference to it but there's HSSFont.getStrikeout() and XSSFFont.getStrikeout()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!