Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url and tip options do not seem to be honored when inserting an image from buffer. #292

Closed
FrankenApps opened this issue May 31, 2020 · 5 comments
Assignees

Comments

@FrankenApps
Copy link
Contributor

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

@jmcnamara
Copy link
Owner

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

jmcnamara added a commit that referenced this issue May 31, 2020
Fix for issue where hyperlinks urls and tips were ignored for
worksheet_insert_image_buffer_opt() images.

Issue #292
@jmcnamara
Copy link
Owner

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

@jmcnamara
Copy link
Owner

jmcnamara commented 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

@FrankenApps
Copy link
Contributor Author

Great, thank you very much.

@jmcnamara
Copy link
Owner

Fixed in version 0.9.5. Closing.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 2, 2020
From the changelog:

 - Fix for issue where hyperlinks urls and tips were ignored for
   `worksheet_insert_image_buffer_opt()` images.

   jmcnamara/libxlsxwriter#292

 - Added #LXW_CHART_LINE_STACKED and #LXW_CHART_LINE_STACKED_PERCENT
   line charts subtypes.

 - Removed LXW_ERROR_SHEETNAME_RESERVED warning which was used with the
   reserved worksheet name "History". However, this is an allowed
   worksheet name in some Excel variants so the warning has been turned
   into a documentation note instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants