How to check a cell text is strikethrough or not i

2019-03-22 08:34发布

I need to check the text format of a cell in .xlsx file (Microsoft Excel file) is strike through or not using Apache POI libraries.

Look following Image

Please Check this image !

I need to check whether B3 Cell text is strike through or not.

3条回答
淡お忘
2楼-- · 2019-03-22 08:38

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); 
查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-22 08:40

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()
查看更多
▲ chillily
4楼-- · 2019-03-22 08:57

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

查看更多
登录 后发表回答