* (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);
}
}
/**
- * 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);
/**
* 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
/**
* 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);
}
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");
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){
+ ;
+ }
+ }
}