use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class ExcelToFoConverter method processCellStyleBorder.
protected void processCellStyleBorder(HSSFWorkbook workbook, Element cellTarget, String type, BorderStyle xlsBorder, short borderColor) {
if (xlsBorder == BorderStyle.NONE)
return;
StringBuilder borderStyle = new StringBuilder();
borderStyle.append(ExcelToHtmlUtils.getBorderWidth(xlsBorder));
final HSSFColor color = workbook.getCustomPalette().getColor(borderColor);
if (color != null) {
borderStyle.append(' ');
borderStyle.append(ExcelToHtmlUtils.getColor(color));
borderStyle.append(' ');
borderStyle.append(ExcelToHtmlUtils.getBorderStyle(xlsBorder));
}
cellTarget.setAttribute("border-" + type, borderStyle.toString());
}
use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class ExcelToHtmlConverter method buildStyle.
protected String buildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle) {
StringBuilder style = new StringBuilder();
style.append("white-space:pre-wrap;");
ExcelToHtmlUtils.appendAlign(style, cellStyle.getAlignment());
switch(cellStyle.getFillPattern()) {
// no fill
case 0:
break;
case 1:
final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor();
if (foregroundColor == null)
break;
String fgCol = ExcelToHtmlUtils.getColor(foregroundColor);
style.append("background-color:" + fgCol + ";");
break;
default:
final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor();
if (backgroundColor == null)
break;
String bgCol = ExcelToHtmlUtils.getColor(backgroundColor);
style.append("background-color:" + bgCol + ";");
break;
}
buildStyle_border(workbook, style, "top", cellStyle.getBorderTopEnum(), cellStyle.getTopBorderColor());
buildStyle_border(workbook, style, "right", cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor());
buildStyle_border(workbook, style, "bottom", cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor());
buildStyle_border(workbook, style, "left", cellStyle.getBorderLeftEnum(), cellStyle.getLeftBorderColor());
HSSFFont font = cellStyle.getFont(workbook);
buildStyle_font(workbook, style, font);
return style.toString();
}
use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class ExcelToFoConverter method processCellStyleFont.
protected void processCellStyleFont(HSSFWorkbook workbook, Element blockTarget, HSSFFont font) {
Triplet triplet = new Triplet();
triplet.fontName = font.getFontName();
switch(font.getBoldweight()) {
case HSSFFont.BOLDWEIGHT_BOLD:
triplet.bold = true;
break;
case HSSFFont.BOLDWEIGHT_NORMAL:
default:
triplet.bold = false;
break;
}
if (font.getItalic()) {
triplet.italic = true;
}
getFontReplacer().update(triplet);
setBlockProperties(blockTarget, triplet);
final HSSFColor fontColor = workbook.getCustomPalette().getColor(font.getColor());
if (fontColor != null)
blockTarget.setAttribute("color", ExcelToHtmlUtils.getColor(fontColor));
if (font.getFontHeightInPoints() != 0)
blockTarget.setAttribute("font-size", font.getFontHeightInPoints() + "pt");
}
use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class HSSFPalette method findSimilarColor.
/**
* Finds the closest matching color in the custom palette. The
* method for finding the distance between the colors is fairly
* primative.
*
* @param red The red component of the color to match.
* @param green The green component of the color to match.
* @param blue The blue component of the color to match.
* @return The closest color or null if there are no custom
* colors currently defined.
*/
public HSSFColor findSimilarColor(int red, int green, int blue) {
HSSFColor result = null;
int minColorDistance = Integer.MAX_VALUE;
byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);
for (short i = PaletteRecord.FIRST_COLOR_INDEX; b != null; b = _palette.getColor(++i)) {
int colorDistance = Math.abs(red - unsignedInt(b[0])) + Math.abs(green - unsignedInt(b[1])) + Math.abs(blue - unsignedInt(b[2]));
if (colorDistance < minColorDistance) {
minColorDistance = colorDistance;
result = getColor(i);
}
}
return result;
}
use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class TestHSSFPalette method compareToDefaults.
private void compareToDefaults(ColorComparator c) {
Map<Integer, HSSFColor> colors = HSSFColor.getIndexHash();
Iterator<Integer> it = colors.keySet().iterator();
while (it.hasNext()) {
Number index = it.next();
HSSFColor expectedColor = colors.get(index);
HSSFColor paletteColor = _hssfPalette.getColor(index.shortValue());
c.compare(expectedColor, paletteColor);
}
}
Aggregations