[GH-ISSUE #417] How do I insert a picture as embedded in a cell ? #328

Closed
opened 2026-05-05 12:09:29 -06:00 by gitea-mirror · 23 comments
Owner

Originally created by @zhjiarong on GitHub (Nov 7, 2023).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/417

I want to insert a picture as embedded in a cell. How do I do that with libxlsxwriter? thank you
Snipaste_2023-11-07_15-36-02

Originally created by @zhjiarong on GitHub (Nov 7, 2023). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/417 I want to insert a picture as embedded in a cell. How do I do that with libxlsxwriter? thank you ![Snipaste_2023-11-07_15-36-02](https://github.com/jmcnamara/libxlsxwriter/assets/44044519/1e81d6b4-d530-45d4-a8a2-269d07e7b5b5)
Author
Owner

@jmcnamara commented on GitHub (Nov 7, 2023):

When you perform this action in Excel it scales the image to fit the cell.

It is also possible with libxslxwriter to scale images (using worksheet_insert_image_opt(). However, there aren't any helper functions to scale it to a cell/pixel size. I had planned to do this at some stage but I didn't get around to it.

You can do it yourself by using some library to get the X and Y pixel size of the the image and also the X and Y DPI. There are internal functions to do this in libxslxwriter but they aren't public.

After that you need to scale the image (using the dimensions and DPI) to the pixel size of the cell. There is some code for that in the Rust version of the library that I wrote. See here.

<!-- gh-comment-id:1798111061 --> @jmcnamara commented on GitHub (Nov 7, 2023): When you perform this action in Excel it scales the image to fit the cell. It is also possible with `libxslxwriter` to scale images (using [`worksheet_insert_image_opt()`](http://libxlsxwriter.github.io/worksheet_8h.html#a0b05e75e2c2a5c3452374714cdb2b79b). However, there aren't any helper functions to scale it to a cell/pixel size. I had planned to do this at some stage but I didn't get around to it. You can do it yourself by using some library to get the X and Y pixel size of the the image and also the X and Y DPI. There are [internal functions](https://github.com/jmcnamara/libxlsxwriter/blob/main/src/worksheet.c#L4218) to do this in `libxslxwriter` but they aren't public. After that you need to scale the image (using the dimensions and DPI) to the pixel size of the cell. There is some code for that in the Rust version of the library that I wrote. See [here](https://github.com/jmcnamara/rust_xlsxwriter/blob/main/src/image.rs#L442).
Author
Owner

@zhjiarong commented on GitHub (Nov 10, 2023):

ok, thank you, I hope to add this feature in the future.

<!-- gh-comment-id:1804927546 --> @zhjiarong commented on GitHub (Nov 10, 2023): ok, thank you, I hope to add this feature in the future.
Author
Owner

@sunilsabraham commented on GitHub (Nov 30, 2023):

@jmcnamara : The author is asking how to embed picture in cell. In latest excel there are 2 options to insert picture.

  1. place in cell
  2. place over cells
    The first option is to embed picture in cell which automatically scale the picture by excel. The second once is the current one implemented by libxlswriter. Is it possible to add the first option as well. Hope you can implement it asap. Thanks.
<!-- gh-comment-id:1834311934 --> @sunilsabraham commented on GitHub (Nov 30, 2023): @jmcnamara : The author is asking how to embed picture in cell. In latest excel there are 2 options to insert picture. 1) place in cell 2) place over cells The first option is to embed picture in cell which automatically scale the picture by excel. The second once is the current one implemented by libxlswriter. Is it possible to add the first option as well. Hope you can implement it asap. Thanks.
Author
Owner

@jmcnamara commented on GitHub (Dec 1, 2023):

@sunilsabraham Could you attach an Excel example with an image embedded in a cell and a similar example with an image just inserted, and not embedded, for reference.

<!-- gh-comment-id:1835914076 --> @jmcnamara commented on GitHub (Dec 1, 2023): @sunilsabraham Could you attach an Excel example with an image embedded in a cell and a similar example with an image just inserted, and not embedded, for reference.
Author
Owner

@sunilsabraham commented on GitHub (Dec 1, 2023):

@jmcnamara Please see the screen shot below. Just open excel and try to insert a picture and you will get 2 options. first one is to embed picture to a cell and excel will automatically scale the image. second one is to place image over a cell and that is the current implementation in libxlswriter. Old excel had only place over a cell may be upto 2016 version. If you can implement the embed in cell that would be great. so we dont need to scale the image and it automatically does according to row height etc. I am attaching an example file as well.

image

Book1.xlsx

<!-- gh-comment-id:1836008440 --> @sunilsabraham commented on GitHub (Dec 1, 2023): @jmcnamara Please see the screen shot below. Just open excel and try to insert a picture and you will get 2 options. first one is to embed picture to a cell and excel will automatically scale the image. second one is to place image over a cell and that is the current implementation in libxlswriter. Old excel had only place over a cell may be upto 2016 version. If you can implement the embed in cell that would be great. so we dont need to scale the image and it automatically does according to row height etc. I am attaching an example file as well. ![image](https://github.com/jmcnamara/libxlsxwriter/assets/152528892/fb2ed273-5963-4e87-bf75-cf167daec822) [Book1.xlsx](https://github.com/jmcnamara/libxlsxwriter/files/13526318/Book1.xlsx)
Author
Owner

@jmcnamara commented on GitHub (Dec 1, 2023):

@sunilsabraham Thanks for pointing that out. That is a useful feature. I'll try add it.

<!-- gh-comment-id:1836738824 --> @jmcnamara commented on GitHub (Dec 1, 2023): @sunilsabraham Thanks for pointing that out. That is a useful feature. I'll try add it.
Author
Owner

@sunilsabraham commented on GitHub (Dec 3, 2023):

Thanks.

<!-- gh-comment-id:1837366776 --> @sunilsabraham commented on GitHub (Dec 3, 2023): Thanks.
Author
Owner

@rickabitdigital commented on GitHub (Dec 12, 2023):

@jmcnamara I'd love the Place in cell feature too! Images placed in cells will scale according to column width/row height. As we can define the initial column width and row height, to accommodate our inserted images, cells shoudn't be hidden on file open. I think this produces a more natural and robust layout behaviour - e.g. when objects float over cells users can struggle with the overlap.

<!-- gh-comment-id:1851207487 --> @rickabitdigital commented on GitHub (Dec 12, 2023): @jmcnamara I'd love the _Place in cell_ feature too! Images placed in cells will scale according to column width/row height. As we can define the initial column width and row height, to accommodate our inserted images, cells shoudn't be hidden on file open. I think this produces a more natural and robust layout behaviour - e.g. when objects float over cells users can struggle with the overlap.
Author
Owner

@rickabitdigital commented on GitHub (Jan 24, 2024):

Hi @jmcnamara
Have you looked into implementing this feature yet?

I've been reading the openxml API reference docs (my first time), but the 'place in cell' xml format is not immediately obvious. So I have begun using an OOXML editor/viewer to see the difference between images placed in cells using typical drawing references vs an image embedded in a cell.
I'll let you know if I get anywhere.
If there's any way you can think of me helping advance this feature please could you advise?
thank you.

<!-- gh-comment-id:1908453911 --> @rickabitdigital commented on GitHub (Jan 24, 2024): Hi @jmcnamara Have you looked into implementing this feature yet? I've been reading the openxml API reference docs (my first time), but the 'place in cell' xml format is not immediately obvious. So I have begun using an OOXML editor/viewer to see the difference between images placed in cells using typical drawing references vs an image embedded in a cell. I'll let you know if I get anywhere. If there's any way you can think of me helping advance this feature please could you advise? thank you.
Author
Owner

@jmcnamara commented on GitHub (Jan 24, 2024):

Have you looked into implementing this feature yet?

Yes. I started working on it in December but then got sucked into some work on rust_xlsxwriter. I made some progress on the Metadata and RichValue files but there is still quite a bit to do. I'll start working on it again next week after the 0.62.0 release of rust_xlsxwriter but I can't give a timeline.

<!-- gh-comment-id:1908588666 --> @jmcnamara commented on GitHub (Jan 24, 2024): > Have you looked into implementing this feature yet? Yes. I started working on it in December but then got sucked into some work on `rust_xlsxwriter`. I made some progress on the Metadata and RichValue files but there is still quite a bit to do. I'll start working on it again next week after the 0.62.0 release of `rust_xlsxwriter` but I can't give a timeline.
Author
Owner

@rickabitdigital commented on GitHub (Jan 24, 2024):

Hi John,
That's great to hear and thank you very kindly for the update. Much appreciated.
I have just reached the point where the basic OOXML viewer I found wasn't showing me the RichValue relationship for an image placed in cell for me to compare with the XML of the existing drawing relationships for image objects.
I suppose I may need to give in and use the obvious OOXML explorer for VSCode.
I'll keep going with my learning and appreciate any time you find to work on this.

<!-- gh-comment-id:1908602912 --> @rickabitdigital commented on GitHub (Jan 24, 2024): Hi John, That's great to hear and thank you very kindly for the update. Much appreciated. I have just reached the point where the basic OOXML viewer I found wasn't showing me the RichValue relationship for an image placed in cell for me to compare with the XML of the existing drawing relationships for image objects. I suppose I may need to give in and use the obvious OOXML explorer for VSCode. I'll keep going with my learning and appreciate any time you find to work on this.
Author
Owner

@slw287r commented on GitHub (Jan 29, 2024):

Snippets to get image dimensions and DPIs for in-cell embedding.

https://github.com/slw287r/imgt/blob/main/imgt.c

<!-- gh-comment-id:1914205665 --> @slw287r commented on GitHub (Jan 29, 2024): Snippets to get image dimensions and DPIs for in-cell embedding. [https://github.com/slw287r/imgt/blob/main/imgt.c](https://github.com/slw287r/imgt/blob/main/imgt.c)
Author
Owner

@jmcnamara commented on GitHub (Jan 29, 2024):

Snippets to get image dimensions and DPIs for in-cell embedding.

Note, there is already code like that in the library: https://github.com/jmcnamara/libxlsxwriter/blob/main/src/worksheet.c#L3885

It isn't public, by default, and I could make it public but the feature request is for a newer type of embedded image feature in Excel.

<!-- gh-comment-id:1915486052 --> @jmcnamara commented on GitHub (Jan 29, 2024): > Snippets to get image dimensions and DPIs for in-cell embedding. Note, there is already code like that in the library: https://github.com/jmcnamara/libxlsxwriter/blob/main/src/worksheet.c#L3885 It isn't public, by default, and I could make it public but the feature request is for a newer type of embedded image feature in Excel.
Author
Owner

@jmcnamara commented on GitHub (Feb 19, 2024):

Just a note that I've made some progress on this. I've implemented this feature in the Python and Perl versions of the library (XlsxWriter and Excel::Writer::XLSX). Next up I will implement it in the Rust version rust_xlsxwriter and then I will move on to the C version libxlsxwriter.

https://xlsxwriter.readthedocs.io/worksheet.html#embed_image

<!-- gh-comment-id:1951984351 --> @jmcnamara commented on GitHub (Feb 19, 2024): Just a note that I've made some progress on this. I've implemented this feature in the Python and Perl versions of the library (`XlsxWriter` and `Excel::Writer::XLSX`). Next up I will implement it in the Rust version `rust_xlsxwriter` and then I will move on to the C version `libxlsxwriter`. https://xlsxwriter.readthedocs.io/worksheet.html#embed_image
Author
Owner

@rickabitdigital commented on GitHub (Mar 19, 2024):

Hi John,
I'm creating sheets and images in memory - in your C Library.
Will this feature be an option for the worksheet_insert_image_buffer_opt function?

<!-- gh-comment-id:2007495266 --> @rickabitdigital commented on GitHub (Mar 19, 2024): Hi John, I'm creating sheets and images in memory - in your C Library. Will this feature be an option for the _worksheet_insert_image_buffer_opt_ function?
Author
Owner

@jmcnamara commented on GitHub (Apr 4, 2024):

Will this feature be an option for the worksheet_insert_image_buffer_opt function?

Yes. Probably.

<!-- gh-comment-id:2036826955 --> @jmcnamara commented on GitHub (Apr 4, 2024): > Will this feature be an option for the _worksheet_insert_image_buffer_opt_ function? Yes. Probably.
Author
Owner

@rickabitdigital commented on GitHub (Jul 24, 2024):

Hey @jmcnamara, Any idea when you may revisit this feature?
kind regards
Rick

<!-- gh-comment-id:2248524141 --> @rickabitdigital commented on GitHub (Jul 24, 2024): Hey @jmcnamara, Any idea when you may revisit this feature? kind regards Rick
Author
Owner

@jmcnamara commented on GitHub (Jul 28, 2024):

Any idea when you may revisit this feature?

I'll try tackle it this week.

<!-- gh-comment-id:2254612307 --> @jmcnamara commented on GitHub (Jul 28, 2024): > Any idea when you may revisit this feature? I'll try tackle it this week.
Author
Owner

@jmcnamara commented on GitHub (Jul 29, 2024):

I've pushed an initial functional version of this feature to main.

It works as follows (from the examples folder):

#include "xlsxwriter.h"

int main() {

    /* Create a new workbook and add a worksheet. */
    lxw_workbook  *workbook  = workbook_new("embed_images.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    /* Change some of the column widths for clarity. */
    worksheet_set_column(worksheet, COLS("A:B"), 30, NULL);

    /* Embed an image. */
    worksheet_write_string(worksheet, CELL("A2"), "Embed an image in a cell:", NULL);
    worksheet_embed_image(worksheet, CELL("B2"), "logo.png");

    /* Make a row bigger and embed the image. */
    worksheet_set_row(worksheet, 3, 72, NULL);
    worksheet_write_string(worksheet, CELL("A4"), "Embed an image in a cell:", NULL);
    worksheet_embed_image(worksheet, CELL("B4"), "logo.png");

    /* Make a row bigger and embed the image. */
    worksheet_set_row(worksheet, 5, 150, NULL);
    worksheet_write_string(worksheet, CELL("A6"), "Embed an image in a cell:", NULL);
    worksheet_embed_image(worksheet, CELL("B6"), "logo.png");

    workbook_close(workbook);

    return 0;
}

Which gives this output:

screenshot 1

There is still some work to do:

  • Add support for alt_text/description Done
  • Add support for urls Done
  • Add support for cell format behind the image Done
  • Add buffer support Done
  • Docs and examples Done

As an aside I'd like to refactor image handling into an Image struct that can be constructed from a path or a buffer and could be configured without the lxw_image_options struct. It could also then return the calculated dimensions of the image. Something like the Rust interface: https://docs.rs/rust_xlsxwriter/latest/rust_xlsxwriter/struct.Image.html However, that will be for another day.

<!-- gh-comment-id:2257197436 --> @jmcnamara commented on GitHub (Jul 29, 2024): I've pushed an initial functional version of this feature to main. It works as follows (from the examples folder): ```C #include "xlsxwriter.h" int main() { /* Create a new workbook and add a worksheet. */ lxw_workbook *workbook = workbook_new("embed_images.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); /* Change some of the column widths for clarity. */ worksheet_set_column(worksheet, COLS("A:B"), 30, NULL); /* Embed an image. */ worksheet_write_string(worksheet, CELL("A2"), "Embed an image in a cell:", NULL); worksheet_embed_image(worksheet, CELL("B2"), "logo.png"); /* Make a row bigger and embed the image. */ worksheet_set_row(worksheet, 3, 72, NULL); worksheet_write_string(worksheet, CELL("A4"), "Embed an image in a cell:", NULL); worksheet_embed_image(worksheet, CELL("B4"), "logo.png"); /* Make a row bigger and embed the image. */ worksheet_set_row(worksheet, 5, 150, NULL); worksheet_write_string(worksheet, CELL("A6"), "Embed an image in a cell:", NULL); worksheet_embed_image(worksheet, CELL("B6"), "logo.png"); workbook_close(workbook); return 0; } ``` Which gives this output: ![screenshot 1](https://github.com/user-attachments/assets/4a55b234-e6f4-4c6d-b77a-ce806c3edd07) There is still some work to do: - ~~Add support for alt_text/description~~ Done - ~~Add support for urls~~ Done - ~~Add support for cell format behind the image~~ Done - ~~Add buffer support~~ Done - ~~Docs and examples~~ Done As an aside I'd like to refactor image handling into an Image struct that can be constructed from a path or a buffer and could be configured without the `lxw_image_options` struct. It could also then return the calculated dimensions of the image. Something like the Rust interface: https://docs.rs/rust_xlsxwriter/latest/rust_xlsxwriter/struct.Image.html However, that will be for another day.
Author
Owner

@jmcnamara commented on GitHub (Jul 30, 2024):

I've added support for image options such as urls and alt text and also support for creating the image from a buffer:

#include "xlsxwriter.h"


/* Simple array with some PNG data. */
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() {

    /* Create a new workbook and add a worksheet. */
    lxw_workbook  *workbook  = workbook_new("embed_image_buffer.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    /* Embed the image from the buffer. */
    worksheet_embed_image_buffer(worksheet, CELL("B3"), image_buffer, image_size);

    workbook_close(workbook);

    return 0;
}

Output:

screenshot

<!-- gh-comment-id:2259324927 --> @jmcnamara commented on GitHub (Jul 30, 2024): I've added support for image options such as urls and alt text and also support for creating the image from a buffer: ```C #include "xlsxwriter.h" /* Simple array with some PNG data. */ 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() { /* Create a new workbook and add a worksheet. */ lxw_workbook *workbook = workbook_new("embed_image_buffer.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); /* Embed the image from the buffer. */ worksheet_embed_image_buffer(worksheet, CELL("B3"), image_buffer, image_size); workbook_close(workbook); return 0; } ``` Output: ![screenshot](https://github.com/user-attachments/assets/db53857b-6f57-4dfb-b28f-d9c98fa3aa1c)
Author
Owner

@jmcnamara commented on GitHub (Jul 31, 2024):

Available upstream in v1.1.8.

<!-- gh-comment-id:2261580292 --> @jmcnamara commented on GitHub (Jul 31, 2024): Available upstream in `v1.1.8`.
Author
Owner

@HEUBITLYJ commented on GitHub (Jul 1, 2025):

@jmcnamara
hello, thank you for implementing worksheet_embed_image, but since i run the example code:
`
/* Create a new workbook and add a worksheet. */
lxw_workbook *workbook = workbook_new("embed_images2.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, "sheet1");

/* Change some of the column widths for clarity. */
worksheet_set_column(worksheet, COLS("A:B"), 30, NULL);

/* Embed an image. */
worksheet_write_string(worksheet, CELL("A2"), "Embed an image in a cell:", NULL);
worksheet_embed_image(worksheet, CELL("B2"), "result.png");

/* Make a row bigger and embed the image. */
worksheet_set_row(worksheet, 3, 72, NULL);
worksheet_write_string(worksheet, CELL("A4"), "Embed an image in a cell:", NULL);
worksheet_embed_image(worksheet, CELL("B4"), "2k.png");

/* Make a row bigger and embed the image. */
worksheet_set_row(worksheet, 5, 150, NULL);
worksheet_write_string(worksheet, CELL("A6"), "Embed an image in a cell:", NULL);
worksheet_embed_image(worksheet, CELL("B6"), "result.png");

workbook_close(workbook);

`
i open the embed_images2.xlsx with office 2021, the image does not display in xlsx:

Image

is there something wrong with my operation?

looking forward to your reply

<!-- gh-comment-id:3023779452 --> @HEUBITLYJ commented on GitHub (Jul 1, 2025): @jmcnamara hello, thank you for implementing worksheet_embed_image, but since i run the example code: ` /* Create a new workbook and add a worksheet. */ lxw_workbook *workbook = workbook_new("embed_images2.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, "sheet1"); /* Change some of the column widths for clarity. */ worksheet_set_column(worksheet, COLS("A:B"), 30, NULL); /* Embed an image. */ worksheet_write_string(worksheet, CELL("A2"), "Embed an image in a cell:", NULL); worksheet_embed_image(worksheet, CELL("B2"), "result.png"); /* Make a row bigger and embed the image. */ worksheet_set_row(worksheet, 3, 72, NULL); worksheet_write_string(worksheet, CELL("A4"), "Embed an image in a cell:", NULL); worksheet_embed_image(worksheet, CELL("B4"), "2k.png"); /* Make a row bigger and embed the image. */ worksheet_set_row(worksheet, 5, 150, NULL); worksheet_write_string(worksheet, CELL("A6"), "Embed an image in a cell:", NULL); worksheet_embed_image(worksheet, CELL("B6"), "result.png"); workbook_close(workbook); ` i open the embed_images2.xlsx with office 2021, the image does not display in xlsx: ![Image](https://github.com/user-attachments/assets/330b569f-0c1c-4aa1-9ea5-0a3d23f8c0ab) is there something wrong with my operation? looking forward to your reply
Author
Owner

@jmcnamara commented on GitHub (Jul 1, 2025):

i open the embed_images2.xlsx with office 2021, the image does not display in xlsx:

This feature was added in Excel 365 in 2023. Older versions don't support it and you get an "#UNKNOWN!" or " #VALUE!" error by default.

https://libxlsxwriter.github.io/worksheet_8h.html#afaf00521027cd79c6d7d93537848b283

<!-- gh-comment-id:3023856265 --> @jmcnamara commented on GitHub (Jul 1, 2025): > i open the embed_images2.xlsx with office 2021, the image does not display in xlsx: This feature was added in Excel 365 in 2023. Older versions don't support it and you get an "#UNKNOWN!" or " #VALUE!" error by default. https://libxlsxwriter.github.io/worksheet_8h.html#afaf00521027cd79c6d7d93537848b283
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#328
No description provided.