GeeCON Prague 2014*
The moose likes JSF and the fly likes Any tips on how to obtain the Excel data in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Any tips on how to obtain the Excel data in "human" format?" Watch "Any tips on how to obtain the Excel data in "human" format?" New topic
Author

Any tips on how to obtain the Excel data in "human" format?

Marcos Silvestri
Ranch Hand

Joined: Dec 06, 2009
Posts: 62

Hello folks from all over the world!!!

First of all, I'd like to tell that I'm following along this content:

http://livedemo.exadel.com/richfaces-demo/richfaces/fileUpload.jsf

The difference in my project here is that I adapted some portions of the code to meet my requirements, despite the fact that I am want to upload Excel files, what made me change things like:

acceptedTypes="jpg, gif, png, bmp" => acceptedTypes="xls, xlsx"

and

changing the Mime Types for

XLS => application/vnd.ms-excel

XLSX => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Actually, the code is running, my objects of type File get filled up accordingly as I can see through debugging, as well as the proper functionality for the end user. The point is, I'm trying now to retrieve from the uploaded spreadsheets all their contents, and naturally, in human-readable format. My attempt has been through the use of the methods:

filesList.get(i) => filesList is of type List<File>

and

item.getData() => item is obtained from [[[ UploadItem item = event.getUploadItem(); ]]]

By printing on the console, the results I get are:

get(i) => org.richfaces.demo.fileUpload.File@15330ea
getData() => [B@b0838a
get(i) => org.richfaces.demo.fileUpload.File@15330ea
getData() => [B@93a8fa
get(i) => org.richfaces.demo.fileUpload.File@3ae8ac
getData() => [B@93a8fa

Does anyone know how to proceed to obtain the desired data?

Thanks in advance!


DJ aspirant, Engineering undergraduate, Tokusatsus addicted, fond of English language and Asia's, Buddhist, blogger, etc. I'll need to insert all these attributes in a Java class and manage to create methods for handling my overwhelming life
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Well, just using the toString() method of a File object (which is what you did) isn't going to do all of the complicated work of extracting the data from that File, recognizing what kind of data it is, and breaking it up into human-readable pieces. That's your job. You have to write suitable code to do it.
Marcos Silvestri
Ranch Hand

Joined: Dec 06, 2009
Posts: 62

Paul,

Thanks for the answer. I'll have to resume these activities soon and check to see if I'll need further help. Maybe my co-worker will provide some assistance regarding that.

Cheers!
Marcos Silvestri
Ranch Hand

Joined: Dec 06, 2009
Posts: 62


Actually, my last message was aimed at thanking for the attention. Truly, the answer "That's your job. You have to write suitable code to do it" is fully known, Paul.

What I need at the moment is some insights on how to proceed with what I've got, tips on how to carry on...

I know there is an API called Apache POI, I have also used it in another test project, successfully reading an Excel workbook on the file system and displaying its contents on the browser. However, I don't see it applicable to my scenario since this time I don't want to read directly from the file system, but rather, to capture the data of the object that contains the Excel content obtained from a previously Excel file upload.

Either you or another comrade, does anyone have a tip for me?

Thanks in advance!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I haven't used Apache POI for a while, but I don't recall that it was limited to reading data from the file system. I would be surprised to find that, in fact. I would expect that it could take its data from an InputStream. So check that out.

The other half of the puzzle would be to get an InputStream from that file upload. I expect that should be a normal thing to do as well. Check that out too.
Marcos Silvestri
Ranch Hand

Joined: Dec 06, 2009
Posts: 62

Thanks for the reply! I've got something to search for, if it's possible to handle an InputStream from an uploaded Excel file.

Any further ideas are welcome!

Regards!
 
jQuery in Action, 2nd edition
 
subject: Any tips on how to obtain the Excel data in "human" format?