Bug 51504 - avoid NPE when DefaultRowHeight or DefaultColumnWidth records are missing
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147049 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aded116bd7
commit
3f4627ec37
@ -34,6 +34,7 @@
|
||||
|
||||
<changes>
|
||||
<release version="3.8-beta4" date="2011-??-??">
|
||||
<action dev="poi-developers" type="fix">51504 - avoid NPE when DefaultRowHeight or DefaultColumnWidth records are missing</action>
|
||||
<action dev="poi-developers" type="fix">51502 - Correct Subtotal function javadoc entry</action>
|
||||
<action dev="poi-developers" type="add">Support for hyperlinks in SXSSF</action>
|
||||
<action dev="poi-developers" type="fix">49933 - Word 6/95 documents with sections cause ArrayIndexOutOfBoundsException</action>
|
||||
|
@ -65,12 +65,12 @@ import org.apache.poi.hssf.record.aggregates.DataValidityTable;
|
||||
import org.apache.poi.hssf.record.aggregates.MergedCellsTable;
|
||||
import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
|
||||
import org.apache.poi.hssf.record.aggregates.RecordAggregate;
|
||||
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
|
||||
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
|
||||
import org.apache.poi.hssf.record.aggregates.RecordAggregate.PositionTrackingVisitor;
|
||||
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
|
||||
import org.apache.poi.ss.formula.FormulaShifter;
|
||||
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
|
||||
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
|
||||
import org.apache.poi.hssf.util.PaneInformation;
|
||||
import org.apache.poi.ss.formula.FormulaShifter;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.util.Internal;
|
||||
import org.apache.poi.util.POILogFactory;
|
||||
@ -110,8 +110,8 @@ public final class InternalSheet {
|
||||
protected PrintGridlinesRecord printGridlines = null;
|
||||
protected GridsetRecord gridset = null;
|
||||
private GutsRecord _gutsRecord;
|
||||
protected DefaultColWidthRecord defaultcolwidth = null;
|
||||
protected DefaultRowHeightRecord defaultrowheight = null;
|
||||
protected DefaultColWidthRecord defaultcolwidth = new DefaultColWidthRecord();
|
||||
protected DefaultRowHeightRecord defaultrowheight = new DefaultRowHeightRecord();
|
||||
private PageSettingsBlock _psBlock;
|
||||
|
||||
/**
|
||||
@ -272,7 +272,7 @@ public final class InternalSheet {
|
||||
records.add(rec);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (recSid == EOFRecord.sid) {
|
||||
records.add(rec);
|
||||
break;
|
||||
@ -723,7 +723,7 @@ public final class InternalSheet {
|
||||
public void removeRow(RowRecord row) {
|
||||
_rowsAggregate.removeRow(row);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all the value records (from LOC). Records will be returned from the first
|
||||
* record (starting at LOC) which is a value record.
|
||||
@ -753,7 +753,7 @@ public final class InternalSheet {
|
||||
* subsequent calls will return values in (physical) sequence or NULL when you get to the end.
|
||||
*
|
||||
* @return Array of CellValueRecordInterface representing the remaining value records
|
||||
* @deprecated use {@link #getValueIterator()} instead
|
||||
* @deprecated use {@link #getCellValueIterator()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public CellValueRecordInterface[] getValueRecords() {
|
||||
@ -934,7 +934,7 @@ public final class InternalSheet {
|
||||
DefaultRowHeightRecord retval = new DefaultRowHeightRecord();
|
||||
|
||||
retval.setOptionFlags(( short ) 0);
|
||||
retval.setRowHeight(( short ) 0xff);
|
||||
retval.setRowHeight(DefaultRowHeightRecord.DEFAULT_ROW_HEIGHT);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -955,7 +955,7 @@ public final class InternalSheet {
|
||||
*/
|
||||
private static DefaultColWidthRecord createDefaultColWidth() {
|
||||
DefaultColWidthRecord retval = new DefaultColWidthRecord();
|
||||
retval.setColWidth(( short ) 8);
|
||||
retval.setColWidth(DefaultColWidthRecord.DEFAULT_COLUMN_WIDTH);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,14 @@ public final class DefaultColWidthRecord extends StandardRecord {
|
||||
public final static short sid = 0x0055;
|
||||
private int field_1_col_width;
|
||||
|
||||
/**
|
||||
* The default column width is 8 characters
|
||||
*/
|
||||
public final static int DEFAULT_COLUMN_WIDTH = 0x0008;
|
||||
|
||||
public DefaultColWidthRecord()
|
||||
{
|
||||
field_1_col_width = DEFAULT_COLUMN_WIDTH;
|
||||
}
|
||||
|
||||
public DefaultColWidthRecord(RecordInputStream in)
|
||||
|
@ -15,7 +15,7 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
|
||||
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
@ -38,8 +38,15 @@ public final class DefaultRowHeightRecord
|
||||
private short field_1_option_flags;
|
||||
private short field_2_row_height;
|
||||
|
||||
/**
|
||||
* The default row height for empty rows is 255 twips (255 / 20 == 12.75 points)
|
||||
*/
|
||||
public static final short DEFAULT_ROW_HEIGHT = 0xFF;
|
||||
|
||||
public DefaultRowHeightRecord()
|
||||
{
|
||||
field_1_option_flags = 0x0000;
|
||||
field_2_row_height = DEFAULT_ROW_HEIGHT;
|
||||
}
|
||||
|
||||
public DefaultRowHeightRecord(RecordInputStream in)
|
||||
|
@ -736,6 +736,28 @@ public final class TestHSSFSheet extends BaseTestSheet {
|
||||
assertEquals(40000, sh.getColumnWidth(0));
|
||||
}
|
||||
|
||||
|
||||
public void testDefaultColumnWidth() {
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook( "12843-1.xls" );
|
||||
HSSFSheet sheet = wb.getSheetAt( 7 );
|
||||
// shall not be NPE
|
||||
assertEquals(8, sheet.getDefaultColumnWidth());
|
||||
assertEquals(8*256, sheet.getColumnWidth(0));
|
||||
|
||||
assertEquals(0xFF, sheet.getDefaultRowHeight());
|
||||
|
||||
wb = HSSFTestDataSamples.openSampleWorkbook( "34775.xls" );
|
||||
// second and third sheets miss DefaultColWidthRecord
|
||||
for(int i = 1; i <= 2; i++){
|
||||
int dw = wb.getSheetAt( i ).getDefaultColumnWidth();
|
||||
assertEquals(8, dw);
|
||||
int cw = wb.getSheetAt( i ).getColumnWidth(0);
|
||||
assertEquals(8*256, cw);
|
||||
|
||||
assertEquals(0xFF, sheet.getDefaultRowHeight());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Some utilities write Excel files without the ROW records.
|
||||
* Excel, ooo, and google docs are OK with this.
|
||||
|
Loading…
Reference in New Issue
Block a user