mirror of https://github.com/apache/poi.git
[bug-66052] apply cell style fixes supplied by Axel Richter
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902622 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d9383d6ba9
commit
6602122926
|
@ -829,6 +829,19 @@ public class XSSFCellStyle implements CellStyle, Duplicatable {
|
|||
addFill(ct);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
|
||||
* <br>
|
||||
* @param color the color to use
|
||||
* @since POI 5.2.3
|
||||
*/
|
||||
@Override
|
||||
public void setFillBackgroundColor(org.apache.poi.ss.usermodel.Color color) {
|
||||
if (color instanceof XSSFColor) {
|
||||
setFillBackgroundColor((XSSFColor)color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background fill color represented as a indexed color value.
|
||||
* <p>
|
||||
|
@ -882,6 +895,19 @@ public class XSSFCellStyle implements CellStyle, Duplicatable {
|
|||
|
||||
addFill(ct);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the foreground fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
|
||||
* <br>
|
||||
* @param color the color to use
|
||||
* @since POI 5.2.3
|
||||
*/
|
||||
@Override
|
||||
public void setFillForegroundColor(org.apache.poi.ss.usermodel.Color color) {
|
||||
if (color instanceof XSSFColor) {
|
||||
setFillForegroundColor((XSSFColor)color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the foreground fill color as a indexed color value
|
||||
|
|
|
@ -637,6 +637,21 @@ public final class HSSFCellStyle implements CellStyle, Duplicatable {
|
|||
_format.setFillBackground(bg);
|
||||
checkDefaultBackgroundFills();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
|
||||
* <br>
|
||||
* @param color the color to use
|
||||
* @since POI 5.2.3
|
||||
*/
|
||||
@Override
|
||||
public void setFillBackgroundColor(org.apache.poi.ss.usermodel.Color color)
|
||||
{
|
||||
if (color instanceof HSSFColor) {
|
||||
short index2 = ((HSSFColor)color).getIndex2();
|
||||
if (index2 != -1) setFillBackgroundColor(index2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background fill color.
|
||||
|
@ -678,6 +693,21 @@ public final class HSSFCellStyle implements CellStyle, Duplicatable {
|
|||
_format.setFillForeground(bg);
|
||||
checkDefaultBackgroundFills();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the foreground fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
|
||||
* <br>
|
||||
* @param color the color to use
|
||||
* @since POI 5.2.3
|
||||
*/
|
||||
@Override
|
||||
public void setFillForegroundColor(org.apache.poi.ss.usermodel.Color color)
|
||||
{
|
||||
if (color instanceof HSSFColor) {
|
||||
short index2 = ((HSSFColor)color).getIndex2();
|
||||
if (index2 != -1) setFillForegroundColor(index2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreground fill color.
|
||||
|
|
|
@ -311,6 +311,15 @@ public interface CellStyle {
|
|||
*/
|
||||
void setFillBackgroundColor(short bg);
|
||||
|
||||
/**
|
||||
* set the background fill color.
|
||||
* use not a indexed color but a {@link org.apache.poi.ss.usermodel.Color)
|
||||
*
|
||||
* @param color org.apache.poi.ss.usermodel.Color to set
|
||||
* @since POI 5.2.3
|
||||
*/
|
||||
void setFillBackgroundColor(Color color);
|
||||
|
||||
/**
|
||||
* get the background fill color, if the fill
|
||||
* is defined with an indexed color.
|
||||
|
@ -334,6 +343,15 @@ public interface CellStyle {
|
|||
*/
|
||||
void setFillForegroundColor(short bg);
|
||||
|
||||
/**
|
||||
* set the foreground fill color.
|
||||
* use not a indexed color but a {@link org.apache.poi.ss.usermodel.Color)
|
||||
*
|
||||
* @param color org.apache.poi.ss.usermodel.Color to set
|
||||
* @since POI 5.2.3
|
||||
*/
|
||||
void setFillForegroundColor(Color color);
|
||||
|
||||
/**
|
||||
* get the foreground fill color, if the fill
|
||||
* is defined with an indexed color.
|
||||
|
|
|
@ -56,6 +56,10 @@ public final class CellUtil {
|
|||
public static final String DATA_FORMAT = "dataFormat";
|
||||
public static final String FILL_BACKGROUND_COLOR = "fillBackgroundColor";
|
||||
public static final String FILL_FOREGROUND_COLOR = "fillForegroundColor";
|
||||
|
||||
public static final String FILL_BACKGROUND_COLOR_COLOR = "fillBackgroundColorColor";
|
||||
public static final String FILL_FOREGROUND_COLOR_COLOR = "fillForegroundColorColor";
|
||||
|
||||
public static final String FILL_PATTERN = "fillPattern";
|
||||
public static final String FONT = "font";
|
||||
public static final String HIDDEN = "hidden";
|
||||
|
@ -79,6 +83,13 @@ public final class CellUtil {
|
|||
DATA_FORMAT,
|
||||
ROTATION
|
||||
)));
|
||||
|
||||
private static final Set<String> colorValues = Collections.unmodifiableSet(
|
||||
new HashSet<>(Arrays.asList(
|
||||
FILL_FOREGROUND_COLOR_COLOR,
|
||||
FILL_BACKGROUND_COLOR_COLOR
|
||||
)));
|
||||
|
||||
private static final Set<String> intValues = Collections.unmodifiableSet(
|
||||
new HashSet<>(Collections.singletonList(
|
||||
FONT
|
||||
|
@ -376,6 +387,7 @@ public final class CellUtil {
|
|||
public static void setCellStyleProperties(Cell cell, Map<String, Object> properties) {
|
||||
Workbook workbook = cell.getSheet().getWorkbook();
|
||||
CellStyle originalStyle = cell.getCellStyle();
|
||||
|
||||
CellStyle newStyle = null;
|
||||
Map<String, Object> values = getFormatProperties(originalStyle);
|
||||
putAll(properties, values);
|
||||
|
@ -447,8 +459,12 @@ public final class CellUtil {
|
|||
put(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor());
|
||||
put(properties, DATA_FORMAT, style.getDataFormat());
|
||||
put(properties, FILL_PATTERN, style.getFillPattern());
|
||||
|
||||
put(properties, FILL_FOREGROUND_COLOR, style.getFillForegroundColor());
|
||||
put(properties, FILL_BACKGROUND_COLOR, style.getFillBackgroundColor());
|
||||
put(properties, FILL_FOREGROUND_COLOR_COLOR, style.getFillForegroundColorColor());
|
||||
put(properties, FILL_BACKGROUND_COLOR_COLOR, style.getFillBackgroundColorColor());
|
||||
|
||||
put(properties, FONT, style.getFontIndex());
|
||||
put(properties, HIDDEN, style.getHidden());
|
||||
put(properties, INDENTION, style.getIndention());
|
||||
|
@ -475,6 +491,8 @@ public final class CellUtil {
|
|||
for (final String key : src.keySet()) {
|
||||
if (shortValues.contains(key)) {
|
||||
dest.put(key, getShort(src, key));
|
||||
} else if (colorValues.contains(key)) {
|
||||
dest.put(key, getColor(src, key));
|
||||
} else if (intValues.contains(key)) {
|
||||
dest.put(key, getInt(src, key));
|
||||
} else if (booleanValues.contains(key)) {
|
||||
|
@ -511,8 +529,12 @@ public final class CellUtil {
|
|||
style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
|
||||
style.setDataFormat(getShort(properties, DATA_FORMAT));
|
||||
style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
|
||||
|
||||
style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
|
||||
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
|
||||
style.setFillForegroundColor(getColor(properties, FILL_FOREGROUND_COLOR_COLOR));
|
||||
style.setFillBackgroundColor(getColor(properties, FILL_BACKGROUND_COLOR_COLOR));
|
||||
|
||||
style.setFont(workbook.getFontAt(getInt(properties, FONT)));
|
||||
style.setHidden(getBoolean(properties, HIDDEN));
|
||||
style.setIndention(getShort(properties, INDENTION));
|
||||
|
@ -541,6 +563,23 @@ public final class CellUtil {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that returns the named Color value from the given map.
|
||||
*
|
||||
* @param properties map of named properties (String -> Object)
|
||||
* @param name property name
|
||||
* @return null if the property does not exist, or is not a {@link Color}
|
||||
* otherwise the property value
|
||||
*/
|
||||
private static Color getColor(Map<String, Object> properties, String name) {
|
||||
Object value = properties.get(name);
|
||||
if (value instanceof Color) {
|
||||
return (Color) value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility method that returns the named int value from the given map.
|
||||
|
|
Loading…
Reference in New Issue