List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook getFontAt
@Override public XSSFFont getFontAt(int idx)
From source file:ru.icc.cells.ssdc.DataLoader.java
License:Apache License
private boolean hasSuperscriptText(Cell excelCell) { if (excelCell.getCellType() != Cell.CELL_TYPE_STRING) return false; RichTextString richTextString = excelCell.getRichStringCellValue(); if (null == richTextString) return false; int index = 0; int length = 0; XSSFFont font = null;/* w w w .j a va 2s. c o m*/ XSSFRichTextString rts = (XSSFRichTextString) richTextString; XSSFWorkbook wb = (XSSFWorkbook) workbook; XSSFCellStyle style = ((XSSFCell) excelCell).getCellStyle(); font = style.getFont(); String richText = rts.getString(); if (rts.numFormattingRuns() > 1) { for (int i = 0; i < rts.numFormattingRuns(); i++) { index = rts.getIndexOfFormattingRun(i); length = rts.getLengthOfFormattingRun(i); try { font = rts.getFontOfFormattingRun(i); } catch (NullPointerException e) { font = wb.getFontAt(XSSFFont.DEFAULT_CHARSET); font.setTypeOffset(XSSFFont.SS_NONE); } String s = richText.substring(index, index + length); if (font.getTypeOffset() == XSSFFont.SS_SUPER) return true; } } else { if (font.getTypeOffset() == XSSFFont.SS_SUPER) return true; } return false; }
From source file:ru.icc.cells.ssdc.DataLoader.java
License:Apache License
private String getNotSuperscriptText(Cell excelCell) { if (excelCell.getCellType() != Cell.CELL_TYPE_STRING) return null; RichTextString richTextString = excelCell.getRichStringCellValue(); if (null == richTextString) return null; int index;/*from w ww . j a va 2 s . c om*/ int length; String text; XSSFRichTextString rts = (XSSFRichTextString) richTextString; XSSFWorkbook wb = (XSSFWorkbook) workbook; XSSFCellStyle style = ((XSSFCell) excelCell).getCellStyle(); XSSFFont font = style.getFont(); String richText = rts.getString(); StringBuilder notSuperscriptRuns = new StringBuilder(); if (rts.numFormattingRuns() > 1) { boolean wasNotSuperscriptRun = false; for (int i = 0; i < rts.numFormattingRuns(); i++) { index = rts.getIndexOfFormattingRun(i); length = rts.getLengthOfFormattingRun(i); try { font = rts.getFontOfFormattingRun(i); } catch (NullPointerException e) { font = wb.getFontAt(XSSFFont.DEFAULT_CHARSET); font.setTypeOffset(XSSFFont.SS_NONE); } String s = richText.substring(index, index + length); if (font.getTypeOffset() == XSSFFont.SS_SUPER) { if (wasNotSuperscriptRun) notSuperscriptRuns.append(" "); wasNotSuperscriptRun = false; } else { notSuperscriptRuns.append(s); wasNotSuperscriptRun = true; } } text = notSuperscriptRuns.toString(); } else { if (font.getTypeOffset() == XSSFFont.SS_SUPER) text = null; else text = richText; } return text; }