Example code for your XLSX file, Test6.xlsx.

  File fis = new File("/path/to/Test6.xlsx");
  OPCPackage opcPackage = OPCPackage.open(fis.getAbsolutePath());
  XSSFWorkbook wookbook = new XSSFWorkbook(opcPackage);
  XSSFSheet sheet = wookbook.getSheetAt(0);

  CellReference a1 = new CellReference("A1");
  XSSFCell a1Cell = sheet.getRow(a1.getRow()).getCell(a1.getCol());

  // "Hello" has formatting applied at the cell level.
  XSSFCellStyle a1Style = a1Cell.getCellStyle();
  XSSFFont a1Font = wookbook.getFontAt(a1Style.getFontIndex());
  System.out.println(a1Font.getBold());    // true
  System.out.println(a1Font.getItalic());  // true

  // "World" has formatting applied at the rich text string level.
  XSSFRichTextString value = a1Cell.getRichStringCellValue();
  XSSFFont rtfFont = value.getFontAtIndex(7);
  System.out.println(rtfFont.getBold());   // false
  System.out.println(rtfFont.getItalic()); // false

Ryo Yamamoto

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to