[prev in list] [next in list] [prev in thread] [next in thread]
List: poi-dev
Subject: DO NOT REPLY [Bug 49677] New: About sheet.getDefaultColumnWidth()
From: bugzilla () apache ! org
Date: 2010-07-30 9:17:56
Message-ID: bug-49677-47293 () https ! issues ! apache ! org/bugzilla/
[Download RAW message or body]
https://issues.apache.org/bugzilla/show_bug.cgi?id=49677
Summary: About sheet.getDefaultColumnWidth() serious error!
Product: POI
Version: 3.6
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: normal
Priority: P2
Component: POI Overall
AssignedTo: dev@poi.apache.org
ReportedBy: longxibo@sina.com
Created an attachment (id=25821)
--> (https://issues.apache.org/bugzilla/attachment.cgi?id=25821)
For test
1.For HSSF
//When I adjust xls default column width by excel 2007.then use follow code
//get defaultcolumn width ,broke a excepton
@Test
public void testGetDefaultColumnWidthForHSSF() {
HSSFWorkbook wb;
HSSFSheet sheet;
FileInputStream finput = null;
File file;
String xlsSourceFile = "testfile\\testcolumnwidth.xls";
file = new File(xlsSourceFile);
try {
finput = new FileInputStream(file);
wb = new HSSFWorkbook(finput);
finput.close();
finput = null;
sheet = wb.getSheetAt(2);
System.out.println(sheet.getDefaultColumnWidth());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (finput != null)
finput.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// Exception :
org.apache.poi.hssf.record.RecordFormatException: Unable to construct record
instance
at
org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.java:64)
at
org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:263)
at
org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStream.java:270)
at
org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:236)
at
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:392)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:278)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:203)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:319)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:300)
at poi.TestPOI.testGetDefaultColumnWidthForHSSF(TestPOI.java:437)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.poi.hssf.record.RecordFormatException: Not enough data
(0) to read requested (2) bytes
at
org.apache.poi.hssf.record.RecordInputStream.checkRecordPosition(RecordInputStream.java:215)
at
org.apache.poi.hssf.record.RecordInputStream.readUShort(RecordInputStream.java:260)
at
org.apache.poi.hssf.record.DefaultColWidthRecord.<init>(DefaultColWidthRecord.java:41)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.java:56)
... 33 more
2.For XSSF
//In XSSFSheet.getDefaultColumnWidth
public int getDefaultColumnWidth() {
CTSheetFormatPr pr = worksheet.getSheetFormatPr();
return pr == null ? 8 : (int)pr.getBaseColWidth();
//1. When pt is null ,return 8.It is error .Because I read excel 2007
//help default width is 8.43 char width
//2. When pt not null or default width is adjusted,pr.getBaseCol is
//error,It will return 8 forever.Should call pr.getDefaultColWidth(),But
//return type is int !
}
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic