org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined Java Examples

The following examples show how to use org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HSSFCellStyle.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if the background and foreground fills are set correctly when one
 * or the other is set to the default color.
 * <p>Works like the logic table below:</p>
 * <p>BACKGROUND   FOREGROUND</p>
 * <p>NONE         AUTOMATIC</p>
 * <p>0x41         0x40</p>
 * <p>NONE         RED/ANYTHING</p>
 * <p>0x40         0xSOMETHING</p>
 */
private void checkDefaultBackgroundFills() {
    final short autoIdx = HSSFColorPredefined.AUTOMATIC.getIndex();
    if (_format.getFillForeground() == autoIdx) {
        //JMH: Why +1, hell why not. I guess it made some sense to someone at the time. Doesnt
        //to me now.... But experience has shown that when the fore is set to AUTOMATIC then the
        //background needs to be incremented......
        if (_format.getFillBackground() != autoIdx+1) {
            setFillBackgroundColor((short)(autoIdx+1));
        }
    } else if (_format.getFillBackground() == autoIdx+1) {
        //Now if the forground changes to a non-AUTOMATIC color the background resets itself!!!
        if (_format.getFillForeground() != autoIdx) {
            setFillBackgroundColor(autoIdx);
        }
    }
}
 
Example #2
Source File: InternalWorkbook.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * creates an default cell type ExtendedFormatRecord object.
 * @return ExtendedFormatRecord with initial defaults (cell-type)
 */
private static ExtendedFormatRecord createExtendedFormat() {
    ExtendedFormatRecord retval = new ExtendedFormatRecord();

    retval.setFontIndex(( short ) 0);
    retval.setFormatIndex(( short ) 0x0);
    retval.setCellOptions(( short ) 0x1);
    retval.setAlignmentOptions(( short ) 0x20);
    retval.setIndentionOptions(( short ) 0);
    retval.setBorderOptions(( short ) 0);
    retval.setPaletteOptions(( short ) 0);
    retval.setAdtlPaletteOptions(( short ) 0);
    retval.setFillPaletteOptions(( short ) 0x20c0);
    retval.setTopBorderPaletteIdx(HSSFColorPredefined.BLACK.getIndex());
    retval.setBottomBorderPaletteIdx(HSSFColorPredefined.BLACK.getIndex());
    retval.setLeftBorderPaletteIdx(HSSFColorPredefined.BLACK.getIndex());
    retval.setRightBorderPaletteIdx(HSSFColorPredefined.BLACK.getIndex());
    return retval;
}
 
Example #3
Source File: HSSFPalette.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the color at a given index
 *
 * @param index the palette index, between 0x8 to 0x40 inclusive
 * @return the color, or null if the index is not populated
 */
public HSSFColor getColor(short index)
{
    //Handle the special AUTOMATIC case
    if (index == HSSFColorPredefined.AUTOMATIC.getIndex()) {
        return HSSFColorPredefined.AUTOMATIC.getColor();
    }
    byte[] b = _palette.getColor(index);
    return (b == null) ? null : new CustomColor(index, b);
}
 
Example #4
Source File: HSSFCellStyle.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the background fill color.
 * Note - many cells are actually filled with a foreground
 *  fill, not a background fill - see {@link #getFillForegroundColor()}
 * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
 * @return fill color
 */
@Override
public short getFillBackgroundColor() {
    final short autoIndex = HSSFColorPredefined.AUTOMATIC.getIndex();
    short result = _format.getFillBackground();
    //JMH: Do this ridiculous conversion, and let HSSFCellStyle
    //internally migrate back and forth
    if (result == autoIndex+1) {
        return autoIndex;
    }
    return result;
}
 
Example #5
Source File: CellStyleContext.java    From ureport with Apache License 2.0 5 votes vote down vote up
private HSSFColor buildHSSFColor(HSSFWorkbook wb,String colorStr){
	String[] color=colorStr.split(",");
	HSSFPalette palette=wb.getCustomPalette();
	byte r=BigInteger.valueOf(Integer.valueOf(color[0])).byteValue();
	byte g=BigInteger.valueOf(Integer.valueOf(color[1])).byteValue();
	byte b=BigInteger.valueOf(Integer.valueOf(color[2])).byteValue();
	HSSFColor targetColor=palette.findColor(r,g,b);
	if(targetColor==null){
		palette.setColorAtIndex(HSSFColorPredefined.LAVENDER.getIndex(), r, g,b);
		targetColor=palette.getColor(HSSFColorPredefined.LAVENDER.getIndex());
	}
	return targetColor;
}
 
Example #6
Source File: HSSFBorderFormatting.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
 * @see org.apache.poi.ss.usermodel.BorderFormatting#getVerticalBorderColor()
 */
public short getVerticalBorderColor() {
    return HSSFColorPredefined.AUTOMATIC.getIndex();
}
 
Example #7
Source File: HSSFBorderFormatting.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
 * @see org.apache.poi.ss.usermodel.BorderFormatting#getVerticalBorderColorColor()
 */
public Color getVerticalBorderColorColor() {
    return HSSFColorPredefined.AUTOMATIC.getColor();
}
 
Example #8
Source File: HSSFBorderFormatting.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
 * @see org.apache.poi.ss.usermodel.BorderFormatting#getHorizontalBorderColor()
 */
public short getHorizontalBorderColor() {
    return HSSFColorPredefined.AUTOMATIC.getIndex();
}
 
Example #9
Source File: HSSFBorderFormatting.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
 * @see org.apache.poi.ss.usermodel.BorderFormatting#getHorizontalBorderColorColor()
 */
public Color getHorizontalBorderColorColor() {
    return HSSFColorPredefined.AUTOMATIC.getColor();
}