OK, the following code...
System.out.println(new Date());
Boolean password = false;
try
{
new NPOIFSFileSystem(new File("d:\\big w p.xlsx"));
password = true;
}
catch (OfficeXmlFileException e)
{
}
System.out.println(new Date());
Works a treat for XLSX files, it completes against a 15MB files within 1 second.
For checking XLS files I have been using...
System.out.println(new Date());
InputStream is = new FileInputStream("d:\\big n p.xls");
System.out.println(new Date());
Workbook wb = new HSSFWorkbook(is);
System.out.println(new Date());
Boolean check = ((HSSFWorkbook)wb).isWriteProtected();
System.out.println(check);
This works fine, but on large files it takes an age, and from the memory
consumption is obviously loading the file entirely into memory.
Is my approach correct, or should I be using something from the event API
instead? I would like if possible to remove the loading into memory.
Tom
-----Original Message-----
From: Nick Burch [mailto:[email protected]]
Sent: 05 September 2011 10:50
To: POI Users List
Subject: RE: How to check whether an XLSX has a read password
On Mon, 5 Sep 2011, Simmons, Tom (GE Oil & Gas, VG) wrote:
> Obviously this is working by loading the file into memory and some of
> the files I received are 50, 80 + MB in size.
Nope, when you pass an InputStream to POIFSFileSystem or NPOIFSFileSystem, only
the first few bytes are checked for the magic marker. If the file is really an
OOXML file, it'll fail fast
Also, if you have files on disk, then you probably don't want to wrap them in
InputStreams. Both NPOIFSFileSystem and OPCPackage have constructors that work
directly with files
> Also, is there a similar idea of sliding window available for the
> older XLS files so as to reduce the memory footprint?
Only for reading, you'd probably want:
http://poi.apache.org/spreadsheet/how-to.html#record_aware_event_api
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional
commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]