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
I need to check whether B3 Cell text is strike through or not.
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:
- Get the
XSSFRichTextString
from the cell usingXSSFCell#getRichStringCellValue()
- Get the
XSSFFont
at a specific position usingXSSFRichTextString#getFontAtIndex(int index)
- Check the font using
XSSFFont#getStrikeout()
Not sure how you get a reference to it but there's HSSFont.getStrikeout() and XSSFFont.getStrikeout()
来源:https://stackoverflow.com/questions/40037299/how-to-check-a-cell-text-is-strikethrough-or-not-in-xlsx-file-using-apache-poi