0

I want to store the values from the database to an existing excel file. For example if the file is stored in C: data.xls. I want the data from db table to be stored in that. I will mention the column name in the excel file itself.

Please help me to do this.

3
  • Would you consider a CSV file, or is your heart set on an Excel file? Commented Nov 17, 2011 at 4:55
  • "Please help me in doing this." Which part are you having trouble with? What have you tried? It almost seems like you are asking if someone will "gimme' da' codez?". Commented Nov 17, 2011 at 5:01
  • i could able to get the values from database and create a xl file and store it in that . am trying to store it in an existing excel file . Commented Nov 17, 2011 at 5:26

3 Answers 3

2

Use JDBC API to read/fetch result from the MySql database and jExcelAPI or Apache POI (recommended) to write/update excel document.

Sign up to request clarification or add additional context in comments.

1 Comment

I would second the recommendation for Apache POI its an excellent piece of code, in many ways superior to Microsofts own .COM API.
2

Writing to a CSV file is probably the easiest way to do this. CSV files can be opened up in Excel, but cannot have any text formatting. See the CSV Wikipedia article for more details on the format.

If you would rather use an XLS or XLSX format, consider using Apache POI, as the formats of those file types (particularly XLS) is quite complicated to write to manually.

Comments

1

If you are going for a CSV file, you need only open the file, and begin putting rows, one per line, with commas in between values. It's very simple, and works with a variety of software.

3 Comments

"commas in between values" What if the values contain commas? ;)
Ok, it's slightly more complicated than that, but still ridiculously simple. It's the kind of code you write once in a given language, and never have to modify again. ^_^
OK I'll concede that. :) +1 for the concept of CSV and the last sentence in your comment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.