In the previous section we created a simple spreadsheet using C and the
This converted the required data into an Excel file but it looked a little bare. In order to make the information clearer we would like to add some simple formatting, like this:
The differences here are that we have added Item and Cost column headers in a bold font, we have formatted the currency in the second column and we have made the Total string bold.
To do this we can extend our program as follows:
The main difference between this and the previous program is that we have added two Format objects that we can use to format cells in the spreadsheet.
Format objects represent all of the formatting properties that can be applied to a cell in Excel such as fonts, number formatting, colors and borders. This is explained in more detail in The Format object and Working with Formats.
For now we will avoid getting into the details and just use a limited amount of the format functionality to add some simple formatting:
We can then pass these formats as a parameter to the
worksheet_write*() functions to format the data in the cell:
In the next section we will look at handling more data types.