How do I take data from a spreadsheet (LibreOffice Impress, to be precise), and use it as input to a program in Java?
December 5, 2011 11:01 PM   Subscribe

How do I take data from a spreadsheet (LibreOffice Impress, to be precise), and use it as input to a program in Java? This is fairly basic stuff, so I'm a little embarrassed to be having issues with this, but I don't have much time. I'm well aware of how to do file I/O with a text file using a Scanner object for input, but how does this work with a spreadsheet?
posted by bookman117 to Computers & Internet (5 answers total) 1 user marked this as a favorite
*LibreOffice Calc
posted by bookman117 at 11:02 PM on December 5, 2011

Export as .csv. Reading from that with Java should be simple.
posted by WasabiFlux at 11:14 PM on December 5, 2011 [1 favorite]

For a quick and dirty solution, export your data to CSV and read the CSV file.

You can also parse the Calc file directly, since it is just a compressed XML file. In theory, you could read up on the XML schema and roll your own parser, but this is not a good idea - it probably is not a trivial task, and you don't want to have to deal with all the corner cases and maintain it if the format changes in the future.

Your best bet is to find an existing library that will parse the Calc file for you - LibreOffice being open-source means such a thing would be much easier to write than the equivalent Excel file manipulation libraries. A quick internet search turns this up - I don't know how usable this is, but that's what you are looking for.
posted by Dr Dracator at 11:15 PM on December 5, 2011

LibreOffice Impress is not a spreadsheet, it's a presentation program - I suppose you mean Calc?

It depends on what you want. If you just need to read/write raw data, then CSV is indeed the way to go. If you care about formatting, graphics etc, you'll probably need to use ODFDOM.
posted by themel at 2:57 AM on December 6, 2011

If you're going to export I'd recommend tab-separated rather than comma-separated.

Several years ago I had success unpacking a .ods file and parsing the XML in-memory. It actually wasn't bad, although it was pretty verbose and had a lot of nesting. If you use an event-based parser (push or pull, either way) you can skip past the intermediate layers without much difficulty.

That said, ODFDOM is probably the least trouble to work with as you won't have to care about such details.
posted by vsync at 1:32 PM on December 6, 2011

« Older Where does the name PolyDac come from?   |   Because lemons are for drinks, not for data. Newer »
This thread is closed to new comments.