Spreadsheet Parser in Java/Groovy

2019-05-08 19:10发布

Hi I'm looking to parse spreadsheets (xls/ods) in Groovy. I have been using the Roo library for Ruby and was looking to try the same tasks in Groovy, as Java is already installed on a development server I use, and I would like to keep the number of technologies on the server to a simple core few.

I am aware that the ods format is zipped XML, and so can be parsed as such, but I would like to process the file using spreadsheet concepts, not XML concepts.

The ability to process xls files is not of major importance, but would save me having to save multiple xls files to ods (as this is for parsing data from clients).

Thanks

8条回答
够拽才男人
2楼-- · 2019-05-08 19:15

Groovy in Action has a chapter named "Groovy on Windows" that discusses using Scriptom, a Groovy/COM bridge (using JACOB under the covers), to access several Windows apps including Excel.

For OpenOffice, you can use ODF Toolkit, as Amit pointed out.

查看更多
\"骚年 ilove
3楼-- · 2019-05-08 19:17

A couple things:

1) I agree that using a CSV format can simplify some of the development work. OpenCSV can help with processing CSV files. There are other good CSV parsers for Java out there. Just remember that anything that's available for Java can be used by Groovy due to Groovy's unparalleled integration with Java.

2) I know you said you wanted to avoid handling XML, but Groovy makes XML processing exceedingly simple.

查看更多
何必那么认真
4楼-- · 2019-05-08 19:20

There's also JExcelAPI, which has a nice, clean, simple interface (for the most part).

Can't help you with ODS Files though.

查看更多
Evening l夕情丶
5楼-- · 2019-05-08 19:24

I suggest you to take a look at SimpleXlsBuilder and SimpleXlsSlurper, both are based on apache POI and can fit your basic needs for reading from and writing to Excel 97 spreadsheets in a concise way.

查看更多
Rolldiameter
6楼-- · 2019-05-08 19:25

If your spreadsheets are simple enught - without charts and other embedded contents - you should simply convert the spreadsheet to CSV.

Pros:

  • Both xls and ods will produce the same CSV - You'll have to handle just one input type.
  • You won't have to mess with new versions of (Open) Office.
  • Handling plaintext is always more fun than other obscure formats.

Cons:

  • One that I can think of - finding a reliable converter from xls and odf to csv. Shouldn't be too hard - OpenOffice has a built in one.
查看更多
时光不老,我们不散
7楼-- · 2019-05-08 19:27

How about looking at 'odftoolkit' ? http://odftoolkit.openoffice.org/

查看更多
登录 后发表回答