diff options
author | Nick Burch <nick@apache.org> | 2008-04-05 13:38:52 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2008-04-05 13:38:52 +0000 |
commit | 2486c5524cca2afd7c8b31b6f468945cdd18de1b (patch) | |
tree | 1e88336abe60db6043b6fcdadbafeaf19f8d83c9 /src/java | |
parent | 92396054a43e3625005ba45228d29b5dace44421 (diff) | |
download | poi-2486c5524cca2afd7c8b31b6f468945cdd18de1b.tar.gz poi-2486c5524cca2afd7c8b31b6f468945cdd18de1b.zip |
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-645088 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r643625 | josh | 2008-04-01 23:18:25 +0100 (Tue, 01 Apr 2008) | 1 line
Bug #44733 - DPRODUCT function should be index 189, not 191
........
r643654 | josh | 2008-04-02 00:53:51 +0100 (Wed, 02 Apr 2008) | 1 line
fix for bug 44710 - Incorrect skip() of second formula in DATAVALIDATION record
........
r643670 | klute | 2008-04-02 01:50:45 +0100 (Wed, 02 Apr 2008) | 1 line
44694 - HPSF: Support for property sets without sections
........
r643672 | klute | 2008-04-02 01:55:52 +0100 (Wed, 02 Apr 2008) | 1 line
Restored an entry that had been deleted by chance.
........
r643831 | yegor | 2008-04-02 11:20:31 +0100 (Wed, 02 Apr 2008) | 1 line
added set accessor to indentation level
........
r643834 | yegor | 2008-04-02 11:25:18 +0100 (Wed, 02 Apr 2008) | 1 line
Fixed inconsistency between HSSFSHeet.getColumnWidth and HSSFSheet.getDefaultColumnWidth: getColumnWidth should always return width measured in 1/256th units.
........
r644343 | nick | 2008-04-03 16:04:52 +0100 (Thu, 03 Apr 2008) | 1 line
Make a bit of a start on being able to edit chart titles, based on the email to user@poi from Russ on the 2nd of April. Not quite there though
........
r644473 | josh | 2008-04-03 21:25:53 +0100 (Thu, 03 Apr 2008) | 1 line
Fix for bug 44739 - Conditional formatting (regions with max row/col index)
........
r644509 | josh | 2008-04-03 22:17:26 +0100 (Thu, 03 Apr 2008) | 1 line
Follow up fix after r644473 (bug 44739) TestHSSFConditionalFormatting had a bug and wasn't yet included in the test suite hierarchy
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@645096 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/poi/hpsf/MutablePropertySet.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/poi/hpsf/PropertySet.java | 10 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/model/Sheet.java | 12 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/CFHeaderRecord.java | 4 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/DVRecord.java | 25 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/cf/CellRange.java | 70 |
6 files changed, 54 insertions, 69 deletions
diff --git a/src/java/org/apache/poi/hpsf/MutablePropertySet.java b/src/java/org/apache/poi/hpsf/MutablePropertySet.java index 34281b90c1..5ecbfeee3d 100644 --- a/src/java/org/apache/poi/hpsf/MutablePropertySet.java +++ b/src/java/org/apache/poi/hpsf/MutablePropertySet.java @@ -92,6 +92,8 @@ public class MutablePropertySet extends PropertySet osVersion = ps.getOSVersion(); setClassID(ps.getClassID()); clearSections(); + if (sections == null) + sections = new LinkedList(); for (final Iterator i = ps.getSections().iterator(); i.hasNext();) { final MutableSection s = new MutableSection((Section) (i.next())); diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java index 0bfbb8f32f..b39ba08bfa 100644 --- a/src/java/org/apache/poi/hpsf/PropertySet.java +++ b/src/java/org/apache/poi/hpsf/PropertySet.java @@ -387,7 +387,7 @@ public class PropertySet o += ClassID.LENGTH; final long sectionCount = LittleEndian.getUInt(src, o); o += LittleEndian.INT_SIZE; - if (sectionCount < 1) + if (sectionCount < 0) return false; return true; } @@ -426,9 +426,9 @@ public class PropertySet o += ClassID.LENGTH; final int sectionCount = LittleEndian.getInt(src, o); o += LittleEndian.INT_SIZE; - if (sectionCount <= 0) + if (sectionCount < 0) throw new HPSFRuntimeException("Section count " + sectionCount + - " must be greater than 0."); + " is negative."); /* * Read the sections, which are following the header. They @@ -468,6 +468,8 @@ public class PropertySet */ public boolean isSummaryInformation() { + if (sections.size() <= 0) + return false; return Util.equal(((Section) sections.get(0)).getFormatID().getBytes(), SectionIDMap.SUMMARY_INFORMATION_ID); } @@ -483,6 +485,8 @@ public class PropertySet */ public boolean isDocumentSummaryInformation() { + if (sections.size() <= 0) + return false; return Util.equal(((Section) sections.get(0)).getFormatID().getBytes(), SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]); } diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 451cde7579..2af25e7481 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -1879,12 +1879,12 @@ public class Sheet implements Model } /** - * get the width of a given column in units of 1/20th of a point width (twips?) + * get the width of a given column in units of 1/256th of a character width * @param column index * @see org.apache.poi.hssf.record.DefaultColWidthRecord * @see org.apache.poi.hssf.record.ColumnInfoRecord * @see #setColumnWidth(short,short) - * @return column width in units of 1/20th of a point (twips?) + * @return column width in units of 1/256th of a character width */ public short getColumnWidth(short column) @@ -1912,7 +1912,9 @@ public class Sheet implements Model } else { - retval = defaultcolwidth.getColWidth(); + //default column width is measured in characters + //multiply + retval = (short)(256*defaultcolwidth.getColWidth()); } return retval; } @@ -1951,9 +1953,9 @@ public class Sheet implements Model } /** - * set the width for a given column in 1/20th of a character width units + * set the width for a given column in 1/256th of a character width units * @param column - the column number - * @param width (in units of 1/20th of a character width) + * @param width (in units of 1/256th of a character width) */ public void setColumnWidth(short column, short width) { diff --git a/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java index 7f2d5c3197..d74d54ab17 100644 --- a/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java +++ b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java @@ -58,12 +58,12 @@ public final class CFHeaderRecord extends Record { field_1_numcf = in.readShort(); field_2_need_recalculation = in.readShort(); - field_3_enclosing_cell_range = new CellRange(in.readShort(),in.readShort(),in.readShort(),in.readShort()); + field_3_enclosing_cell_range = new CellRange(in.readUShort(), in.readUShort(), in.readUShort(), in.readUShort()); int numCellRanges = in.readShort(); CellRange[] crs = new CellRange[numCellRanges]; for( int i=0; i<numCellRanges; i++) { - crs[i] = new CellRange(in.readShort(),in.readShort(),in.readShort(),in.readShort()); + crs[i] = new CellRange(in.readUShort(),in.readUShort(),in.readUShort(),in.readUShort()); } field_4_cell_ranges = crs; } diff --git a/src/java/org/apache/poi/hssf/record/DVRecord.java b/src/java/org/apache/poi/hssf/record/DVRecord.java index a7b68a1743..c4e37114d9 100644 --- a/src/java/org/apache/poi/hssf/record/DVRecord.java +++ b/src/java/org/apache/poi/hssf/record/DVRecord.java @@ -28,7 +28,7 @@ import org.apache.poi.util.LittleEndian; import org.apache.poi.util.StringUtil; /** - * Title: DV Record<P> + * Title: DATAVALIDATION Record (0x01BE)<p/> * Description: This record stores data validation settings and a list of cell ranges * which contain these settings. The data validation settings of a sheet * are stored in a sequential list of DV records. This list is followed by @@ -36,7 +36,7 @@ import org.apache.poi.util.StringUtil; * @author Dragos Buleandra (dragos.buleandra@trade2b.ro) * @version 2.0-pre */ -public class DVRecord extends Record +public final class DVRecord extends Record { public final static short sid = 0x01BE; @@ -170,11 +170,6 @@ public class DVRecord extends Record this.field_not_used_1 = in.readShort(); //read first formula data condition - // Not sure if this was needed or not... -// try { -// in.skip(this.field_size_first_formula); -// } catch(IOException e) { throw new IllegalStateException(e); } - int token_pos = 0; while (token_pos < this.field_size_first_formula) { @@ -187,14 +182,14 @@ public class DVRecord extends Record this.field_not_used_2 = in.readShort(); //read sec formula data condition - //Not sure if this was needed or not... - try { - in.skip(this.field_size_sec_formula); - } catch(IOException e) { - e.printStackTrace(); - throw new IllegalStateException(e.getMessage()); + if (false) { // TODO - prior to bug 44710 this 'skip' was being executed. write a junit to confirm this fix + try { + in.skip(this.field_size_sec_formula); + } catch(IOException e) { + e.printStackTrace(); + throw new IllegalStateException(e.getMessage()); + } } - token_pos = 0; while (token_pos < this.field_size_sec_formula) { @@ -516,7 +511,7 @@ public class DVRecord extends Record /**@todo DVRecord = Serializare */ - private class StringHandler + private static final class StringHandler { private int _string_length = 0x0001; private byte _string_unicode_flag = 0x00; diff --git a/src/java/org/apache/poi/hssf/record/cf/CellRange.java b/src/java/org/apache/poi/hssf/record/cf/CellRange.java index 16093ee582..f45b79b003 100644 --- a/src/java/org/apache/poi/hssf/record/cf/CellRange.java +++ b/src/java/org/apache/poi/hssf/record/cf/CellRange.java @@ -29,12 +29,10 @@ import org.apache.poi.hssf.util.Region; */ public final class CellRange { - /** - * max index for both row and column<p/> - * - * Note - this value converts to <tt>-1</tt> when cast to a <tt>short</tt> - */ - private static final int MAX_INDEX = Integer.MAX_VALUE; + /** max 65536 rows in BIFF8 */ + private static final int LAST_ROW_INDEX = 0x00FFFF; + /** max 256 columns in BIFF8 */ + private static final int LAST_COLUMN_INDEX = 0x00FF; private static final Region[] EMPTY_REGION_ARRAY = { }; @@ -57,54 +55,46 @@ public final class CellRange + ", " + firstColumn + ", " + lastColumn + ")"); } _firstRow = firstRow; - _lastRow = convertM1ToMax(lastRow); + _lastRow = convertM1ToMax(lastRow, LAST_ROW_INDEX); _firstColumn = firstColumn; - _lastColumn = convertM1ToMax(lastColumn); + _lastColumn = convertM1ToMax(lastColumn, LAST_COLUMN_INDEX); } - private static int convertM1ToMax(int lastIx) { + /** + * Range arithmetic is easier when using a large positive number for 'max row or column' + * instead of <tt>-1</tt>. + */ + private static int convertM1ToMax(int lastIx, int maxIndex) { if(lastIx < 0) { - return MAX_INDEX; - } - return lastIx; - } - private static int convertMaxToM1(int lastIx) { - if(lastIx == MAX_INDEX) { - return -1; + return maxIndex; } return lastIx; } public boolean isFullColumnRange() { - return _firstColumn == 0 && _lastColumn == MAX_INDEX; + return _firstRow == 0 && _lastRow == LAST_ROW_INDEX; } public boolean isFullRowRange() { - return _firstRow == 0 && _lastRow == MAX_INDEX; + return _firstColumn == 0 && _lastColumn == LAST_COLUMN_INDEX; } - public CellRange(Region r) { - this(r.getRowFrom(), r.getRowTo(), r.getColumnFrom(), r.getColumnTo()); + private static CellRange createFromRegion(Region r) { + return new CellRange(r.getRowFrom(), r.getRowTo(), r.getColumnFrom(), r.getColumnTo()); } - - private static boolean isValid(int firstRow, int lastRow, int firstColumn, int lastColumn) { - if(lastRow == -1) { - if(firstRow !=0) { - return false; - } + if(lastRow < 0 || lastRow > LAST_ROW_INDEX) { + return false; } - if(firstRow < 0 || lastRow < -1) { + if(firstRow < 0 || firstRow > LAST_ROW_INDEX) { return false; } - if(lastColumn == -1) { - if(firstColumn !=0) { - return false; - } + if(lastColumn < 0 || lastColumn > LAST_COLUMN_INDEX) { + return false; } - if(firstColumn < 0 || lastColumn < -1) { + if(firstColumn < 0 || firstColumn > LAST_COLUMN_INDEX) { return false; } return true; @@ -114,23 +104,17 @@ public final class CellRange { return _firstRow; } - /** - * @return <tt>-1</tt> for whole column ranges - */ public int getLastRow() { - return convertMaxToM1(_lastRow); + return _lastRow; } public int getFirstColumn() { return _firstColumn; } - /** - * @return <tt>-1</tt> for whole row ranges - */ public int getLastColumn() { - return convertMaxToM1(_lastColumn); + return _lastColumn; } public static final int NO_INTERSECTION = 1; @@ -374,7 +358,7 @@ public final class CellRange CellRange[] result = new CellRange[regions.length]; for( int i=0; i<regions.length; i++) { - result[i] = new CellRange(regions[i]); + result[i] = createFromRegion(regions[i]); } return result; } @@ -404,10 +388,8 @@ public final class CellRange private Region convertToRegion() { - int lastRow = convertMaxToM1(_lastRow); - int lastColumn = convertMaxToM1(_lastColumn); - return new Region(_firstRow, (short)_firstColumn, lastRow, (short)lastColumn); + return new Region(_firstRow, (short)_firstColumn, _lastRow, (short)_lastColumn); } |