diff --git a/.gitignore b/.gitignore index fe762b50..da98d356 100644 --- a/.gitignore +++ b/.gitignore @@ -38,8 +38,7 @@ docs/latex _temp.c examples/* !examples/*.c -!examples/logo.png -!examples/logo_small.png +!examples/*.png !examples/Makefile !examples/vbaProject.bin cov-int diff --git a/dev/release/fix_example_docs.pl b/dev/release/fix_example_docs.pl index 24db66a0..f4c992bd 100644 --- a/dev/release/fix_example_docs.pl +++ b/dev/release/fix_example_docs.pl @@ -42,6 +42,7 @@ my @examples = ( [ 'defined_name.c', 'Example of how to create defined names' ], [ 'outline.c', 'Example of grouping and outlines' ], [ 'outline_collapsed.c', 'Example of grouping and collapsed outlines' ], + [ 'watermark.c', 'Example of how to set a watermark image for a worksheet' ], [ 'background.c', 'Example of how to set the background image for a worksheet' ], [ 'tab_colors.c', 'Example of how to set worksheet tab colors' ], [ 'diagonal_border.c', 'Example of how to set a worksheet cell diagonal border.' ], diff --git a/docs/images/worksheet_watermark.png b/docs/images/worksheet_watermark.png new file mode 100644 index 00000000..de6a119c Binary files /dev/null and b/docs/images/worksheet_watermark.png differ diff --git a/docs/src/examples.dox b/docs/src/examples.dox index 128c8f84..414bac57 100644 --- a/docs/src/examples.dox +++ b/docs/src/examples.dox @@ -509,7 +509,7 @@ Example of how to generate Excel outlines and grouping. - +
@ref outline.c "<< outline.c"@ref background.c "background.c >>"@ref watermark.c "watermark.c >>"
@@ -521,11 +521,29 @@ mainly on collapsed outlines. -@example background.c +@example watermark.c + + +
@ref outline_collapsed.c "<< outline_collapsed.c"@ref background.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 + +@image html worksheet_watermark.png + + + + +@example background.c + + + +
@ref watermark.c "<< watermark.c" @ref tab_colors.c "tab_colors.c >>"
diff --git a/docs/src/examples.txt b/docs/src/examples.txt index 794ed995..8988f975 100644 --- a/docs/src/examples.txt +++ b/docs/src/examples.txt @@ -239,6 +239,15 @@ mainly on collapsed outlines. @image html outline2.png +############################################################## +@example watermark.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 + +@image html worksheet_watermark.png + ############################################################## @example background.c diff --git a/examples/watermark.c b/examples/watermark.c new file mode 100644 index 00000000..980307c6 --- /dev/null +++ b/examples/watermark.c @@ -0,0 +1,26 @@ +/* + * 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-2021, 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; +} diff --git a/examples/watermark.png b/examples/watermark.png new file mode 100644 index 00000000..25495c01 Binary files /dev/null and b/examples/watermark.png differ diff --git a/test/functional/src/images/watermark.png b/test/functional/src/images/watermark.png new file mode 100644 index 00000000..25495c01 Binary files /dev/null and b/test/functional/src/images/watermark.png differ diff --git a/test/functional/src/test_header_image20.c b/test/functional/src/test_header_image20.c new file mode 100644 index 00000000..34e77d8a --- /dev/null +++ b/test/functional/src/test_header_image20.c @@ -0,0 +1,22 @@ +/***************************************************************************** + * Test cases for libxlsxwriter. + * + * Test to compare output against Excel files. + * + * Copyright 2014-2022, John McNamara, jmcnamara@cpan.org + * + */ + +#include "xlsxwriter.h" + +int main() { + + lxw_workbook *workbook = workbook_new("test_header_image20.xlsx"); + lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); + + lxw_header_footer_options header_options = {.image_center = "images/watermark.png"}; + + worksheet_set_header_opt(worksheet, "&C&G", &header_options); + + return workbook_close(workbook); +} diff --git a/test/functional/test_header_image.py b/test/functional/test_header_image.py index b98c443f..1cd4dc12 100644 --- a/test/functional/test_header_image.py +++ b/test/functional/test_header_image.py @@ -100,6 +100,10 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest): self.ignore_elements = {'xl/worksheets/sheet1.xml': ['