protected XSSFColor extractColor(XSSFCell cell, XSSFColor... acceptableColors) { XSSFCellStyle cellStyle = cell.getCellStyle(); FillPatternType fillPattern = cellStyle.getFillPatternEnum(); if (fillPattern == null || fillPattern == FillPatternType.NO_FILL) { return null; } if (fillPattern != FillPatternType.SOLID_FOREGROUND) { throw new IllegalStateException(currentPosition() + ": The fill pattern (" + fillPattern + ") should be either " + FillPatternType.NO_FILL + " or " + FillPatternType.SOLID_FOREGROUND + "."); } XSSFColor color = cellStyle.getFillForegroundColorColor(); for (XSSFColor acceptableColor : acceptableColors) { if (acceptableColor.equals(color)) { return acceptableColor; } } throw new IllegalStateException(currentPosition() + ": The fill color (" + color + ") is not one of the acceptableColors (" + Arrays.toString(acceptableColors) + ")."); } }
XSSFCell cell = ... if (IndexedColors.WHITE.getIndex() == cell.getCellStyle().getFont().getColor()) { ... }
public static double getCellWidth(XSSFCell cell, String value) { return cell.getCellStyle().getWrapText() ? 2 : value.length() + 2; } }
private static XSSFColor getCellColor(XSSFCell cell) { return cell.getCellStyle().getFillForegroundXSSFColor(); }
public boolean isWrapped() { return cell.getCellStyle().getWrapText(); }
private boolean isWrapped(XSSFCell cell) { return cell.getCellStyle().getWrapText(); }
public XSSFCellStyle getCellStyle() { return getCell().getCellStyle(); }
XSSFRow myRow = (XSSFRow) rowIter.next(); Iterator cellIter = myRow.cellIterator(); List cellRowList = new ArrayList(); while (cellIter.hasNext()) { XSSFCell originalCell = (XSSFCell) cellIter.next(); XSSFCell myCell = originalCell; try { // XSSFCell newCell = myCell; //( How to clone or copy a new one) XSSFCellStyle style = workbook.createCellStyle(); // the XSSFWorkbook from which you clone style.cloneStyleFrom(originalCell.getCellStyle()); myCell.setCellStyle(style); } catch (Exception e) { syso(e); } }
public Alignment determineAlignment(Object value, XSSFCell cell) { return getAlignmentFinder().determineAlignment(value, cell.getCellStyle()); } }
/** * Checks if cell font family matches. */ private void isCellFontFamilyMatches(Locator loc1, Locator loc2) { // TODO: Check for NPEs if (!(loc1.cell instanceof XSSFCell)) return; String family1 = ((XSSFCell)loc1.cell).getCellStyle().getFont().getFontName(); String family2 = ((XSSFCell)loc2.cell).getCellStyle().getFont().getFontName(); if (!family1.equals(family2)) { addMessage(loc1, loc2, "Cell Font Family does not Match ::", family1, family2); } }
public byte getUnderline() { return cell.getCellStyle().getFont().getUnderline(); }
/** * Checks if cell font size matches. */ private void isCellFontSizeMatches(Locator loc1, Locator loc2) { if (!(loc1.cell instanceof XSSFCell)) return; short size1 = ((XSSFCell)loc1.cell).getCellStyle().getFont().getFontHeightInPoints(); short size2 = ((XSSFCell)loc2.cell).getCellStyle().getFont().getFontHeightInPoints(); if (size1 != size2) { addMessage(loc1, loc2, "Cell Font Size does not Match ::", Short.toString(size1), Short.toString(size2) ); } }
/** * Checks if cell font italics matches. */ private void isCellFontItalicsMatches(Locator loc1, Locator loc2) { if (!(loc1.cell instanceof XSSFCell)) return; boolean b1 = ((XSSFCell)loc1.cell).getCellStyle().getFont().getItalic(); boolean b2 = ((XSSFCell)loc2.cell).getCellStyle().getFont().getItalic(); if (b1 != b2) { addMessage(loc1, loc2, CELL_FONT_ATTRIBUTES_DOES_NOT_MATCH, (b1 ? "" : "NOT ")+"ITALICS", (b2 ? "" : "NOT ")+"ITALICS" ); } }
public int findFontSize() { return getCell().getCellStyle().getFont().getFontHeightInPoints(); }
public PDFont getFont() { return PDFHelper.findFont(getCell().getCellStyle().getFont()); }
public Color getTextColor() { XSSFColor color = getCell().getCellStyle().getFont().getXSSFColor(); return color == null ? Color.BLACK : getColorHelper().getAwtColor(color); }
public float getMaxFontHeight() { return findMaxFontHeight(getFont(), getCell().getCellStyle().getFont().getFontHeightInPoints()); }
public float findTextLength(String value) { short fontHeightInPoints = getCell().getCellStyle().getFont().getFontHeightInPoints(); float length; try { length = getFont().getStringWidth(value) / 1000 * fontHeightInPoints; } catch (IOException e) { throw new ReportException(e); } return length; }
@Override protected void drawBorders(RenderingContext context) { PdfContext pdfContext = context.getPdfContext(); if (node.isMerged(pdfContext)) { XSSFCell otherCell = getRegionBottomRightCell(pdfContext); drawBorders(pdfContext, otherCell.getCellStyle()); drawBorders(pdfContext, node.getCellStyle()); } }
public PdfCellNode(XSSFSheet sheet, XSSFCell cell, XLSXExpression expr) { super(sheet, cell, expr); excelWidth = sheet.getColumnWidth(cell.getColumnIndex()); colRef = CellReference.convertNumToColString(cell.getColumnIndex()); int rowIndex = getCell().getRowIndex(); int rowRef = rowIndex + 1; absoluteRef = colRef + rowRef; verticalRange = new SimpleRange(rowIndex, rowIndex); horizontalAlignment = Alignment.LEFT; verticalAlignment = getCell().getCellStyle().getVerticalAlignment(); }