2014-06-08 17:40:59 +01:00
|
|
|
/*
|
|
|
|
* A simple example of some of the features of the libxlsxwriter library.
|
|
|
|
*
|
2025-02-11 00:03:36 +00:00
|
|
|
* Copyright 2014-2025, John McNamara, jmcnamara@cpan.org
|
2014-06-08 17:40:59 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xlsxwriter.h"
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
2014-06-09 23:54:03 +01:00
|
|
|
/* Create a new workbook and add a worksheet. */
|
2016-01-04 19:48:16 +00:00
|
|
|
lxw_workbook *workbook = workbook_new("demo.xlsx");
|
2014-06-08 17:40:59 +01:00
|
|
|
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
|
|
|
|
|
|
|
/* Add a format. */
|
2015-03-07 17:23:04 +00:00
|
|
|
lxw_format *format = workbook_add_format(workbook);
|
2014-06-08 17:40:59 +01:00
|
|
|
|
|
|
|
/* Set the bold property for the format */
|
|
|
|
format_set_bold(format);
|
|
|
|
|
2016-01-05 00:38:05 +00:00
|
|
|
/* Change the column width for clarity. */
|
2016-01-04 00:01:00 +00:00
|
|
|
worksheet_set_column(worksheet, 0, 0, 20, NULL);
|
2014-06-20 01:00:21 +01:00
|
|
|
|
2014-06-08 17:40:59 +01:00
|
|
|
/* Write some simple text. */
|
|
|
|
worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
|
|
|
|
|
|
|
|
/* Text with formatting. */
|
|
|
|
worksheet_write_string(worksheet, 1, 0, "World", format);
|
|
|
|
|
2016-08-16 20:14:12 +01:00
|
|
|
/* Write some numbers. */
|
2014-06-09 23:54:03 +01:00
|
|
|
worksheet_write_number(worksheet, 2, 0, 123, NULL);
|
|
|
|
worksheet_write_number(worksheet, 3, 0, 123.456, NULL);
|
2014-06-08 17:40:59 +01:00
|
|
|
|
2015-12-27 00:04:51 +00:00
|
|
|
/* Insert an image. */
|
2016-01-03 19:11:22 +00:00
|
|
|
worksheet_insert_image(worksheet, 1, 2, "logo.png");
|
2015-12-27 00:04:51 +00:00
|
|
|
|
2014-06-08 17:40:59 +01:00
|
|
|
workbook_close(workbook);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|