Search in sources :

Example 6 with CellStyleProxy

use of org.eclipse.nebula.widgets.nattable.style.CellStyleProxy in project nebula.widgets.nattable by eclipse.

the class ExcelExporter method exportCell.

@Override
public void exportCell(OutputStream outputStream, Object exportDisplayValue, ILayerCell cell, IConfigRegistry configRegistry) throws IOException {
    CellStyleProxy cellStyle = new CellStyleProxy(configRegistry, DisplayMode.NORMAL, cell.getConfigLabels().getLabels());
    Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
    Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
    Font font = cellStyle.getAttributeValue(CellStyleAttributes.FONT);
    if (fg == null) {
        fg = GUIHelper.COLOR_BLACK;
    }
    if (bg == null) {
        bg = GUIHelper.COLOR_WHITE;
    }
    if (font == null) {
        font = GUIHelper.DEFAULT_FONT;
    }
    String htmlAttributes = // $NON-NLS-1$
    String.format(// $NON-NLS-1$
    "style='color: %s; background-color: %s; %s;'", getColorInCSSFormat(fg), getColorInCSSFormat(bg), getFontInCSSFormat(font));
    // $NON-NLS-1$
    String htmlText = exportDisplayValue != null ? exportDisplayValue.toString() : "";
    if (htmlText.startsWith(" ")) {
        // $NON-NLS-1$
        // $NON-NLS-1$ //$NON-NLS-2$
        htmlAttributes += " x:str=\"'" + htmlText + "\";";
        // $NON-NLS-1$ //$NON-NLS-2$
        htmlText = htmlText.replaceFirst("^(\\ *)", "<span style='mso-spacerun:yes'>$1</span>");
    }
    // $NON-NLS-1$
    outputStream.write(asBytes(String.format("\t<td %s>%s</td>\n", htmlAttributes, htmlText)));
}
Also used : Color(org.eclipse.swt.graphics.Color) CellStyleProxy(org.eclipse.nebula.widgets.nattable.style.CellStyleProxy) Font(org.eclipse.swt.graphics.Font)

Aggregations

CellStyleProxy (org.eclipse.nebula.widgets.nattable.style.CellStyleProxy)6 Color (org.eclipse.swt.graphics.Color)3 IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Cell (org.apache.poi.ss.usermodel.Cell)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1 Row (org.apache.poi.ss.usermodel.Row)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)1 HorizontalAlignmentEnum (org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum)1 Style (org.eclipse.nebula.widgets.nattable.style.Style)1 StyleProxy (org.eclipse.nebula.widgets.nattable.style.StyleProxy)1 Font (org.eclipse.swt.graphics.Font)1