Closed k-bx closed 10 months ago
Do you mean you want to link to some image within the file or to some image at an external URL?
External url opened in browser, basically a web page.
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:
Sample file: gh54.xlsx
That's a clever hack, thank you! Created an upstream issue at https://github.com/jmcnamara/libxlsxwriter/issues/416 too
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.
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.
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.
I'd like to paste a text saying "Photo 1" which, upon click, leads to some photo link. It should look like this (in Ukrainian):
Is it possible via current means of xlsxwriter-rs?