[GH-ISSUE #292] Url and tip options do not seem to be honored when inserting an image from buffer. #234

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

Originally created by @FrankenApps on GitHub (May 31, 2020).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/292

Originally assigned to: @jmcnamara on GitHub.

When I insert a picture from the file system, everything works as expected. However when I insert it from a buffer, the .url set in the image options does not get added to the image in excel. The same thing happens with the .tip. All the other options I tested worked fine with both methods, so I suspect this might be a bug. I am using version 0.9.4.

This is my test code:

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("images.xlsx");
    lxw_worksheet* worksheet = workbook_add_worksheet(workbook, NULL);

    worksheet_set_column(worksheet, COLS("A:A"), 40, NULL);
    worksheet_set_column(worksheet, COLS("B:B"), 30, NULL);

    lxw_image_options options = { .url = "https://github.com/jmcnamara",
                                                   .tip = "Github"};

    worksheet_write_string(worksheet, CELL("A2"), "Image form buffer with hyperlink:", NULL);
    //This method does not honor the url and tip options:
    worksheet_insert_image_buffer_opt(worksheet, CELL("B2"), image_buffer, image_size, &options);

    worksheet_write_string(worksheet, CELL("A5"), "Image form file with hyperlink:", NULL);
    worksheet_insert_image_opt(worksheet, CELL("B5"), "logo.png", &options);

    workbook_close(workbook);

    return 0;
}

And the generated file: images.xlsx

Originally created by @FrankenApps on GitHub (May 31, 2020). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/292 Originally assigned to: @jmcnamara on GitHub. When I insert a picture from the file system, everything works as expected. However when I insert it from a buffer, the `.url` set in the image options does not get added to the image in excel. The same thing happens with the `.tip`. All the other options I tested worked fine with both methods, so I suspect this might be a bug. I am using version `0.9.4`. This is my test code: ```c 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("images.xlsx"); lxw_worksheet* worksheet = workbook_add_worksheet(workbook, NULL); worksheet_set_column(worksheet, COLS("A:A"), 40, NULL); worksheet_set_column(worksheet, COLS("B:B"), 30, NULL); lxw_image_options options = { .url = "https://github.com/jmcnamara", .tip = "Github"}; worksheet_write_string(worksheet, CELL("A2"), "Image form buffer with hyperlink:", NULL); //This method does not honor the url and tip options: worksheet_insert_image_buffer_opt(worksheet, CELL("B2"), image_buffer, image_size, &options); worksheet_write_string(worksheet, CELL("A5"), "Image form file with hyperlink:", NULL); worksheet_insert_image_opt(worksheet, CELL("B5"), "logo.png", &options); workbook_close(workbook); return 0; } ``` And the generated file: [images.xlsx](https://github.com/jmcnamara/libxlsxwriter/files/4707401/images.xlsx)
gitea-mirror 2026-05-05 12:00:29 -06:00
Author
Owner

@jmcnamara commented on GitHub (May 31, 2020):

Looks like a bug. I'll have a look at it.

<!-- gh-comment-id:636462396 --> @jmcnamara commented on GitHub (May 31, 2020): Looks like a bug. I'll have a look at it.
Author
Owner

@jmcnamara commented on GitHub (May 31, 2020):

Thanks for the report. I've push a fix to master and I'll package it up a bit later into a release.

<!-- gh-comment-id:636466301 --> @jmcnamara commented on GitHub (May 31, 2020): Thanks for the report. I've push a fix to master and I'll package it up a bit later into a release.
Author
Owner

@jmcnamara commented on GitHub (May 31, 2020):

P.S.: I think you are the same person on StackOverflow who suggested that the Libxlsxwriter docs for CocoaPods could be improved.

If you'd like to submit a PR with some improvements or just paste the suggestion here, that would be appreciated. See #291

<!-- gh-comment-id:636466926 --> @jmcnamara commented on GitHub (May 31, 2020): P.S.: I think you are the same person on [StackOverflow](https://stackoverflow.com/a/62027495/10238) who suggested that the [Libxlsxwriter docs for CocoaPods](https://libxlsxwriter.github.io/getting_started.html#gsg_cocoapods) could be improved. If you'd like to submit a PR with some improvements or just paste the suggestion here, that would be appreciated. See #291
Author
Owner

@FrankenApps commented on GitHub (May 31, 2020):

Great, thank you very much.

<!-- gh-comment-id:636482877 --> @FrankenApps commented on GitHub (May 31, 2020): Great, thank you very much.
Author
Owner

@jmcnamara commented on GitHub (May 31, 2020):

Fixed in version 0.9.5. Closing.

<!-- gh-comment-id:636518520 --> @jmcnamara commented on GitHub (May 31, 2020): Fixed in version 0.9.5. Closing.
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#234
No description provided.