From ea751b7749fa8bcae67565e99145db76d6f209f9 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 12 Nov 2007 12:47:34 +0000 Subject: [PATCH] Support getting and setting as int, as well as short (bug #43648) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@594097 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 3 +- src/documentation/content/xdocs/status.xml | 2 ++ .../poi/hssf/record/formula/IntPtg.java | 36 +++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 29df020f3c..d2298ea8be 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,7 +36,8 @@ - 43751 - [PATCH] - Fix for handling rotated text in HSSFSheet.autoSizeColumn + 43648 - Fix for IntPtg and short vs int + 43751 - [PATCH] - Fix for handling rotated text in HSSFSheet.autoSizeColumn Include an Excel text extractor, and put all existing text extractors under a common superclass Improvements to the LZW compression engine used by HDGF HSSFPicture.resize() - a handy method to reset a picture to its original width and height diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 22be5a09fb..f8c0eb6de8 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,8 @@ + 43648 - Fix for IntPtg and short vs int + 43751 - [PATCH] - Fix for handling rotated text in HSSFSheet.autoSizeColumn Include an Excel text extractor, and put all existing text extractors under a common superclass Improvements to the LZW compression engine used by HDGF HSSFPicture.resize() - a handy method to reset a picture to its original width and height diff --git a/src/java/org/apache/poi/hssf/record/formula/IntPtg.java b/src/java/org/apache/poi/hssf/record/formula/IntPtg.java index 46de94ff61..602289776b 100644 --- a/src/java/org/apache/poi/hssf/record/formula/IntPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/IntPtg.java @@ -29,8 +29,8 @@ import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.record.RecordInputStream; /** - * Integer (short intger) - * Stores a (java) short value in a formula + * Integer (unsigned short intger) + * Stores an unsigned short value (java int) in a formula * @author Andrew C. Oliver (acoliver at apache dot org) * @author Jason Height (jheight at chariot dot net dot au) */ @@ -57,16 +57,48 @@ public class IntPtg setValue(Short.parseShort(formulaToken)); } + /** + * Sets the wrapped value. + * Normally you should call with a positive int. + */ public void setValue(short value) { field_1_value = value; } + /** + * Sets the unsigned value. + * (Handles conversion to the internal short value) + */ + public void setValue(int value) + { + if(value > Short.MAX_VALUE) { + // Need to wrap + value -= (Short.MAX_VALUE+1)*2; + } + field_1_value = (short)value; + } + + /** + * Returns the value as a short, which may have + * been wrapped into negative numbers + */ public short getValue() { return field_1_value; } + /** + * Returns the value as an unsigned positive int. + */ + public int getValueAsInt() + { + if(field_1_value < 0) { + return (Short.MAX_VALUE + 1)*2 + field_1_value; + } + return field_1_value; + } + public void writeBytes(byte [] array, int offset) { array[ offset + 0 ] = sid; -- 2.39.5