aspose file tools*
The moose likes JSF and the fly likes opening an xls file from the database in jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "opening an xls file from the database in jsf" Watch "opening an xls file from the database in jsf" New topic
Author

opening an xls file from the database in jsf

sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
I have been given the task of opening xls files in the browser using jsf and oracle, these files are stored in the database.
How do I accomplish this?

Thanks,
Sonia
Viswanath Tg
Greenhorn

Joined: Nov 27, 2007
Posts: 20
Step 1 : Load the data to a object of type List
Step 2 : Iterate the list of the object and write the data corresponding to the excel file...
Step 3 : upload the data..

Code Snippet...

String fileName = "excelFileName";

// Create a new work book
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("mySheet1");
........
..........
........

for (SlectedObjectTO : objectList)
{
HSSFRow rows = sheet.createRow(j);

..........
........

}

// Writing data to the output stream.
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()
.getResponse();
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xls");
response.setContentType("application/vnd.ms-excel");
log.debug("Response contect :: " + response.getContentType());
ServletOutputStream out;

try
{
out = response.getOutputStream();
wb.write(out);
out.flush();
out.close();
}


Required API :: POI


Helping hands are better than praying lips
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
Hi,

I downloaded the poi libraries and put it in eclipse classpath and in the WEB-INF/lib directory.
But I am getting a ClassNotFoundException: org.apache.poi.usermodel.HSSFWorkBook.

Thanks,

Sonia
Viswanath Tg
Greenhorn

Joined: Nov 27, 2007
Posts: 20
Hi,

May be configuration is not correct.
or More than one poi.jar is referred.
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
Hi,

I got it to work. But it looks like all the examples produce an excel file. But they don't open in a swing application for editing. or in the browser. Is there such an example?

Thanks,

Sonia
Viswanath Tg
Greenhorn

Joined: Nov 27, 2007
Posts: 20
Hi,

I am not clear with your query. can you explain it again.

Regards
Viswanath
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
I am writing a jsf application in which when the user selects a file it is pulled from the database. I want to be able to open the xls file in swing or in the browser. I need an example to do that.
They need to be able to edit and save the xls file.

Thanks,

Sonia
Viswanath Tg
Greenhorn

Joined: Nov 27, 2007
Posts: 20
In the previous scenerio when the execl file is populated it will have 3 buttons saying open, save and close
user can click on open and edit the deatils and save.

I will let you know, once i find the solution

Regards
viswanath
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
Thanks, I need it fast though.

Sonia
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
Somebody from the apache mailing list has suggested a Servlet. Trying to figure out how
to map a servlet into a jsf application.

Thanks,

Sonia

Viswanath Tg
Greenhorn

Joined: Nov 27, 2007
Posts: 20
Hi,

Check the following URL.. it may satisfy your requirement.
http://www.icefaces.org/JForum/posts/list/6015.page

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: opening an xls file from the database in jsf