libxlsxwriter
Loading...
Searching...
No Matches
watermark.c
<< outline_collapsed.c background.c >>

Example of how to a watermark image for a worksheet using the method suggested in the Microsoft documentation: https://support.microsoft.com/en-us/office/add-a-watermark-in-excel-a372182a-d733-484e-825c-18ddf3edf009

/*
* An example of adding a worksheet watermark image using libxlsxwriter. This
* is based on the method of putting an image in the worksheet header as
* suggested in the Microsoft documentation:
* https://support.microsoft.com/en-us/office/add-a-watermark-in-excel-a372182a-d733-484e-825c-18ddf3edf009
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("watermark.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
/* Set a worksheet header with the watermark image. */
lxw_header_footer_options header_options = {.image_center = "watermark.png"};
worksheet_set_header_opt(worksheet, "&C&[Picture]", &header_options);
workbook_close(workbook);
return 0;
}
Struct to represent an Excel workbook.
Definition: workbook.h:293
Struct to represent an Excel worksheet.
Definition: worksheet.h:2115
lxw_workbook * workbook_new(const char *filename)
Create a new workbook object.
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)
Add a new worksheet to a workbook.
lxw_error worksheet_set_header_opt(lxw_worksheet *worksheet, const char *string, lxw_header_footer_options *options)
Set the printed page header caption with additional options.