mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-05-21 22:01:48 -06:00
54 lines
1.5 KiB
Text
54 lines
1.5 KiB
Text
/**
|
|
@page tutorial02 Tutorial 2: Adding formatting to the XLSX File
|
|
|
|
|
|
In the previous section we created a simple spreadsheet using C and
|
|
the @c libxlsxwriter library.
|
|
|
|
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:
|
|
|
|
@image html tutorial02.png
|
|
|
|
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:
|
|
|
|
@dontinclude tutorial2.c
|
|
@skip include
|
|
@until };
|
|
@until };
|
|
@until }
|
|
@until }
|
|
|
|
The main difference between this and the previous program is that we have
|
|
added two @ref format.h "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 @ref format.h "The Format object" and @ref
|
|
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:
|
|
|
|
@dontinclude tutorial2.c
|
|
@skipline bold
|
|
@until num_format
|
|
|
|
We can then pass these formats as a parameter to the `worksheet_write*()`
|
|
functions to format the data in the cell:
|
|
|
|
@dontinclude tutorial2.c
|
|
@skipline Total
|
|
@skipline SUM
|
|
|
|
In the next section we will look at handling more data types.
|
|
|
|
Next: @ref tutorial03.
|
|
|
|
*/
|