Howdy fellas...!
First of all, please move the thread if this doesn't seem to be the appropriate place for this question, I am posting only because there is Java code involved here.
My Requirement is that I need to programmatically print out a .csv file that has 2 rows as headers. The second row is actually Sub-headers row which has 4-5 sub-headers under each header from first row.
I need to have the headers from Row 1 combined for its sub-headers (like we can in Excel files). I hope the goal is clear.
My questions 1. Is it possible in a .csv file format to combine columns? (I've tried that in advanced text editors like Textpad, Notepad++ and it doesn't seem to work)
2. Is there a Java utility/class/package readily available to implement that?
Thanks,
Ashutosh.
SCJP 6, next stop - OCPJWCD!
Fyodor Sherstobitov
Greenhorn
Joined: Feb 21, 2011
Posts: 9
posted
0
Hi!
Excel works with .csv files pretty well, so you can merge two .csv files by copying and paseting them from one file opened in Excel to another.
Thanks for the reply.
But no, that's not what I am looking for.
For one thing, I need to write a program that will merge them through the PrintWriter that writes the whole file.
And second, the comma separated files (.csv) seem to lose all the column-combining kind of formatting while saving. Otherwise it needs be saved as some other Excel-featured type.
EDIT:
Oops, so rude on my part... Welcome to Ranch, Fyodor!
It would be better if you can explain the requirement a bit more. May be graphically if possible.
What I can understand from your requirement is that , you need to produce something like (I have excluded the comma separator).
For acheiving something like this , I don't think there will be any ready made code/library available.
But you can try writing something in this direction.
For each "sub-header" of a "header" , you will have to repeate the "header" column in the first row as shown above.
You got the requirement right, but you too know how bad it will look.
The requirement is of a Report in CSV which contains 4 pieces of info about 3 departments:
Gross Amount
Refunds
Agent Charges
Net Amount I don't think repetition is an option here.
I know that would look bad. But CSV is a plain stuff ; very limited formatting options.
You can try to code for the below formats (Only if its ok for your customer :-))
Copy the below formats to a text file , save as CSV file and open using excel and see if this would work for you
OR
Else as mentioned in the one of the messages below , try using POI if possible. You won't get a CSV but a spreadsheet with proper formatting can be created.
Curious to know why you need only CSV ...?