views:

80

answers:

6

I am very new to java. I am trying to fetch some data from a database and the result set is displayed in excel. I am able to inetract with database. But how should I go ahead for inserting data into excel sheet.Its simple Java program and in future I would like to generate files in other format say PDF, doc etc. I am looking for an approach with lesser load on CPU, faster.

thanks in advance for help.

A: 

The key words you should google for are OLE and DDE.

Though, Java is not the best language for interface Microsoft's software.

Vanya
+4  A: 

Just spit out a CSV file. It's lightweight and portable. You can grab a csv writer from Apache commons I think but spending the 10 min it would take to write one might be a good learning exercise as well.

CurtainDog
+1  A: 

The new xlsx format is based on Open-XML and would provide a method of generating these files without any dependency on Microsoft-office COM libraries -- the same could done for docx and pptx formats later, as well as other open-Xml formats like EPUB.

The Apache POI project looks like it might provide one possible solution. There's also an article on the MSDN interop blog that discusses this in some detail.

kdmurray
+1  A: 

The easiest and standard way of doing this is to use POI library:

http://poi.apache.org/spreadsheet/quick-guide.html

newguy
+1  A: 

If you want a real solution where you want different outputs (eg excel, pdf, rich text etc) then use a reporting tool. There are plenty of opensource tools like ireport which will let you create a template then write a simple java app that renders that to pdf, excel etc. Otherwise you will end up doing it by hand. It's a bit heavyweight but anything more than trival tabular output will be easier.

crafty
+1  A: 

Apache POI is for you in this case, but you will find it a little bit overwhelmed if you just need to write/read data from an excel file.

Try jExcel instead, the API is simple and straightforward, you can also manipulate sheets within an excel workbook.

Truong Ha