From fac8191235eee7711979bb13bf44a5f4d183b20d Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 3 May 2015 08:10:07 +0000 Subject: [PATCH] Avoid short wrapping on cell styles and formats > 32,767 in XSSF - format supports up to 64,000 of them #57880 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1677371 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/XSSFCellStyle.java | 12 +++++++ .../poi/xssf/usermodel/XSSFDataFormat.java | 8 +++++ .../poi/xssf/usermodel/XSSFWorkbook.java | 9 +++++ .../poi/xssf/usermodel/TestXSSFBugs.java | 35 +++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java index 760026be11..f83facdda4 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java @@ -603,6 +603,9 @@ public class XSSFCellStyle implements CellStyle { public short getIndex() { return (short)this._cellXfId; } + protected int getUIndex() { + return this._cellXfId; + } /** * Get the color to use for the left border @@ -974,6 +977,15 @@ public class XSSFCellStyle implements CellStyle { * @param fmt the index of a data format */ public void setDataFormat(short fmt) { + // XSSF supports >32,767 formats + setDataFormat(fmt&0xffff); + } + /** + * Set the index of a data format + * + * @param fmt the index of a data format + */ + public void setDataFormat(int fmt) { _cellXf.setApplyNumberFormat(true); _cellXf.setNumFmtId(fmt); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java index 00ac90736a..870c6c0254 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java @@ -51,6 +51,14 @@ public class XSSFDataFormat implements DataFormat { * @return string represented at index of format or null if there is not a format at that index */ public String getFormat(short index) { + return getFormat(index&0xffff); + } + /** + * get the format string that matches the given format index + * @param index of a format + * @return string represented at index of format or null if there is not a format at that index + */ + public String getFormat(int index) { String fmt = stylesSource.getNumberFormatAt(index); if(fmt == null) fmt = BuiltinFormats.getBuiltinFormat(index); return fmt; diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 499c3db08e..9230797e41 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -843,6 +843,15 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable