views:

56

answers:

4

Hello everyone!

For this project I'm working on, I want to take multiple excel sheets and then merge them into one, manipulating the data as I please to make everything a little more readable.

What would be the best way to open files, read their contents, store that content, create a new file (.csv), then paste the information in the organization of my choosing?

I definitely need to stick to java, as this will be part of a pre-existing automated process and I don't want to have to change everything to another language.

Is there a useful package out there that I should know about?

Many thanks

Justian

+1  A: 

As far as I know, csv is not excel-specific, but rather just a "comma-separated values"-file.

So this might help you.

phimuemue
Yup. That's true. CSV isn't specific to excel, but I figured most people would understand what it was better if I related it to a common program.This looks great, albeit a little confusing. I'm looking into it.
Justian Meyer
A: 

Writing CSV files is usually very simple, for obvious reasons. You can write your own helper class to do it. The caveat is to ensure that you do not have your delimeter in any of the outputs.

Reading CSV is trickier. There isn't a standard library like there is in Python (a much better language, IMHO, for doing CSV processing), but if you search for it there are a lot of decent free implementations around.

The biggest question is the internal representation in your program: Depending on the size of your inputs and outputs, keeping everything in memory may be out of the question. Can you do everything in one pass? (I mean, read some, write some, etc.)

You may also want to use sparse representations rather than just represent all the spreadsheets in an array.

Uri
Read some, write some is absolutely what I'd hope to do. It's just that, from what I hear, there isn't much flexibility editing an existing file, just creating one with the content of your choosing.
Justian Meyer
What do you mean by "editing" an existing file? Even excel simply replaces the version when you create a new one. With the appropriate APIs or design, you could write something that "copies" a file and introduces changes when relevant, like an event-based parser.
Uri
Let's say I don't want to hold all the data in my program. I'd create the file with starting lines/values, then reopen it when I wanted to add on to it. Of course, I'd have to evaluate efficiency. Storing more data vs. opening/writing.
Justian Meyer
+2  A: 

I think any serious work in Excel should consider Joel's solution of letting Office do it for you on a Windows machine you call remotely if necessary. If, however, your needs are simple enough or you really need a pure Java solution, Apache's POI library does a good enough job.

Yishai
A: 

Maybe you should try this one: Jxcell,it is a java spreadsheet component,and can read/write/edit all xls/xlsx/csv files.

liya
Thanks, but that's not quite what I'm looking for. That's a spreadsheet program that was made with Java. I need something that I can USE with Java.
Justian Meyer