jmcnamara / rust_xlsxwriter

A Rust library for creating Excel XLSX files.
https://crates.io/crates/rust_xlsxwriter
Apache License 2.0
250 stars 23 forks source link

feature request: Implement the URLs in images feature #91

Closed 33nya closed 1 month ago

33nya commented 2 months ago

I have noticed that the URLs in images feature outlined in the roadmap hasn't been implemented yet. I am interested in contributing to this feature and was wondering if there is an opportunity for me to do so.

I have some ideas on how it could be implemented, with reference to the Python version library:

  1. If the image URL exists, add it to the drawing_relationships vector.
  2. Adding a function to write the element when drawing an object.
  3. Adding a boolean field to the DrawingType::Image option to determine whether to call the write_a_hlink_click function or not.

However, I am uncertain if I am proceeding in the right direction, or if there are any additional aspects that should be taken into consideration. Could you give me some advice on it?

Thank you for your time and consideration.

jmcnamara commented 1 month ago

Thanks for the offer of help. From memory there were a lot of edge cases and 20+ test cases, so it is probably best if I tackle this myself. I'll work on it in the next few weeks and I'll let you know when there is anything testable.

jmcnamara commented 1 month ago

I've pushed an initial version of this to the image_url branch if you want to do some early access testing. It passes all the XlsxWriter tests but it needs some heavy refactoring and the Image API will probably change from &mut self to mut self so the methods can be chained. It also needs more tests for the embed_image() variant.

That notwithstanding it should be okay to test if you want. Currently it works like this:

    let mut image = Image::new("github_logo.png")?;
    image.set_url("https://github.com")?;

    worksheet.insert_image(8, 4, &image)?;
jmcnamara commented 1 month ago

I've refactored and rebased the code and merged it back to main. The API is now:

    let image = Image::new("github_logo.png")?
        .set_url("https://github.com")?;

    worksheet.insert_image(8, 4, &image)?;

I'l push it out in a release in the next 1-2 days.

jmcnamara commented 1 month ago

This feature is now upstream in v0.68.0.