You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2009/02/06 19:59:25 UTC
svn commit: r741678 - in /poi/trunk/src: java/org/apache/poi/hssf/model/
java/org/apache/poi/hssf/usermodel/
ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/
ooxml/java/org/apache/poi/xssf/usermodel/
ooxml/testcases/org/apache/poi/xssf/usermodel/ te...
Author: yegor
Date: Fri Feb 6 18:59:24 2009
New Revision: 741678
URL: http://svn.apache.org/viewvc?rev=741678&view=rev
Log:
changed. Sheet.setColumnWidth to throw IllegalArgumentException if the column width argument is greater than 255 characters (the maximum column width in Excel)
Modified:
poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java?rev=741678&r1=741677&r2=741678&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java Fri Feb 6 18:59:24 2009
@@ -1091,6 +1091,8 @@
* (in units of 1/256th of a character width)
*/
public void setColumnWidth(int column, int width) {
+ if(width > 255*256) throw new IllegalArgumentException("The maximum column width for an individual cell is 255 characters.");
+
setColumn(column, null, new Integer(width), null, null, null);
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=741678&r1=741677&r2=741678&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Fri Feb 6 18:59:24 2009
@@ -429,9 +429,16 @@
}
/**
- * set the width (in units of 1/256th of a character width)
+ * Set the width (in units of 1/256th of a character width)
+ * <p>
+ * The maximum column width for an individual cell is 255 characters.
+ * This value represents the number of characters that can be displayed
+ * in a cell that is formatted with the standard font.
+ * </p>
+ *
* @param columnIndex - the column to set (0-based)
* @param width - the width in units of 1/256th of a character width
+ * @throws IllegalArgumentException if width > 65536 (the maximum column width in Excel)
*/
public void setColumnWidth(int columnIndex, int width) {
sheet.setColumnWidth(columnIndex, width);
Modified: poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java?rev=741678&r1=741677&r2=741678&view=diff
==============================================================================
--- poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java (original)
+++ poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java Fri Feb 6 18:59:24 2009
@@ -118,6 +118,11 @@
/**
* Set the width (in units of 1/256th of a character width)
+ * <p>
+ * The maximum column width for an individual cell is 255 characters.
+ * This value represents the number of characters that can be displayed
+ * in a cell that is formatted with the standard font.
+ * </p>
*
* @param columnIndex - the column to set (0-based)
* @param width - the width in units of 1/256th of a character width
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=741678&r1=741677&r2=741678&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Fri Feb 6 18:59:24 2009
@@ -1266,11 +1266,19 @@
/**
* Set the width (in units of 1/256th of a character width)
+ * <p>
+ * The maximum column width for an individual cell is 255 characters.
+ * This value represents the number of characters that can be displayed
+ * in a cell that is formatted with the standard font.
+ * </p>
*
* @param columnIndex - the column to set (0-based)
* @param width - the width in units of 1/256th of a character width
+ * @throws IllegalArgumentException if width > 65536 (the maximum column width in Excel)
*/
public void setColumnWidth(int columnIndex, int width) {
+ if(width > 255*256) throw new IllegalArgumentException("The maximum column width for an individual cell is 255 characters.");
+
columnHelper.setColWidth(columnIndex, (double)width/256);
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=741678&r1=741677&r2=741678&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Fri Feb 6 18:59:24 2009
@@ -184,6 +184,18 @@
assertEquals(1, sheet.getRowBreaks().length);
}
+ public void testMaxColumnWidth() {
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ Sheet sheet = workbook.createSheet("Sheet 1");
+ sheet.setColumnWidth(0, 255*256); //the limit
+ try {
+ sheet.setColumnWidth(0, 256*256); //the limit
+ fail("expected exception");
+ } catch (Exception e){
+ ;
+ }
+ }
+
public void testGetSetColumnBreaks() {
XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet 1");
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java?rev=741678&r1=741677&r2=741678&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java Fri Feb 6 18:59:24 2009
@@ -54,4 +54,15 @@
assertEquals((short)100,sheet.getColumnWidth((short)9));
assertEquals((short)100,sheet.getColumnWidth((short)10));
}
+
+ public void testMaxColumnWidth() {
+ Sheet sheet = Sheet.createSheet();
+ sheet.setColumnWidth(0, 255*256); //the limit
+ try {
+ sheet.setColumnWidth(0, 256*256); //the limit
+ fail("expected exception");
+ } catch (Exception e){
+ ;
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org