public StyleVO(HSSFCellStyle style, Workbook workbook) { alignment = style.getAlignment(); borderBottom = style.getBorderBottom(); borderLeft = style.getBorderLeft(); borderRight = style.getBorderRight(); borderTop = style.getBorderTop(); bottomBorderColor = style.getBottomBorderColor(); dataFormat = style.getDataFormat(); fillBackgroundColor = style.getFillBackgroundColor(); fillForegroundColor = style.getFillForegroundColor(); fillPattern = style.getFillPattern(); fontIndex = style.getFontIndex(); hidden = style.getHidden(); indention = style.getIndention(); leftBorderColor = style.getLeftBorderColor(); locked = style.getLocked(); rightBorderColor = style.getRightBorderColor(); rotation = style.getRotation(); topBorderColor = style.getTopBorderColor(); verticalAlignment = style.getVerticalAlignment(); wrapText = style.getWrapText(); fontVal = new FontVO(style.getFont(workbook)); }
/** * Создает новый стиль в документе Excel который полностью копирует свойства некоторого исходного * стиля этого же документа. Данный метод используется для того чтобы в последствии поменять в * новом стиле один или несколько свойств не затрагивая при этом свойства исходного стиля. * * @param wb документ Excel. * @param src стиль ячейки взятый в качестве шаблона. * @return созданная копия исходного стиля в этом же документе. */ public static HSSFCellStyle copyStyle(final HSSFWorkbook wb, final HSSFCellStyle src) { final HSSFCellStyle dst = wb.createCellStyle(); dst.setAlignment(src.getAlignment()); dst.setBorderBottom(src.getBorderBottom()); dst.setBorderLeft(src.getBorderLeft()); dst.setBorderRight(src.getBorderRight()); dst.setBorderTop(src.getBorderTop()); dst.setBottomBorderColor(src.getBottomBorderColor()); dst.setDataFormat(src.getDataFormat()); dst.setFillForegroundColor(src.getFillForegroundColor()); dst.setFillBackgroundColor(src.getFillBackgroundColor()); dst.setFillPattern(src.getFillPattern()); dst.setFont(src.getFont(wb)); dst.setHidden(src.getHidden()); dst.setIndention(src.getIndention()); dst.setLeftBorderColor(src.getLeftBorderColor()); dst.setLocked(src.getLocked()); dst.setRightBorderColor(src.getRightBorderColor()); dst.setRotation(src.getRotation()); dst.setTopBorderColor(src.getTopBorderColor()); dst.setVerticalAlignment(src.getVerticalAlignment()); dst.setWrapText(src.getWrapText()); return dst; }
public void colorStyles(CellStyle style, Formatter out) { HSSFCellStyle cs = (HSSFCellStyle) style; out.format(" /* fill pattern = %d */%n", cs.getFillPattern()); styleColor(out, "background-color", cs.getFillForegroundColor()); styleColor(out, "color", colors.getColor(cs.getFont(wb).getColor())); }
/** * Gets the tableCellEditorComponent attribute of the SVTableCellEditor object * * @return The tableCellEditorComponent value */ public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { System.out.println("GetTableCellEditorComponent"); HSSFCell cell = (HSSFCell) value; if (cell != null) { HSSFCellStyle style = cell.getCellStyle(); HSSFFont f = wb.getFontAt(style.getFontIndex()); boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL; boolean isitalics = f.getItalic(); int fontstyle = Font.PLAIN; if (isbold) fontstyle = Font.BOLD; if (isitalics) fontstyle = fontstyle | Font.ITALIC; int fontheight = f.getFontHeightInPoints(); if (fontheight == 9) fontheight = 10; // fix for stupid ol Windows Font font = new Font(f.getFontName(), fontstyle, fontheight); editor.setFont(font); if (style.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) { editor.setBackground(getAWTColor(style.getFillForegroundColor(), white)); } else editor.setBackground(white); editor.setForeground(getAWTColor(f.getColor(), black)); // Set the value that is rendered for the cell switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_BLANK: editor.setText(""); break; case HSSFCell.CELL_TYPE_BOOLEAN: if (cell.getBooleanCellValue()) { editor.setText("true"); } else { editor.setText("false"); } break; case HSSFCell.CELL_TYPE_NUMERIC: editor.setText(Double.toString(cell.getNumericCellValue())); break; case HSSFCell.CELL_TYPE_STRING: editor.setText(cell.getRichStringCellValue().getString()); break; case HSSFCell.CELL_TYPE_FORMULA: default: editor.setText("?"); } switch (style.getAlignment()) { case HSSFCellStyle.ALIGN_LEFT: case HSSFCellStyle.ALIGN_JUSTIFY: case HSSFCellStyle.ALIGN_FILL: editor.setHorizontalAlignment(SwingConstants.LEFT); break; case HSSFCellStyle.ALIGN_CENTER: case HSSFCellStyle.ALIGN_CENTER_SELECTION: editor.setHorizontalAlignment(SwingConstants.CENTER); break; case HSSFCellStyle.ALIGN_GENERAL: case HSSFCellStyle.ALIGN_RIGHT: editor.setHorizontalAlignment(SwingConstants.RIGHT); break; default: editor.setHorizontalAlignment(SwingConstants.LEFT); break; } } return editor; }