use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class HSSFHtmlHelper method styleColor.
private void styleColor(Formatter out, String attr, short index) {
HSSFColor color = colors.getColor(index);
if (index == HSSF_AUTO.getIndex() || color == null) {
out.format(" /* %s: index = %d */%n", attr, index);
} else {
short[] rgb = color.getTriplet();
out.format(" %s: #%02x%02x%02x; /* index = %d */%n", attr, rgb[0], rgb[1], rgb[2], index);
}
}
use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class HSSFExtendedColor method getIndexedRGB.
protected byte[] getIndexedRGB() {
if (isIndexed() && getIndex() > 0) {
int indexNum = getIndex();
HSSFColor indexed = HSSFColor.getIndexHash().get(indexNum);
if (indexed != null) {
byte[] rgb = new byte[3];
rgb[0] = (byte) indexed.getTriplet()[0];
rgb[1] = (byte) indexed.getTriplet()[1];
rgb[2] = (byte) indexed.getTriplet()[2];
return rgb;
}
}
// else
return null;
}
use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class TestUnfixedBugs method testBug57074.
@Test
public void testBug57074() throws IOException {
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("57074.xls");
Sheet sheet = wb.getSheet("Sheet1");
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
HSSFColor bgColor = (HSSFColor) cell.getCellStyle().getFillBackgroundColorColor();
String bgColorStr = bgColor.getTriplet()[0] + ", " + bgColor.getTriplet()[1] + ", " + bgColor.getTriplet()[2];
//System.out.println(bgColorStr);
assertEquals("215, 228, 188", bgColorStr);
HSSFColor fontColor = (HSSFColor) cell.getCellStyle().getFillForegroundColorColor();
String fontColorStr = fontColor.getTriplet()[0] + ", " + fontColor.getTriplet()[1] + ", " + fontColor.getTriplet()[2];
//System.out.println(fontColorStr);
assertEquals("0, 128, 128", fontColorStr);
wb.close();
}
use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class ExcelToFoConverter method processCellStyle.
protected void processCellStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle, Element cellTarget, Element blockTarget) {
blockTarget.setAttribute("white-space-collapse", "false");
{
String textAlign = ExcelToFoUtils.getAlign(cellStyle.getAlignment());
if (ExcelToFoUtils.isNotEmpty(textAlign))
blockTarget.setAttribute("text-align", textAlign);
}
if (cellStyle.getFillPattern() == 0) {
// no fill
} else if (cellStyle.getFillPattern() == 1) {
final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor();
if (foregroundColor != null)
cellTarget.setAttribute("background-color", ExcelToFoUtils.getColor(foregroundColor));
} else {
final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor();
if (backgroundColor != null)
cellTarget.setAttribute("background-color", ExcelToHtmlUtils.getColor(backgroundColor));
}
processCellStyleBorder(workbook, cellTarget, "top", cellStyle.getBorderTopEnum(), cellStyle.getTopBorderColor());
processCellStyleBorder(workbook, cellTarget, "right", cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor());
processCellStyleBorder(workbook, cellTarget, "bottom", cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor());
processCellStyleBorder(workbook, cellTarget, "left", cellStyle.getBorderLeftEnum(), cellStyle.getLeftBorderColor());
HSSFFont font = cellStyle.getFont(workbook);
processCellStyleFont(workbook, blockTarget, font);
}
use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.
the class TestPaletteRecord method testDefaultPalette.
/**
* Tests that the default palette matches the constants of HSSFColor
*/
@Test
public void testDefaultPalette() {
PaletteRecord palette = new PaletteRecord();
//make sure all the HSSFColor constants match
Map<Integer, HSSFColor> colors = HSSFColor.getIndexHash();
for (Entry<Integer, HSSFColor> entry : colors.entrySet()) {
int index = entry.getKey();
HSSFColor c = entry.getValue();
short[] rgbTriplet = c.getTriplet();
byte[] paletteTriplet = palette.getColor((short) index);
String msg = "Expected HSSFColor constant to match PaletteRecord at index" + (index == c.getIndex2() ? "2" : "") + " 0x" + Integer.toHexString(index);
assertEquals(msg, rgbTriplet[0], paletteTriplet[0] & 0xff);
assertEquals(msg, rgbTriplet[1], paletteTriplet[1] & 0xff);
assertEquals(msg, rgbTriplet[2], paletteTriplet[2] & 0xff);
}
}
Aggregations