| xlsx2pdf | R Documentation |
Convert xlsx to pdf directly using "Microsoft Excel". This function will not work if "Microsoft Excel" is not available on your machine.
All the sheets of the workbook are exported. Each sheet is scaled to fit the width of one page (its height can span several pages), so the scale can differ from one sheet to another. The workbook itself is not modified.
The calls to "Microsoft Excel" are made differently depending on the operating system. On "Windows", a "PowerShell" script using COM technology is used to control "Microsoft Excel". On macOS, an "AppleScript" script is used to control "Microsoft Excel".
xlsx2pdf(
input,
output = gsub("\\.(xlsx|xlsm)$", ".pdf", input, ignore.case = TRUE)
)
input, output |
file input and optional file output (default to input with pdf extension). |
the name of the produced pdf (the same value as output)
On macOS the call is happening into a working
directory managed with function working_directory().
Manual interventions are necessary to authorize 'Excel' applications to write in a single directory: the working directory. These permissions must be set manually, this is required by the macOS security policy.
You must also click "allow" two times to:
allow R to run 'AppleScript' scripts that will control Excel
allow Excel to write to the working directory.
This process is a one-time operation.
library(locatexec)
if (exec_available('excel')) {
file <- system.file(package = "doconv",
"doc-examples/example.xlsx")
out <- xlsx2pdf(input = file,
output = tempfile(fileext = ".pdf"))
if (file.exists(out)) {
message(basename(out), " is existing now.")
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.