mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-05-15 14:15:54 -06:00
worksheet: add embedded image options
This commit is contained in:
parent
34b2d2045f
commit
1dc5977e5f
23 changed files with 493 additions and 65 deletions
22
test/functional/src/test_embed_image08.c
Normal file
22
test/functional/src/test_embed_image08.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_embed_image08.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
lxw_image_options image_options = {.description = "Some alt text"};
|
||||
|
||||
worksheet_embed_image_opt(worksheet, 0, 0, "images/red.png", &image_options);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
22
test/functional/src/test_embed_image09.c
Normal file
22
test/functional/src/test_embed_image09.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_embed_image09.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
lxw_image_options image_options = {.description = "Some alt text", .decorative = LXW_TRUE};
|
||||
|
||||
worksheet_embed_image_opt(worksheet, 0, 0, "images/red.png", &image_options);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
22
test/functional/src/test_embed_image10.c
Normal file
22
test/functional/src/test_embed_image10.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_embed_image10.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
lxw_image_options image_options = {.url = "http://www.cpan.org/"};
|
||||
|
||||
worksheet_embed_image_opt(worksheet, 0, 0, "images/red.png", &image_options);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
25
test/functional/src/test_embed_image12.c
Normal file
25
test/functional/src/test_embed_image12.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_embed_image12.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
lxw_format *format1 = workbook_add_format(workbook);
|
||||
format_set_bg_color( format1, 0xFFFF00);
|
||||
|
||||
lxw_image_options image_options = {.cell_format = format1};
|
||||
|
||||
worksheet_embed_image_opt(worksheet, 0, 0, "images/red.png", &image_options);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
44
test/functional/src/test_embed_image51.c
Normal file
44
test/functional/src/test_embed_image51.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
|
||||
unsigned char image_buffer[] = {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
|
||||
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
|
||||
0x08, 0x02, 0x00, 0x00, 0x00, 0xfc, 0x18, 0xed, 0xa3, 0x00, 0x00, 0x00,
|
||||
0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
|
||||
0x00, 0x04, 0x67, 0x41, 0x4d, 0x41, 0x00, 0x00, 0xb1, 0x8f, 0x0b, 0xfc,
|
||||
0x61, 0x05, 0x00, 0x00, 0x00, 0x20, 0x63, 0x48, 0x52, 0x4d, 0x00, 0x00,
|
||||
0x7a, 0x26, 0x00, 0x00, 0x80, 0x84, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00,
|
||||
0x80, 0xe8, 0x00, 0x00, 0x75, 0x30, 0x00, 0x00, 0xea, 0x60, 0x00, 0x00,
|
||||
0x3a, 0x98, 0x00, 0x00, 0x17, 0x70, 0x9c, 0xba, 0x51, 0x3c, 0x00, 0x00,
|
||||
0x00, 0x46, 0x49, 0x44, 0x41, 0x54, 0x48, 0x4b, 0x63, 0xfc, 0xcf, 0x40,
|
||||
0x63, 0x00, 0xb4, 0x80, 0xa6, 0x88, 0xb6, 0xa6, 0x83, 0x82, 0x87, 0xa6,
|
||||
0xce, 0x1f, 0xb5, 0x80, 0x98, 0xe0, 0x1d, 0x8d, 0x03, 0x82, 0xa1, 0x34,
|
||||
0x1a, 0x44, 0xa3, 0x41, 0x44, 0x30, 0x04, 0x08, 0x2a, 0x18, 0x4d, 0x45,
|
||||
0xa3, 0x41, 0x44, 0x30, 0x04, 0x08, 0x2a, 0x18, 0x4d, 0x45, 0xa3, 0x41,
|
||||
0x44, 0x30, 0x04, 0x08, 0x2a, 0x18, 0x4d, 0x45, 0x03, 0x1f, 0x44, 0x00,
|
||||
0xaa, 0x35, 0xdd, 0x4e, 0xe6, 0xd5, 0xa1, 0x22, 0x00, 0x00, 0x00, 0x00,
|
||||
0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
|
||||
};
|
||||
|
||||
unsigned int image_size = 200;
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_embed_image51.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
worksheet_embed_image_buffer(worksheet, 0, 0, image_buffer, image_size);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
46
test/functional/src/test_embed_image52.c
Normal file
46
test/functional/src/test_embed_image52.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
|
||||
unsigned char image_buffer[] = {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
|
||||
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
|
||||
0x08, 0x02, 0x00, 0x00, 0x00, 0xfc, 0x18, 0xed, 0xa3, 0x00, 0x00, 0x00,
|
||||
0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
|
||||
0x00, 0x04, 0x67, 0x41, 0x4d, 0x41, 0x00, 0x00, 0xb1, 0x8f, 0x0b, 0xfc,
|
||||
0x61, 0x05, 0x00, 0x00, 0x00, 0x20, 0x63, 0x48, 0x52, 0x4d, 0x00, 0x00,
|
||||
0x7a, 0x26, 0x00, 0x00, 0x80, 0x84, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00,
|
||||
0x80, 0xe8, 0x00, 0x00, 0x75, 0x30, 0x00, 0x00, 0xea, 0x60, 0x00, 0x00,
|
||||
0x3a, 0x98, 0x00, 0x00, 0x17, 0x70, 0x9c, 0xba, 0x51, 0x3c, 0x00, 0x00,
|
||||
0x00, 0x46, 0x49, 0x44, 0x41, 0x54, 0x48, 0x4b, 0x63, 0xfc, 0xcf, 0x40,
|
||||
0x63, 0x00, 0xb4, 0x80, 0xa6, 0x88, 0xb6, 0xa6, 0x83, 0x82, 0x87, 0xa6,
|
||||
0xce, 0x1f, 0xb5, 0x80, 0x98, 0xe0, 0x1d, 0x8d, 0x03, 0x82, 0xa1, 0x34,
|
||||
0x1a, 0x44, 0xa3, 0x41, 0x44, 0x30, 0x04, 0x08, 0x2a, 0x18, 0x4d, 0x45,
|
||||
0xa3, 0x41, 0x44, 0x30, 0x04, 0x08, 0x2a, 0x18, 0x4d, 0x45, 0xa3, 0x41,
|
||||
0x44, 0x30, 0x04, 0x08, 0x2a, 0x18, 0x4d, 0x45, 0x03, 0x1f, 0x44, 0x00,
|
||||
0xaa, 0x35, 0xdd, 0x4e, 0xe6, 0xd5, 0xa1, 0x22, 0x00, 0x00, 0x00, 0x00,
|
||||
0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
|
||||
};
|
||||
|
||||
unsigned int image_size = 200;
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_embed_image52.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
lxw_image_options image_options = {.description = "Some alt text"};
|
||||
|
||||
worksheet_embed_image_buffer_opt(worksheet, 0, 0, image_buffer, image_size, &image_options);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Simple test case for TODO.
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Simple test case for TODO.
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Simple test case for TODO.
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Simple test case for TODO.
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org.
|
||||
|
|
|
|||
|
|
@ -39,9 +39,30 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
|
|||
def test_embed_image07(self):
|
||||
self.run_exe_test('test_embed_image07')
|
||||
|
||||
def test_embed_image11(self):
|
||||
def test_embed_image08(self):
|
||||
self.run_exe_test('test_embed_image08')
|
||||
|
||||
def test_embed_image09(self):
|
||||
self.run_exe_test('test_embed_image09')
|
||||
|
||||
def test_embed_image10(self):
|
||||
# Ignore the missing "display" parameter.
|
||||
self.ignore_elements = {'xl/worksheets/sheet1.xml': ['<hyperlink']}
|
||||
self.run_exe_test('test_embed_image10')
|
||||
|
||||
def test_embed_image13(self):
|
||||
self.run_exe_test('test_embed_image11')
|
||||
def test_embed_image12(self):
|
||||
self.run_exe_test('test_embed_image12')
|
||||
|
||||
@pytest.mark.skipif(os.environ.get('USE_NO_MD5'), reason="compiled without MD5 support")
|
||||
def test_embed_image13(self):
|
||||
self.run_exe_test('test_embed_image13')
|
||||
|
||||
# Test in-memory image handling.
|
||||
def test_embed_image51(self):
|
||||
self.run_exe_test('test_embed_image51', 'embed_image01.xlsx')
|
||||
|
||||
def test_embed_image52(self):
|
||||
self.run_exe_test('test_embed_image52', 'embed_image08.xlsx')
|
||||
|
||||
|
|
|
|||
BIN
test/functional/xlsx_files/embed_image08.xlsx
Normal file
BIN
test/functional/xlsx_files/embed_image08.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/embed_image09.xlsx
Normal file
BIN
test/functional/xlsx_files/embed_image09.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/embed_image10.xlsx
Normal file
BIN
test/functional/xlsx_files/embed_image10.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/embed_image12.xlsx
Normal file
BIN
test/functional/xlsx_files/embed_image12.xlsx
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue