You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by mak <mu...@gmail.com> on 2013/07/19 06:39:08 UTC

Excel file saved by javamail API not readable to apache poi API

MailExtractor.java

*    Multipart multiPart = (Multipart) message.getContent(); 
    int numberOfParts = multiPart.getCount(); 
    for (int partCount = 0; partCount < numberOfParts; partCount++) { 
     MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount); 
     if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) { 
       // this part is attachment 
       String fileName = part.getFileName(); 
       attachFiles += fileName + ", "; 
       part.saveFile(saveDir + File.separator + fileName); 
     } 
     else { 
       // this part may be the message content 
       messageContent = part.getContent().toString(); 
     }
    }*

Now another program polls that disk directory and reads all incoming file. I
am only concerned with File extensions - xls/xlsx, so I use apache poi to
read the files:


*//AvailabilityDirectoryPoller.java 
FileInputStream fs = new FileInputStream(file); 
 Workbook wb = null; 
 Sheet sheet = null; 
 if(FilenameUtils.getExtension(file.getName()).equalsIgnoreCase("xls")){ 
   wb = new HSSFWorkbook(fs);   //line no 178 
   sheet = (HSSFSheet)wb.getSheetAt(0); 
 } 
 else{ 
   wb = new XSSFWorkbook(fs); 
   sheet = (XSSFSheet)wb.getSheetAt(0); 
 } *

This sometimes(read random) results in error as below 



[2013-07-18 23:38:32,409] ERROR [AvailabilityDirectoryPoller]: Exception in
I/O Reading file 
java.io.IOException: Your file contains 79 sectors, but the initial DIFAT
array at index 1 referenced block # 98. This isn't allowed and  your file is
corrupt 
    at
org.apache.poi.poifs.storage.BlockAllocationTableReader.<init>(BlockAllocationTableReader.java:103) 
    at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:151) 
    at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:322) 
    at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:303) 
    at
com.db.mmrepo.app.avl.bespoke.AvailabilityDirectoryPoller.process(AvailabilityDirectoryPoller.java:178) 
    at
com.db.mmrepo.app.avl.bespoke.AvailabilityDirectoryPoller.fileFound(AvailabilityDirectoryPoller.java:73) 
    at
org.sadun.util.polling.DefaultListener.receive(DefaultListener.java:43) 
    at com.deltax.util.listener.SignalQueue.run(Unknown Source)



If I open the javamail saved file in MS Excel, it opens with no
warnings/errors.


Please advice.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Excel-file-saved-by-javamail-API-not-readable-to-apache-poi-API-tp5713266.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Where are the ooxml-schemas Sources?

Posted by David Law <da...@apconsult.de>.
Hi Dominik,

danke!  We really need to either correct the FAQ's
(because, contrary to what is stated in FAQ #14,
  the Sources are not available in any repository)
or, better still, check the sources in to make FAQ #14
correct, so people will not have to do the build.

All the best,
DaveLaw


On 30.01.2014 21:45, Dominik Stadler wrote:
> Hi, seems your best bet is to run the build locally, you can get the
> jar built via Ant-target "compile-ooxml-xsds", the resulting jar is
> ooxml-lib/ooxml-schemas-src-1.1.jar
>
> Dominik
>
> On Thu, Jan 30, 2014 at 12:29 PM, David Law <da...@apconsult.de> wrote:
>> Hi Nick,
>>
>> nice to hear from you.
>>
>> I confess to being an absolute beginner regarding maven.
>> Having said that, it doesn't seem to be rocket science,
>> so I would expect putting "ooxml-schemas-src"
>> or (maven standard) "ooxml-schemas-1.1-sources"
>> into Google should yield a hit.
>>
>> I certainly can't find anything at maven central.
>> And I don't seem to be
>> <http://permalink.gmane.org/gmane.comp.jakarta.poi.user/19467> alone there.
>>
>> All the best,
>> DaveLaw
>>
>>
>>
>> On 30.01.2014 12:13, Nick Burch wrote:
>>> On Thu, 30 Jan 2014, David Law wrote:
>>>> I can't find 'em anywhere, & having reached the last page of the Internet
>>>> am stumped.
>>>>
>>>> So maybe someone could post an exact link to where they are please?
>>>
>>> Hopefully one of our maven gurus can suggest somewhere suitable to find
>>> them. I believe that if you ask maven in the right way for the source, it
>>> ought to just auto-download the sources for you, does that not work?
>>>
>>>> (I also tried searching for poi-ooxml-schemas sources, also to no avail)
>>>
>>> poi-ooxml-schemas is an auto-generated subset. Best bet for that is to
>>> download the poi sources, run the build, and have them generated for you by
>>> ant
>>>
>>> Nick
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Where are the ooxml-schemas Sources?

Posted by Dominik Stadler <do...@gmx.at>.
Hi, seems your best bet is to run the build locally, you can get the
jar built via Ant-target "compile-ooxml-xsds", the resulting jar is
ooxml-lib/ooxml-schemas-src-1.1.jar

Dominik

On Thu, Jan 30, 2014 at 12:29 PM, David Law <da...@apconsult.de> wrote:
> Hi Nick,
>
> nice to hear from you.
>
> I confess to being an absolute beginner regarding maven.
> Having said that, it doesn't seem to be rocket science,
> so I would expect putting "ooxml-schemas-src"
> or (maven standard) "ooxml-schemas-1.1-sources"
> into Google should yield a hit.
>
> I certainly can't find anything at maven central.
> And I don't seem to be
> <http://permalink.gmane.org/gmane.comp.jakarta.poi.user/19467> alone there.
>
> All the best,
> DaveLaw
>
>
>
> On 30.01.2014 12:13, Nick Burch wrote:
>>
>> On Thu, 30 Jan 2014, David Law wrote:
>>>
>>> I can't find 'em anywhere, & having reached the last page of the Internet
>>> am stumped.
>>>
>>> So maybe someone could post an exact link to where they are please?
>>
>>
>> Hopefully one of our maven gurus can suggest somewhere suitable to find
>> them. I believe that if you ask maven in the right way for the source, it
>> ought to just auto-download the sources for you, does that not work?
>>
>>> (I also tried searching for poi-ooxml-schemas sources, also to no avail)
>>
>>
>> poi-ooxml-schemas is an auto-generated subset. Best bet for that is to
>> download the poi sources, run the build, and have them generated for you by
>> ant
>>
>> Nick
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Where are the ooxml-schemas Sources?

Posted by David Law <da...@apconsult.de>.
Hi Nick,

nice to hear from you.

I confess to being an absolute beginner regarding maven.
Having said that, it doesn't seem to be rocket science,
so I would expect putting "ooxml-schemas-src"
or (maven standard) "ooxml-schemas-1.1-sources"
into Google should yield a hit.

I certainly can't find anything at maven central.
And I don't seem to be 
<http://permalink.gmane.org/gmane.comp.jakarta.poi.user/19467> alone there.

All the best,
DaveLaw


On 30.01.2014 12:13, Nick Burch wrote:
> On Thu, 30 Jan 2014, David Law wrote:
>> I can't find 'em anywhere, & having reached the last page of the 
>> Internet am stumped.
>>
>> So maybe someone could post an exact link to where they are please?
>
> Hopefully one of our maven gurus can suggest somewhere suitable to 
> find them. I believe that if you ask maven in the right way for the 
> source, it ought to just auto-download the sources for you, does that 
> not work?
>
>> (I also tried searching for poi-ooxml-schemas sources, also to no avail)
>
> poi-ooxml-schemas is an auto-generated subset. Best bet for that is to 
> download the poi sources, run the build, and have them generated for 
> you by ant
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>


Re: Where are the ooxml-schemas Sources?

Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 30 Jan 2014, David Law wrote:
> I can't find 'em anywhere, & having reached the last page of the Internet am 
> stumped.
>
> So maybe someone could post an exact link to where they are please?

Hopefully one of our maven gurus can suggest somewhere suitable to find 
them. I believe that if you ask maven in the right way for the source, it 
ought to just auto-download the sources for you, does that not work?

> (I also tried searching for poi-ooxml-schemas sources, also to no avail)

