diff options
author | Josh Micich <josh@apache.org> | 2008-09-17 21:54:32 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2008-09-17 21:54:32 +0000 |
commit | b3f56e20b2a20a6e7a423c80e6bf94c92e5eb665 (patch) | |
tree | b9fcde3848387f664510145804543bebc4d09ad7 /src/java | |
parent | fe820eed5c4aba26347a7d117ffd9f4d052552de (diff) | |
download | poi-b3f56e20b2a20a6e7a423c80e6bf94c92e5eb665.tar.gz poi-b3f56e20b2a20a6e7a423c80e6bf94c92e5eb665.zip |
merged 696075,696084 from trunk - (Fix for bug 45805 - 16-bit signed/unsigned problems in HSSFSheet.getColWidth() etc)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@696475 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
7 files changed, 109 insertions, 100 deletions
diff --git a/src/java/org/apache/poi/hssf/dev/HSSF.java b/src/java/org/apache/poi/hssf/dev/HSSF.java index 6583b94c62..07baa3a2ba 100644 --- a/src/java/org/apache/poi/hssf/dev/HSSF.java +++ b/src/java/org/apache/poi/hssf/dev/HSSF.java @@ -135,8 +135,7 @@ public class HSSF c = r.createCell(cellnum + 1, HSSFCell.CELL_TYPE_STRING); c.setCellValue(new HSSFRichTextString("TEST")); - s.setColumnWidth(( short ) (cellnum + 1), - ( short ) ((50 * 8) / (( double ) 1 / 20))); + s.setColumnWidth(cellnum + 1, (int)(50 * 8 / 0.05)); if ((rownum % 2) == 0) { c.setCellStyle(cs2); diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 164399939a..ba62b225c5 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -973,9 +973,7 @@ public final class Sheet implements Model { * get the default column width for the sheet (if the columns do not define their own width) * @return default column width */ - - public short getDefaultColumnWidth() - { + public int getDefaultColumnWidth() { return defaultcolwidth.getColWidth(); } @@ -1009,9 +1007,7 @@ public final class Sheet implements Model { * set the default column width for the sheet (if the columns do not define their own width) * @param dcw default column width */ - - public void setDefaultColumnWidth(short dcw) - { + public void setDefaultColumnWidth(int dcw) { defaultcolwidth.setColWidth(dcw); } @@ -1043,15 +1039,15 @@ public final class Sheet implements Model { * @return column width in units of 1/256th of a character width */ - public short getColumnWidth(short columnIndex) { + public int getColumnWidth(int columnIndex) { ColumnInfoRecord ci = _columnInfos.findColumnInfo(columnIndex); if (ci != null) { - return (short)ci.getColumnWidth(); + return ci.getColumnWidth(); } //default column width is measured in characters //multiply - return (short)(256*defaultcolwidth.getColWidth()); + return (256*defaultcolwidth.getColWidth()); } /** @@ -1084,8 +1080,8 @@ public final class Sheet implements Model { * @param width * (in units of 1/256th of a character width) */ - public void setColumnWidth(short column, short width) { - setColumn( column, new Short(width), null, null, null); + public void setColumnWidth(int column, int width) { + setColumn(column, null, new Integer(width), null, null, null); } /** @@ -1096,7 +1092,7 @@ public final class Sheet implements Model { * @see #setColumnHidden(short,boolean) * @return whether the column is hidden or not. */ - public boolean isColumnHidden(short columnIndex) { + public boolean isColumnHidden(int columnIndex) { ColumnInfoRecord cir = _columnInfos.findColumnInfo(columnIndex); if (cir == null) { return false; @@ -1109,16 +1105,14 @@ public final class Sheet implements Model { * @param column - the column number * @param hidden - whether the column is hidden or not */ - public void setColumnHidden(short column, boolean hidden) - { - setColumn( column, null, null, new Boolean(hidden), null); + public void setColumnHidden(int column, boolean hidden) { + setColumn( column, null, null, null, Boolean.valueOf(hidden), null); } - - public void setColumn(short column, Short width, Integer level, Boolean hidden, Boolean collapsed) { - _columnInfos.setColumn( column, null, width, level, hidden, collapsed ); + public void setDefaultColumnStyle(int column, int styleIndex) { + setColumn(column, new Short((short)styleIndex), null, null, null, null); } - public void setColumn(short column, Short xfStyle, Short width, Integer level, Boolean hidden, Boolean collapsed) { + private void setColumn(int column, Short xfStyle, Integer width, Integer level, Boolean hidden, Boolean collapsed) { _columnInfos.setColumn( column, xfStyle, width, level, hidden, collapsed ); } diff --git a/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java b/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java index 32aef3a6c3..bd04a636f2 100644 --- a/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java +++ b/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java @@ -40,7 +40,7 @@ public final class ColumnInfoRecord extends Record { private static final BitField outlevel = BitFieldFactory.getInstance(0x0700); private static final BitField collapsed = BitFieldFactory.getInstance(0x1000); // Excel seems write values 2, 10, and 260, even though spec says "must be zero" - private short field_6_reserved; + private int field_6_reserved; /** * Creates a column info record with default width and format @@ -64,14 +64,14 @@ public final class ColumnInfoRecord extends Record { protected void fillFields(RecordInputStream in) { - field_1_first_col = in.readShort(); - field_2_last_col = in.readShort(); - field_3_col_width = in.readShort(); - field_4_xf_index = in.readShort(); - field_5_options = in.readShort(); + field_1_first_col = in.readUShort(); + field_2_last_col = in.readUShort(); + field_3_col_width = in.readUShort(); + field_4_xf_index = in.readUShort(); + field_5_options = in.readUShort(); switch(in.remaining()) { case 2: // usual case - field_6_reserved = in.readShort(); + field_6_reserved = in.readUShort(); break; case 1: // often COLINFO gets encoded 1 byte short diff --git a/src/java/org/apache/poi/hssf/record/DefaultColWidthRecord.java b/src/java/org/apache/poi/hssf/record/DefaultColWidthRecord.java index 6a38f4d2ba..ff6270be01 100644 --- a/src/java/org/apache/poi/hssf/record/DefaultColWidthRecord.java +++ b/src/java/org/apache/poi/hssf/record/DefaultColWidthRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,14 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hssf.record; import org.apache.poi.util.LittleEndian; /** - * Title: Default Column Width Record<P> + * Title: Default Column Width Record (0x0055) <P> * Description: Specifies the default width for columns that have no specific * width set.<P> * REFERENCE: PG 302 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> @@ -30,12 +28,9 @@ import org.apache.poi.util.LittleEndian; * @author Jason Height (jheight at chariot dot net dot au) * @version 2.0-pre */ - -public class DefaultColWidthRecord - extends Record -{ - public final static short sid = 0x55; - private short field_1_col_width; +public final class DefaultColWidthRecord extends Record { + public final static short sid = 0x0055; + private int field_1_col_width; public DefaultColWidthRecord() { @@ -61,17 +56,17 @@ public class DefaultColWidthRecord protected void fillFields(RecordInputStream in) { - field_1_col_width = in.readShort(); + field_1_col_width = in.readUShort(); } /** * set the default column width - * @param height defaultwidth for columns + * @param width defaultwidth for columns */ - public void setColWidth(short height) + public void setColWidth(int width) { - field_1_col_width = height; + field_1_col_width = width; } /** @@ -79,7 +74,7 @@ public class DefaultColWidthRecord * @return defaultwidth for columns */ - public short getColWidth() + public int getColWidth() { return field_1_col_width; } @@ -97,9 +92,9 @@ public class DefaultColWidthRecord public int serialize(int offset, byte [] data) { - LittleEndian.putShort(data, 0 + offset, sid); - LittleEndian.putShort(data, 2 + offset, ( short ) 0x2); - LittleEndian.putShort(data, 4 + offset, getColWidth()); + LittleEndian.putUShort(data, 0 + offset, sid); + LittleEndian.putUShort(data, 2 + offset, 0x2); + LittleEndian.putUShort(data, 4 + offset, getColWidth()); return getRecordSize(); } diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java index 0f405bd111..d1dfe30c50 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java @@ -299,7 +299,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { } - public void setColumn(int targetColumnIx, Short xfIndex, Short width, + public void setColumn(int targetColumnIx, Short xfIndex, Integer width, Integer level, Boolean hidden, Boolean collapsed) { ColumnInfoRecord ci = null; int k = 0; @@ -389,13 +389,13 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { /** * Sets all non null fields into the <code>ci</code> parameter. */ - private static void setColumnInfoFields( ColumnInfoRecord ci, Short xfStyle, Short width, - Integer level, Boolean hidden, Boolean collapsed ) { + private static void setColumnInfoFields(ColumnInfoRecord ci, Short xfStyle, Integer width, + Integer level, Boolean hidden, Boolean collapsed) { if (xfStyle != null) { ci.setXFIndex(xfStyle.shortValue()); } if (width != null) { - ci.setColumnWidth(width.shortValue()); + ci.setColumnWidth(width.intValue()); } if (level != null) { ci.setOutlineLevel( level.shortValue() ); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java index 7327fc1833..1afb30f5a6 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java @@ -160,9 +160,9 @@ public class HSSFPicture return anchor; } - private float getColumnWidthInPixels(short column){ + private float getColumnWidthInPixels(int column){ - short cw = patriarch.sheet.getColumnWidth(column); + int cw = patriarch.sheet.getColumnWidth(column); float px = getPixelWidth(column); return cw/px; @@ -178,10 +178,10 @@ public class HSSFPicture return height/PX_ROW; } - private float getPixelWidth(short column){ + private float getPixelWidth(int column){ int def = patriarch.sheet.getDefaultColumnWidth()*256; - short cw = patriarch.sheet.getColumnWidth(column); + int cw = patriarch.sheet.getColumnWidth(column); return cw == def ? PX_DEFAULT : PX_MODIFIED; } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index 231942f440..eb37a57ce8 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -396,47 +396,74 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet /** + * @deprecated (Sep 2008) use {@link #setColumnHidden(int, boolean)} + */ + public void setColumnHidden(short columnIndex, boolean hidden) { + setColumnHidden(columnIndex & 0xFFFF, hidden); + } + + /** + * @deprecated (Sep 2008) use {@link #isColumnHidden(int)} + */ + public boolean isColumnHidden(short columnIndex) { + return isColumnHidden(columnIndex & 0xFFFF); + } + + /** + * @deprecated (Sep 2008) use {@link #setColumnWidth(int, int)} + */ + public void setColumnWidth(short columnIndex, short width) { + setColumnWidth(columnIndex & 0xFFFF, width & 0xFFFF); + } + + /** + * @deprecated (Sep 2008) use {@link #getColumnWidth(int)} + */ + public short getColumnWidth(short columnIndex) { + return (short)getColumnWidth(columnIndex & 0xFFFF); + } + + /** + * @deprecated (Sep 2008) use {@link #setDefaultColumnWidth(int)} + */ + public void setDefaultColumnWidth(short width) { + setDefaultColumnWidth(width & 0xFFFF); + } + + /** * Get the visibility state for a given column. - * @param column - the column to get (0-based) + * @param columnIndex - the column to get (0-based) * @param hidden - the visiblity state of the column */ - - public void setColumnHidden(short column, boolean hidden) - { - sheet.setColumnHidden(column, hidden); + public void setColumnHidden(int columnIndex, boolean hidden) { + sheet.setColumnHidden(columnIndex, hidden); } /** * Get the hidden state for a given column. - * @param column - the column to set (0-based) - * @return hidden - the visiblity state of the column + * @param columnIndex - the column to set (0-based) + * @return hidden - <code>false</code> if the column is visible */ - - public boolean isColumnHidden(short column) - { - return sheet.isColumnHidden(column); + public boolean isColumnHidden(int columnIndex) { + return sheet.isColumnHidden(columnIndex); } /** * set the width (in units of 1/256th of a character width) - * @param column - the column to set (0-based) + * @param columnIndex - the column to set (0-based) * @param width - the width in units of 1/256th of a character width */ - - public void setColumnWidth(short column, short width) - { - sheet.setColumnWidth(column, width); + public void setColumnWidth(int columnIndex, int width) { + sheet.setColumnWidth(columnIndex, width); } /** * get the width (in units of 1/256th of a character width ) - * @param column - the column to set (0-based) + * @param columnIndex - the column to set (0-based) * @return width - the width in units of 1/256th of a character width */ - - public short getColumnWidth(short column) - { - return sheet.getColumnWidth(column); + public int getColumnWidth(int columnIndex) { + return sheet.getColumnWidth(columnIndex); } /** @@ -444,20 +471,25 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet * characters * @return default column width */ - - public short getDefaultColumnWidth() - { + public int getDefaultColumnWidth() { return sheet.getDefaultColumnWidth(); } + /** + * set the default column width for the sheet (if the columns do not define their own width) in + * characters + * @param width default column width + */ + public void setDefaultColumnWidth(int width) { + sheet.setDefaultColumnWidth(width); + } + /** * get the default row height for the sheet (if the rows do not define their own height) in * twips (1/20 of a point) * @return default row height */ - - public short getDefaultRowHeight() - { + public short getDefaultRowHeight() { return sheet.getDefaultRowHeight(); } @@ -473,17 +505,6 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet } /** - * set the default column width for the sheet (if the columns do not define their own width) in - * characters - * @param width default column width - */ - - public void setDefaultColumnWidth(short width) - { - sheet.setDefaultColumnWidth(width); - } - - /** * set the default row height for the sheet (if the rows do not define their own height) in * twips (1/20 of a point) * @param height default row height @@ -1005,19 +1026,19 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet /** * Sets the protection on enabled or disabled * @param protect true => protection enabled; false => protection disabled - * @deprecated use protectSheet(String, boolean, boolean) + * @deprecated (Jul 2007) use {@link #protectSheet(String)} */ public void setProtect(boolean protect) { getSheet().getProtect().setProtect(protect); } - /** - * Sets the protection enabled as well as the password - * @param password to set for protection - */ - public void protectSheet(String password) { - getSheet().protectSheet(password, true, true); //protect objs&scenarios(normal) - } + /** + * Sets the protection enabled as well as the password + * @param password to set for protection + */ + public void protectSheet(String password) { + getSheet().protectSheet(password, true, true); //protect objs&scenarios(normal) + } /** * Sets the zoom magnication for the sheet. The zoom is expressed as a @@ -1630,7 +1651,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet * @param style the style to set */ public void setDefaultColumnStyle(short column, CellStyle style) { - sheet.setColumn(column, new Short(((HSSFCellStyle) style).getIndex()), null, null, null, null); + sheet.setDefaultColumnStyle(column, style.getIndex()); } /** |