Excel Writer
Working with Excel ..

Last updated
Was this helpful?
Working with Excel ..
Excel reports often need templates, charts, and fixed layouts.
Here you populate a pre-formatted Sales and Expenses report. You will write multiple sections into one workbook. You will control execution order so writers do not conflict.
What you'll do
Use a template workbook and write to fixed cell positions
Write a report header with Generate rows
Read sales and expense rows from text files
Block parallel flows before writing to the same file
Write multiple sections with Microsoft Excel Writer
By the end, you will know how to write into an Excel template safely. You will also know when to block parallel flows.
Prerequisites: Understanding of basic transformation concepts (steps, hops, preview). Complete Text File Input first.
Estimated time: 35 minutes
Workshop files
Download the following files.
Keep the filenames unchanged.
Save them in your workshop folder.

Create a new transformation
Use any of these options to open a new transformation tab:
Select File > New > Transformation
Use Ctrl+N (Windows/Linux) or Cmd+N (macOS)
The various stages of the transformation write data to a template.xlsx. The template has 2 worksheets:
Sales Chart - this worksheet creates a 3D stacked graph
SourceData - worksheet
Open template.xlsx in Excel:

SourceData - the datasheet. Transformations write to the required cells that are used to create the graph.

The first workflow is to write the current Year to the SourceData worksheet in the template.xlsx
You can change the year value.

Generate rows outputs a fixed number of rows. Here you output a single row that contains the report year.
Start Pentaho Data Integration (Spoon).
Drag the ‘Generate Rows’ step onto the canvas.
Double-click on the step, and configure the following properties:

Close Step.
Summary
Generates a record that holds the Year value – 2023 – in the year stream field.
The Excel template will also need to be formatted yyyy to interpret the Date.
Microsoft Excel Writer writes incoming rows into an Excel workbook. Use xlsx when you work with templates and charts.
Drag the ‘Excel writer’ step onto the canvas.
Create a hop from the ‘Year’ step.
Double-click on the step, and configure the following properties:

Use these paths:
Output: ${Internal.Transformation.Filename.Directory}/Sales_and_Expenses_2023.xlsx
Template: ${Internal.Transformation.Filename.Directory}/template.xlsx
Select Replace with new output file while you develop. It resets the workbook on every run.
4. Click on the Content tab, and configure the following properties:

Click on ‘Get Fields’ button.
Click OK.
Write sales rows into the same workbook. Use a blocking step so the year write completes first.

Read the sales dataset from the workshop file. Keep the header row enabled so field names match the template.
Drag the ‘Text file input’ step onto the canvas.
Double-click on the step, and configure the following properties:

Click on the Content tab, and configure the following properties:

Ensure the Header is selected.
No empty rows
Mixed Format
Click on the Fields tab, and click on ‘Get Fields’ button:
Returns the Header values as stream fields.
Click OK.
This step waits for specific steps to finish. Use it to prevent parallel writers.
Drag the ‘Block this step until steps finish’ step onto the canvas.
Create a hop from the ‘Read Sales’ step.
Double-click on the step, and configure the following properties:
Watch step: the step that writes the year (copy 0)
If you used Get steps, remove everything except the year writer step

This will result in the workflow being blocked until the Write Year step has been completed.
Write sales rows into the existing workbook. Use Use existing file for writing.
Drag the ‘Excel writer’ step onto the canvas.
Create a hop from the ‘Wait Year’ step.
Double-click on the step, and configure the following properties:

Use the same output path you used in the year writer:
Output: ${Internal.Transformation.Filename.Directory}/Sales_and_Expenses_2023.xlsx
Select Use existing file for writing.
Click on the Content tab, and configure the following properties:

Click on the ‘Get Fields’ button.
Delete the productline field, as its not required. The template already has the fieldname and you are just writing the data, starting at cell B5.
Click OK.

Last updated
Was this helpful?
Was this helpful?
Set-Location C:\Pentaho\design-tools\data-integration
.\spoon.batcd ~/Pentaho/design-tools/data-integration
./spoon.sh