user1957902
user1957902

Reputation: 37

Read text files and write it to excel in java

I have to read a text file and write it to an already existing excel file. The excel file is a customized excel sheet with different items in different columns. The items has different values for each of them... These items with there value can be found in a text file. But i dont have much idea as to how to do this.

E.g- example.txt

Name: John

Age=24

Sex=M

Graduate=M.S

example.xlsx

Age: Sex:

Name: Graduate:

Thanks in advance :)

Upvotes: 1

Views: 5626

Answers (3)

Losiowaty
Losiowaty

Reputation: 8006

You can also create a *.csv (comma separated value) file in Java. Just create a simple text file with CSV extension and put your values in there like that :

Age:,24,Sex:,M,

So you just separate your values with commas (or other delimiters like ';'). Every line in this file is a row, and every delimiter separates two columns. You won't be able to add colours/styles/formatting this way, but it gives you a file that is openable and understandable even without Excel (or other spreadsheet software).

Upvotes: 0

Shreyos Adikari
Shreyos Adikari

Reputation: 12744

Please see Apache POI-HSSF library for reading and writing Excel files with Java. There are some quick guides to get you started.

This post How to read and write excel file in java might help you.

Upvotes: 0

chooban
chooban

Reputation: 9256

Just as for so many other problems that need solved, there's an Apache library for that! In this case, it's the POI library. I've only used it for very basic spreadsheet manipulation, but managed that by just following a few tutorials. I'd link to one, but I can't now remember where it was.

Upvotes: 4

Related Questions