mirror of https://github.com/apache/poi.git
Provide format-agnostic conditional formatting font colour getter and setter
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691045 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
08007fbaad
commit
fbfe65d52d
|
@ -62,13 +62,13 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
|
|||
if ( fontFormatting != null)
|
||||
{
|
||||
cfRuleRecord.setFontFormatting(fontFormatting);
|
||||
return new HSSFFontFormatting(cfRuleRecord);
|
||||
return new HSSFFontFormatting(cfRuleRecord, workbook);
|
||||
}
|
||||
else if( create )
|
||||
{
|
||||
fontFormatting = new FontFormatting();
|
||||
cfRuleRecord.setFontFormatting(fontFormatting);
|
||||
return new HSSFFontFormatting(cfRuleRecord);
|
||||
return new HSSFFontFormatting(cfRuleRecord, workbook);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.poi.hssf.usermodel;
|
|||
|
||||
import org.apache.poi.hssf.record.CFRuleBase;
|
||||
import org.apache.poi.hssf.record.cf.FontFormatting;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.Color;
|
||||
/**
|
||||
* High level representation for Font Formatting component
|
||||
* of Conditional Formatting settings
|
||||
|
@ -37,10 +39,12 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
|
|||
public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
|
||||
|
||||
private final FontFormatting fontFormatting;
|
||||
private final HSSFWorkbook workbook;
|
||||
|
||||
protected HSSFFontFormatting(CFRuleBase cfRuleRecord)
|
||||
protected HSSFFontFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook)
|
||||
{
|
||||
this.fontFormatting = cfRuleRecord.getFontFormatting();
|
||||
this.workbook = workbook;
|
||||
}
|
||||
|
||||
protected FontFormatting getFontFormattingBlock()
|
||||
|
@ -69,7 +73,26 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
|
|||
return fontFormatting.getFontColorIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
public HSSFColor getFontColor() {
|
||||
return workbook.getCustomPalette().getColor(
|
||||
getFontColorIndex()
|
||||
);
|
||||
}
|
||||
|
||||
public void setFontColor(Color color) {
|
||||
if (color != null && !(color instanceof HSSFColor)) {
|
||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
||||
}
|
||||
|
||||
HSSFColor hcolor = (HSSFColor)color;
|
||||
if (hcolor == null) {
|
||||
fontFormatting.setFontColorIndex((short)0);
|
||||
} else {
|
||||
fontFormatting.setFontColorIndex(hcolor.getIndex());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the height of the font in 1/20th point units
|
||||
*
|
||||
* @return fontheight (in points/20); or -1 if not modified
|
||||
|
|
|
@ -66,15 +66,26 @@ public interface FontFormatting {
|
|||
void setEscapementType(short escapementType);
|
||||
|
||||
/**
|
||||
* @return font color index
|
||||
* @return font colour index, or 0 if not indexed (XSSF only)
|
||||
*/
|
||||
short getFontColorIndex();
|
||||
|
||||
|
||||
/**
|
||||
* @param color font color index
|
||||
* Sets the indexed colour to use
|
||||
* @param color font colour index
|
||||
*/
|
||||
void setFontColorIndex(short color);
|
||||
|
||||
/**
|
||||
* @return The colour of the font, or null if no colour applied
|
||||
*/
|
||||
Color getFontColor();
|
||||
|
||||
/**
|
||||
* Sets the colour to use
|
||||
* @param color font colour to use
|
||||
*/
|
||||
void setFontColor(Color color);
|
||||
|
||||
/**
|
||||
* gets the height of the font in 1/20th point units
|
||||
|
|
|
@ -80,7 +80,6 @@ public class XSSFFontFormatting implements FontFormatting {
|
|||
return (short)idx;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param color font color index
|
||||
*/
|
||||
|
@ -91,16 +90,32 @@ public class XSSFFontFormatting implements FontFormatting {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return xssf color wrapper or null if color info is missing
|
||||
*/
|
||||
public XSSFColor getXSSFColor(){
|
||||
public XSSFColor getFontColor() {
|
||||
if(_font.sizeOfColorArray() == 0) return null;
|
||||
|
||||
return new XSSFColor(_font.getColorArray(0));
|
||||
}
|
||||
|
||||
public void setFontColor(Color color) {
|
||||
if (color != null && !(color instanceof XSSFColor)) {
|
||||
throw new IllegalArgumentException("Only XSSFColor objects are supported");
|
||||
}
|
||||
|
||||
XSSFColor xcolor = (XSSFColor)color;
|
||||
if (xcolor == null) {
|
||||
_font.getColorList().clear();
|
||||
} else {
|
||||
_font.setColorArray(0, xcolor.getCTColor());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getFontColor()}
|
||||
*/
|
||||
public XSSFColor getXSSFColor(){
|
||||
return getFontColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the height of the font in 1/20th point units
|
||||
*
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STConditionalFormatti
|
|||
*/
|
||||
public class XSSFSheetConditionalFormatting implements SheetConditionalFormatting {
|
||||
/** Office 2010 Conditional Formatting extensions namespace */
|
||||
protected static final CF_EXT_2009_NS_X14 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
|
||||
protected static final String CF_EXT_2009_NS_X14 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
|
||||
|
||||
private final XSSFSheet _sheet;
|
||||
|
||||
|
|
Loading…
Reference in New Issue