xlsx2pdf: Convert xlsx to pdf

View source: R/docx2pdf.R

xlsx2pdfR Documentation

Convert xlsx to pdf

Description

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".

Usage

xlsx2pdf(
  input,
  output = gsub("\\.(xlsx|xlsm)$", ".pdf", input, ignore.case = TRUE)
)

Arguments

input, output

file input and optional file output (default to input with pdf extension).

Value

the name of the produced pdf (the same value as output)

Macos manual authorizations

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:

  1. allow R to run 'AppleScript' scripts that will control Excel

  2. allow Excel to write to the working directory.

This process is a one-time operation.

Examples

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.")
  }
}

doconv documentation built on Oct. 22, 2026, 5:14 p.m.