poi-ooxml-schemas is an auto-generated subset. Best bet for that is to 
download the poi sources, run the build, and have them generated for you 
by ant

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Please check in the ooxml-schemas Sources!

Posted by David Law <Da...@apconsult.de>.
Bug 56117 added

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

All the best,
DaveLaw

On 06/02/2014 14:04, Dominik Stadler wrote:
> Hi,
>
> Can you please report this as Bug at
> https://issues.apache.org/bugzilla/enter_bug.cgi?product=POI, this way
> it will not be burried in emails...
>
> Thanks... Dominik.
>
> On Thu, Feb 6, 2014 at 1:00 AM, David Law <da...@apconsult.de> wrote:
>> Could I suggest someone check in the ooxml-schemas sources?
>>
>> Contrary to what is stated in FAQ 14, they are nowhere to be found.
>>
>> All the best,
>> DaveLaw
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Please check in the ooxml-schemas Sources!

Posted by Dominik Stadler <do...@gmx.at>.
Hi,

Can you please report this as Bug at
https://issues.apache.org/bugzilla/enter_bug.cgi?product=POI, this way
it will not be burried in emails...

Thanks... Dominik.

On Thu, Feb 6, 2014 at 1:00 AM, David Law <da...@apconsult.de> wrote:
> Could I suggest someone check in the ooxml-schemas sources?
>
> Contrary to what is stated in FAQ 14, they are nowhere to be found.
>
> All the best,
> DaveLaw
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Please check in the ooxml-schemas Sources!

Posted by David Law <da...@apconsult.de>.
Could I suggest someone check in the ooxml-schemas sources?

Contrary to what is stated in FAQ 14, they are nowhere to be found.

All the best,
DaveLaw

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Where are the ooxml-schemas Sources?

Posted by David Law <Da...@apconsult.de>.
Hi,

having read FAQ 14 <http://poi.apache.org/faq.html#faq-N10109>, where it 
states the ooxml-schemas sources
"ooxml-schemas-src" are available on maven, I've spent several
hours dredging the Internet (including maven) for them.

I can't find 'em anywhere, & having reached the last page of the 
Internet am stumped.

So maybe someone could post an exact link to where they are please?

(I also tried searching for poi-ooxml-schemas sources, also to no avail)

All the best,
DaveLaw

Re: Excel file saved by javamail API not readable to apache poi API

Posted by David Law <Da...@apconsult.de>.
It may be a longshot, but as its sporadic, make sure the file is
not still open in javaMail when you start reading it with poi.

Depending on the File-system, that can make a difference.

If possible, I try to have the sending-system rename the File
& the receiving-system will first "see" it after the rename.

Rename is a fantastic semaphore.

All the best,
DaveLaw

On 19/07/2013 10:50, Nick Burch wrote:
> On Thu, 18 Jul 2013, mak wrote:
>> [2013-07-18 23:38:32,409] ERROR [AvailabilityDirectoryPoller]: 
>> Exception in
>> I/O Reading file
>> java.io.IOException: Your file contains 79 sectors, but the initial 
>> DIFAT
>> array at index 1 referenced block # 98. This isn't allowed and your 
>> file is
>> corrupt
>
> Try reading it with NPOIFSFileSystem rather than POIFSFileSystem, the 
> former is a bit more tolerant of some odd setups than the latter. 
> Otherwise, make sure that the checksum (eg md5/sha1) of the file is 
> correct after the transfer, to ensure that your wrapping / unwrapping 
> didn't corrupt any of the file
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Excel file saved by javamail API not readable to apache poi API

Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 18 Jul 2013, mak wrote:
> [2013-07-18 23:38:32,409] ERROR [AvailabilityDirectoryPoller]: Exception in
> I/O Reading file
> java.io.IOException: Your file contains 79 sectors, but the initial DIFAT
> array at index 1 referenced block # 98. This isn't allowed and  your file is
> corrupt

Try reading it with NPOIFSFileSystem rather than POIFSFileSystem, the 
former is a bit more tolerant of some odd setups than the latter. 
Otherwise, make sure that the checksum (eg md5/sha1) of the file is 
correct after the transfer, to ensure that your wrapping / unwrapping 
didn't corrupt any of the file

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org