as_Workbook: Convert a huxtable for Excel

Description Usage Arguments Details Value Examples

Description

If the openxlsx package is installed, Huxtables can be converted to openxlsx::openxlsx() Worbook objects, for use in Excel documents.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
as_Workbook(ht, ...)

## S3 method for class 'huxtable'
as_Workbook(
  ht,
  Workbook = NULL,
  sheet = "Sheet 1",
  write_caption = TRUE,
  start_row = 1,
  start_col = 1,
  ...
)

Arguments

ht

A huxtable.

...

Not used.

Workbook

An existing Workbook object. By default, a new workbook will be created.

sheet

Name for the worksheet where the huxtable will be created.

write_caption

If TRUE, print any caption in the row above or below the table.

start_row, start_col

Number. Write data starting at the given row and column.

Details

Use openxlsx::saveWorkbook() to save the resulting object to an Excel file.

Properties are supported with the following exceptions:

Huxtable tries to guess appropriate widths and height for rows and columns; numeric width() and height() are treated as scaling factors.

Contents are only stored as numbers if a whole column is "numeric", i.e. can be converted by as.numeric()). Otherwise, they are stored as text.

Value

An object of class Workbook.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
wb <- as_Workbook(jams)

## Not run: 
  openxlsx::saveWorkbook(wb,
        "my-excel-file.xlsx")

## End(Not run)

# multiple sheets in a single workbook:
wb <- openxlsx::createWorkbook()
wb <- as_Workbook(jams,
      Workbook = wb, sheet = "sheet1")
wb <- as_Workbook(
      hux("Another", "huxtable"),
      Workbook = wb,
      sheet = "sheet2")

Example output

Note: zip::zip() is deprecated, please use zip::zipr() instead

huxtable documentation built on May 15, 2021, 1:09 a.m.