Reading an Excel file
In this recipe, you will learn how to read and extract data from an Excel file. If you are a Windows or Mac user, changes are that you have worked in some capacity with Microsoft Excel, the de facto standard for spreadsheets. Excel files are often the default data interchange format of the enterprise. Entire departments are run using incredibly complex Excel files with thousands of rows and absurdly convoluted formulas. As a programmer, it is often the case that you are asked to interact with such files.
Getting ready
Groovy (and Java) does not offer any out-of-the-box ingredient to manipulate Excel files. Fortunately, there is no shortage of third-party libraries that are able to deal with Microsoft documents. The undisputed king of this realm is Apache POI, the Java API for Microsoft documents. With Apache POI, it is possible to parse as well as write Excel 2007 OOXML documents (.xlsx
) and older formats (.xls
).
How to do it...
Let's start with a simple Excel file with...