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)));
}
Aggregations