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

makeHyperlinkString for external files should have sheet, row and col as optional parameters #58

Closed
Danfro opened this issue Apr 8, 2020 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@Danfro
Copy link

Danfro commented Apr 8, 2020

When using the makeHyperlinkString function for an external file, the parameter sheet is a "must-have" parameter, not an optional one.

When passing the string to writeFormula, the hyperlink text=link does get the sheet name added to the filename like this:
=HYPERLINK("[G:/foldername/filename.ext]'Sheetname'!rowcol

I can not reproduce it now anymore, but on the first run like that, my excel file got corrupted. Excel error report said, the file could be corrected by removing a named area.

The hyperlink string should only pass the filename without sheet information.

@Danfro
Copy link
Author

Danfro commented Apr 8, 2020

R v3.6.1
R-Studio v1.2.1335
openxlsm v4.1.4
Excel 2016

Forgot to add that here for reference.

@ycphs
Copy link
Owner

ycphs commented Apr 17, 2020

It would be really helpful if you could provide sample files. If the problem doesn't occur, then we could consider the issue as closed?

@ycphs ycphs added the question Further information is requested label Apr 17, 2020
@Danfro
Copy link
Author

Danfro commented Apr 17, 2020

Not reproducible is only the corrupted file issue because I only tried with one file so far. Maybe next week at work I can find some time to do more tests on that and provide a sample file. I can't test at home because I do not have Excel available.

But the sheetname and row/column information is added every time. At least I do not see the purpose for those "insheet-information" when having a link to an external file. Maybe I am just missing something? 🤔

@Danfro
Copy link
Author

Danfro commented Apr 28, 2020

I am more or less running the following code:

file <- paste("C:/test.xlsx", sep= "")
wb <- loadWorkbook(file)
sheet <- getSheetNames(file)[1]
linkString <- makeHyperlinkString(sheet, col = 1, row = 4, text = "test.png", file = "G:/test.png")
writeFormula(wb,blatt,x = linkString, startCol = 1, startRow = 1)
saveWorkbook(wb,file, overwrite = TRUE)

Here is the resulting file with a hyperlink in it's variations:
test.xlsx

As you can see, the formula created by makehyperlink does look like this:

=HYPERLINK("[C:/test.png]'Tabelle1'!A4"; "test.png")

When using the build in Excel =HYPERLINK() command it does look like this:

=HYPERLINK("C:/test.png";"test.png")

There are clearly some parts added that do not belong there.

And sheet is not an optional parameter. If I run the makehyperlink command without the sheet parameter, I do get the following error:

Error in sprintf("[%s]'%s'!%s", file, sheet, cell) : 
argument "sheet" is missing, with no default

@github-actions
Copy link

github-actions bot commented Aug 7, 2021

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Aug 7, 2021
@JanMarvin JanMarvin removed the Stale label Aug 13, 2021
@JanMarvin JanMarvin self-assigned this Aug 13, 2021
ycphs added a commit that referenced this issue Sep 2, 2021
improve makeHyperlinkString. Closes #57 #58
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 4, 2025
# openxlsx 4.2.7.1

* It's now possible to insert a hyperlinked image by passing a URL,
  relative or absolute file path, or mailto string to the new
  `address` parameter of `insertImage()`.

# openxlsx 4.2.7

* Fixed warning on `dataValidation(..., type = "list")`
  ([#342](ycphs/openxlsx#342))

* Added optional argument to `loadWorkbook` to decide if empty/blank
  cells should be converted to NA_character_ (the default) or left
  blank as is

* `saveWorkbook()` now succeeds when called after the user has set
  column widths for a range of columns (e.g. 1:2), saved the workbook,
  then set column widths for a new range that is inclusive of the
  previous one (e.g. 1:5)
  ([#493](ycphs/openxlsx#493)).

## Improvements

* Improve detectDates
  ([#288](ycphs/openxlsx#288))

* Preserve window size and position, also `getWindowSize()` and
  `setWindowSize()`
  ([466](ycphs/openxlsx#466))

# openxlsx 4.2.6

* Fix external links
  ([#410](ycphs/openxlsx#410))

* Do not add unneccessary sheetPr node
  ([#409](ycphs/openxlsx#409))

* Add support for `namedRegion`s having dots and other special
  characters ([#338](ycphs/openxlsx#338)).

* Add type blanks and not blanks to conditional formatting
  ([#311](ycphs/openxlsx#311))

# openxlsx 4.2.5

## Fixes

* `openxlsx_setOp()` now works with named list
  ([#215](ycphs/openxlsx#215))

* `loadWorkbook()` imports `inlineStr`. Values remain `inlineStr` when
  writing the workbook with `saveWorkbook()`. Similar `read.xlsx` and
  `readWorkbook` import `inlineStr`.

* `read.xlsx()` no longer changes random seed
  ([#183](ycphs/openxlsx#183))

* fixed a regression that caused fonts to be read in incorrectly
  ([#207](ycphs/openxlsx#207))

* add option to save as read only recommended
  ([#201](ycphs/openxlsx#201))

* fixed writing hyperlink formulas
  ([#200](ycphs/openxlsx#200))

* `write.xlsx()` now throws an error if it doesn't have write
  permissions ([#190](ycphs/openxlsx#190))

* `write.xlsx()` now again uses the default of `overwrite = TRUE` for
  saving files ([#249](ycphs/openxlsx#249))

* `as.character.formula()` exported to warn about potential conflicts
  with other packages
  ([#312](ycphs/openxlsx#312),
  [#315](ycphs/openxlsx#315))

## Improvements

* `options()` are more consistently set in functions (see:
  [#289](ycphs/openxlsx#262))

* `Workbook$show()` no longer fails when called in a 0 sheet
  workbook([#240](ycphs/openxlsx#240))

* `read.xlsx()` again accepts `.xlsm` files
([#205](ycphs/openxlsx#205),
[#209](ycphs/openxlsx#209))

* `makeHyperlinkString()` does no longer require a sheet argument
  ([#57](ycphs/openxlsx#57),
  [#58](ycphs/openxlsx#58))

* improvements in how `openxlsx` creates temporary directories (see
  [#262](ycphs/openxlsx#262))

* `writeData()` calls `force(x)` to evaluate the object before options
  are set ([#264](ycphs/openxlsx#264))

* `createComment()` now correctly handles `integers` in `width` and
  `height` ([#275](ycphs/openxlsx#275))

* `setStyles()` accepts `halign="justify"`
  ([#305](ycphs/openxlsx#305))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants