aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/ss/util
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2018-02-20 00:25:43 +0000
committerPJ Fanning <fanningpj@apache.org>2018-02-20 00:25:43 +0000
commit05b0de574cce4c56fc862737242846df4abc2e6e (patch)
treed63312db51c79e1cc39a0ece41bcc59669ab164e /src/java/org/apache/poi/ss/util
parent61b0d86a2d0c1444b77fda00d2450cf289322300 (diff)
downloadpoi-05b0de574cce4c56fc862737242846df4abc2e6e.tar.gz
poi-05b0de574cce4c56fc862737242846df4abc2e6e.zip
[bug-62018] use ints to index fonts
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1824826 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/ss/util')
-rw-r--r--src/java/org/apache/poi/ss/util/CellUtil.java24
-rw-r--r--src/java/org/apache/poi/ss/util/SheetUtil.java4
2 files changed, 22 insertions, 6 deletions
diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java
index e1b909917a..15036761a7 100644
--- a/src/java/org/apache/poi/ss/util/CellUtil.java
+++ b/src/java/org/apache/poi/ss/util/CellUtil.java
@@ -234,7 +234,7 @@ public final class CellUtil {
public static void setFont(Cell cell, Font font) {
// Check if font belongs to workbook
Workbook wb = cell.getSheet().getWorkbook();
- final short fontIndex = font.getIndex();
+ final int fontIndex = font.getIndexAsInt();
if (!wb.getFontAt(fontIndex).equals(font)) {
throw new IllegalArgumentException("Font does not belong to this workbook");
}
@@ -408,7 +408,7 @@ public final class CellUtil {
style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
- style.setFont(workbook.getFontAt(getShort(properties, FONT)));
+ style.setFont(workbook.getFontAt(getInt(properties, FONT)));
style.setHidden(getBoolean(properties, HIDDEN));
style.setIndention(getShort(properties, INDENTION));
style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
@@ -429,8 +429,24 @@ public final class CellUtil {
*/
private static short getShort(Map<String, Object> properties, String name) {
Object value = properties.get(name);
- if (value instanceof Short) {
- return ((Short) value).shortValue();
+ if (value instanceof Number) {
+ return ((Number) value).shortValue();
+ }
+ return 0;
+ }
+
+ /**
+ * Utility method that returns the named int value form the given map.
+ *
+ * @param properties map of named properties (String -> Object)
+ * @param name property name
+ * @return zero if the property does not exist, or is not a {@link Integer}
+ * otherwise the property value
+ */
+ private static int getInt(Map<String, Object> properties, String name) {
+ Object value = properties.get(name);
+ if (value instanceof Number) {
+ return ((Number) value).intValue();
}
return 0;
}
diff --git a/src/java/org/apache/poi/ss/util/SheetUtil.java b/src/java/org/apache/poi/ss/util/SheetUtil.java
index 8f1345230c..2293ebcb1c 100644
--- a/src/java/org/apache/poi/ss/util/SheetUtil.java
+++ b/src/java/org/apache/poi/ss/util/SheetUtil.java
@@ -144,7 +144,7 @@ public class SheetUtil {
if (cellType == CellType.FORMULA)
cellType = cell.getCachedFormulaResultType();
- Font font = wb.getFontAt(style.getFontIndex());
+ Font font = wb.getFontAt(style.getFontIntIndex());
double width = -1;
if (cellType == CellType.STRING) {
@@ -266,7 +266,7 @@ public class SheetUtil {
*/
@Internal
public static int getDefaultCharWidth(final Workbook wb) {
- Font defaultFont = wb.getFontAt((short) 0);
+ Font defaultFont = wb.getFontAt( 0);
AttributedString str = new AttributedString(String.valueOf(defaultChar));
copyAttributes(defaultFont, str, 0, 1);