Writing an Excel file with Kettle has a lot in common with writing a text file. Except for a couple of settings specific for Excel files, configuring an Excel Output step is quite similar to configuring a Text file output step. One of the differences is that when you write an Excel file, you add a sheet to the file. What if you want to write more than one sheet in the same file?
Suppose you have a datasource containing books and their authors and you want to create an Excel file with two sheets. In the first sheet, you want the authors and in the second, the books' titles. This recipe teaches you how to do this.
In order to run this recipe, you will need a database with books and authors with the structure described in Appendix, Data Structures.
Carry out the following steps, in order to create the sheet with the authors' details:
SELECT * FROM Authors order by lastname
xls
. Authors
.If you find that the default types or formats of the fields are not correct, you can fix them manually.
Carry out the following steps, in order to create the sheet with the book's details:
SELECT * FROM Books order by title
xls)
. Titles
.The intuitive way to generate an Excel file with two sheets would be to create a single transformation with two Excel Output steps, one for each sheet. However, that approach does not work because Kettle cannot manage concurrent access to the same Excel file in a single transformation.
One way to avoid this issue is to create different transformations, one for each sheet, and then calling these transformations from a job. With this approach, the transformations are executed sequentially, which means that the sheets are generated one at a time, avoiding the concurrency problem.
Another way to assure the sequential generation of the sheets would be using the Block this step until steps finish step from the Flow category. Using this step, the writing of the second sheet will wait for the first sheet to complete its writing process. For our recipe, the transformation should look like the following:
3.144.114.85