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

Add suport for Excel style hyperlinks #55

Closed
wants to merge 0 commits into from
Closed

Add suport for Excel style hyperlinks #55

wants to merge 0 commits into from

Conversation

jmcnamara
Copy link
Contributor

@jmcnamara jmcnamara commented Apr 21, 2021

Replace existing hyperlink support via formulas with native Excel url types and the default hyperlink style.

This is work in progress and not complete but I wanted to set up a conversation.

The advantage of using the native style urls is that they look like Excel links and they supports a hyperlink style (not format) that changes colour once the link is clicked, as shown in the image:

screenshot

The PR is an initial pass at this but I don't know what would be the best way to pass back the 'url' and optional 'name' as a pair in the xl_hyperlink object. So if you are interested in adopting this feature I would appreciate your guidance on that. My initial thoughts were to have them in a list but I don't know if that is the best way.

Relates to issue #5.

R/excel_types.R Outdated
if(length(name)){
hyperlink <- paste(hyperlink, dubquote(name), sep = ",")
}
out <- xl_formula(sprintf("=HYPERLINK(%s)", hyperlink))
out <- url
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really needs to return something like list(url, name).

src/write_xlsx.c Outdated
@@ -170,7 +165,7 @@ SEXP C_write_data_frame_list(SEXP df_list, SEXP file, SEXP col_names, SEXP forma
case COL_HYPERLINK:{
SEXP val = STRING_ELT(col, i);
if(val != NA_STRING && Rf_length(val))
assert_lxw(worksheet_write_formula(sheet, cursor, j, Rf_translateCharUTF8(val), hyperlink));
assert_lxw(worksheet_write_url(sheet, cursor, j, Rf_translateCharUTF8(val), NULL));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be worksheet_write_url_opt() to also set the string name for the hyperlink. But that is an easy change.

@jmcnamara jmcnamara closed this Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant