Giter Site home page Giter Site logo

Comments (7)

jmcnamara avatar jmcnamara commented on June 11, 2024 1

The wrapped libxlsxwriter library doesn't have a function/method for writing a url and specifying an alternative string like the Perl/Python versions. Instead, the suggested workaround is to write the URL and then overwrite the cell with an alternative string with the same cell format.

Here is an xlsxwriter.rs example:

use xlsxwriter::{format::*, Workbook};

fn main() -> Result<(), xlsxwriter::XlsxError> {
    let workbook = Workbook::new("gh54.xlsx")?;

    let mut worksheet = workbook.add_worksheet(None)?;

    // Create a url format.
    let mut url_format = Format::new();
    url_format.set_font_color(FormatColor::Blue);
    url_format.set_underline(FormatUnderline::Single);

    let image_url = "https://docs.rs/-/rustdoc.static/rust-logo-151179464ae7ed46.svg";

    // Write a url.
    worksheet.write_url(0, 0, image_url, Some(&url_format))?;

    // Overwrite the displayed URL string with another string. Note, we need to
    // specify the format for the string to match the hyperlink.
    worksheet.write_string(0, 0, "Photo 1", Some(&url_format))?;

    workbook.close()
}

Output:

screenshot

Sample file: gh54.xlsx

from xlsxwriter-rs.

jmcnamara avatar jmcnamara commented on June 11, 2024 1

I was under an impression that the way they do it gives you an ability to insert multiple links via comma, like "Photo 1, Photo2, Photo3" all in single cell, each going to its own URL.

Unfortunately, that isn't possible in Excel. It only allows one URL per cell.

from xlsxwriter-rs.

jmcnamara avatar jmcnamara commented on June 11, 2024

Do you mean you want to link to some image within the file or to some image at an external URL?

from xlsxwriter-rs.

k-bx avatar k-bx commented on June 11, 2024

External url opened in browser, basically a web page.

from xlsxwriter-rs.

k-bx avatar k-bx commented on June 11, 2024

That's a clever hack, thank you! Created an upstream issue at jmcnamara/libxlsxwriter#416 too

from xlsxwriter-rs.

jmcnamara avatar jmcnamara commented on June 11, 2024

That's a clever hack, thank you! Created an upstream issue at jmcnamara/libxlsxwriter#416 too

That isn't really a hack. It is the documented way of doing it in libxlsxwriter. It is also more or less what Excel does (it stores a link for the cell but also adds an additional text, or number, or formula, for the cell).

If it works for your use case you should close this issue.

from xlsxwriter-rs.

k-bx avatar k-bx commented on June 11, 2024

Oh, I see. I didn't check if it's possible in JS lib, but I was under an impression that the way they do it gives you an ability to insert multiple links via comma, like "Photo 1, Photo2, Photo3" all in single cell, each going to its own URL. I don't need it for now, can open a new issue later if needed.

from xlsxwriter-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.