public FontVO(HSSFFont font) {
   fontName = font.getFontName();
   fontHeight = font.getFontHeight();
   boldweight = font.getBoldweight();
   italic = font.getItalic();
   strikeout = font.getStrikeout();
   typeOffset = font.getTypeOffset();
   underline = font.getUnderline();
   color = font.getColor();
 }
Exemple #2
0
 /**
  * Копирует все свойства исходного фонта в целевой. И исходный и целевой фонты должны относиться к
  * одному и тому же документу Excel. Данный метод используется для того чтобы в последствии
  * поменять в новом фонте один или несколько свойств не затрагивая при этом свойства исходного
  * фонта.
  *
  * @param wb документ Excel.
  * @param src фонт взятый в качестве шаблона.
  * @return созданная в этом же документе копия шрифта.
  */
 public static HSSFFont copyFont(final HSSFWorkbook wb, final HSSFFont src) {
   final HSSFFont dst = wb.createFont();
   dst.setBoldweight(src.getBoldweight());
   dst.setCharSet(src.getCharSet());
   dst.setColor(src.getColor());
   dst.setFontHeight(src.getFontHeight());
   dst.setFontName(src.getFontName());
   dst.setItalic(src.getItalic());
   dst.setStrikeout(src.getStrikeout());
   dst.setTypeOffset(src.getTypeOffset());
   dst.setUnderline(src.getUnderline());
   return dst;
 }
Exemple #3
0
 /**
  * Находит или создает новый стиль на основе указанного в аргументе исходного стиля в котором были
  * изменены цвета шрифта и/или фона. Информация о всех созданных данным методом стилях сохраняется
  * в контексте выполнения в пространстве имен {@link
  * org.echosoft.framework.reports.model.el.ELContext.Scope#VAR}.
  *
  * @param ectx контекст выполнения. Используется для получения информации о текущей ячейке и для
  *     кэширования информации о вновь созданных в документе стилях.
  * @param originalStyle исходный стиль, который должен послужить основой для создаваемого стиля.
  * @param color Определяет цвет шрифта в данной ячейке. Аргумент содержит идентификатор цвета в
  *     документе или <code>-1</code> если цвет шрифта должен остаться без изменений.
  * @param bgColor Определяет цвет фона в данной ячейке. Аргумент содержит идентификатор цвета в
  *     документе или <code>-1</code> если цвет шрифта должен остаться без изменений.
  * @return копия оригинального стиля указанной ячейки с измененными цветами фона и шрифта. Этот
  *     стиль уже зарегистрирован в рабочей книге.
  */
 public static HSSFCellStyle getAltColorStyle(
     final ExecutionContext ectx,
     final HSSFCellStyle originalStyle,
     final int color,
     final int bgColor) {
   final String styleName =
       "alt.color.style:" + originalStyle.getIndex() + ':' + color + ':' + bgColor;
   HSSFCellStyle style = (HSSFCellStyle) ectx.elctx.getVariables().get(styleName);
   if (style == null) {
     style = POIUtils.copyStyle(ectx.wb, originalStyle);
     if (color >= 0) {
       final HSSFFont of = ectx.wb.getFontAt(originalStyle.getFontIndex());
       HSSFFont nf =
           ectx.wb.findFont(
               of.getBoldweight(),
               (short) color,
               of.getFontHeight(),
               of.getFontName(),
               of.getItalic(),
               of.getStrikeout(),
               of.getTypeOffset(),
               of.getUnderline());
       if (nf == null) {
         nf = POIUtils.copyFont(ectx.wb, of);
         nf.setColor((short) color);
       }
       style.setFont(nf);
     }
     if (bgColor >= 0) {
       style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
       style.setFillForegroundColor((short) bgColor);
     }
     ectx.elctx.getVariables().put(styleName, style);
   }
   return style;
 }
  /**
   * 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;
  }