First, initiate Excel printing with set_opts( output = "Excel" )
. Then, use
the various tabulation functions to "print" / generate the tables and charts.
Finally, call save_excel()
to save all of these tables and charts to a
single Excel file, which consists of one or more spreadsheets, one for each table or chart.
Details
By default, a file name is generated automatically.
Before using Excel printing, be sure to install these packages: openxlsx2
and mschart
.
See also
Other print:
print.surveytable_table()
Examples
set_survey(namcs2019sv)
#> Survey info {NAMCS 2019 PUF}
#> ┌───────────┬──────────────┬────────────────────────────────────────────────┐
#> │ Variables │ Observations │ Design │
#> ├───────────┼──────────────┼────────────────────────────────────────────────┤
#> │ 33 │ 8,250 │ Stratified 1 - level Cluster Sampling design │
#> │ │ │ (with replacement) │
#> │ │ │ With (398) clusters. │
#> │ │ │ namcs2019sv = survey::svydesign(ids = ~CPSUM, │
#> │ │ │ strata = ~CSTRATM, weights = ~PATWT │
#> │ │ │ , data = namcs2019sv_df) │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#>
set_opts(output = "excel")
#> * Printing tables and charts to an Excel workbook.
total()
#> Printing Total {NAMCS 2019 PUF} to an Excel workbook. Use save_excel() to save that workbook to a file.
tab("AGER")
#> Printing Patient age recode {NAMCS 2019 PUF} to an Excel workbook. Use save_excel() to save that workbook to a file.
save_excel(file = "my_workbook.xlsx", .temp = TRUE)
#> Writing Total {NAMCS 2019 PUF} and 1 other tables to my_workbook.xlsx.
set_opts(output = "auto")
#> * Printing with huxtable for screen, gt for HTML, or kableExtra for PDF.