https://issues.apache.org/bugzilla/show_bug.cgi?id=51815

             Bug #: 51815
           Summary: Unable to construct record instance
           Product: POI
           Version: 3.6
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: HSSF
        AssignedTo: [email protected]
        ReportedBy: [email protected]
    Classification: Unclassified


Hi,

I am getting an exception when i am trying to read an excel workbook-
2003(version).Workbook is password protected at workbook level (workbook cant
be opened without password)and write protceted(workbook cant be modified
without password) as well.

Error Details:

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:276)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:201)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:183)
    at test.ExcelReader3.read(ExcelReader3.java:35)
    at test.ExcelReader3.main(ExcelReader3.java:85)
Caused by: java.lang.IllegalArgumentException: Name is too long:
ü?Cl5‹¸…s."‡L^»ô’‘?˜yêââøýù&—JÖö6²¸øÄùjÿËL+?­ÊäÓ'›¿RV¤?ÐqЪ$E}½då
L~íL £¨Î*€=‚ÿ\Ì ë¼%âñð$yCüˆä¿3¿l4
    at
org.apache.poi.hssf.record.WriteAccessRecord.setUsername(WriteAccessRecord.java:107)
    at
org.apache.poi.hssf.record.WriteAccessRecord.<init>(WriteAccessRecord.java:74)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at
org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.java:56)
    ... 9 more
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook
Picked up _JAVA_OPTIONS: -Xrunjvmhook
-Xbootclasspath/a:C:\PROGRA~1\HP\QUICKT~1\bin\JAVA_S~1\classes;C:\PROGRA~1\HP\QUICKT~1\bin\JAVA_S~1\classes\jasmine.jar


My Java code is ->


package test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class ExcelReader3 
{
    public static final String PATH = "C:\\Monika\\2003\\";
    //This is Password protected file(it is protceted by both options- i.e.,
workbook cant be openede without pwd and can't be modified without pwd.) 
    public static final String FILE_NAME = PATH + "Both.xls";

    public void read(String password) throws Exception
    {


        Biff8EncryptionKey.setCurrentUserPassword(password);         

        POIFSFileSystem pois = new POIFSFileSystem(new
FileInputStream(FILE_NAME));        

        //THIS LINE FAILS
        HSSFWorkbook book = new HSSFWorkbook(pois);

        HSSFSheet sheet = book.getSheetAt(0);

        System.out.println(sheet.getSheetName());


        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        book.write(bos);        

        FileOutputStream fs=new FileOutputStream("C:\\testfos.xls");
        int count;
        ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray());
        while((count = bis.read()) != -1) 
        {
            fs.write(count);
        }    
    }

    public static void main(String[] args) 
    {
        try 
        {
            String password = "abc";

            ExcelReader3 reader = new ExcelReader3();    
            reader.read(password);
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }
}


Same code works fine, if excel is only password protected at workbook level
(workbook cant be opened without password)- it gives me an unprotected excel or
only write protceted(workbook cant be modified without password) - it gives me
the file as is,i.e., write protected.

but if excel is protceted by both the cases, it fails.

i am using POI version - 3.6 .Have tried with 3.7 also. but not working.

Pls help!!! :(

Thanks!!!

-- 
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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to