## Create a new workbook
wb <- wb_workbook()
## Add a worksheet
wb$add_worksheet("Sheet 1")
## set col widths
wb$set_col_widths(cols = c(1, 4, 6, 7, 9), widths = c(16, 15, 12, 18, 33))
## auto columns
wb$add_worksheet("Sheet 2")
wb$add_data(sheet = 2, x = iris)
wb$set_col_widths(sheet = 2, cols = 1:5, widths = "auto")
## removing column widths
## Create a new workbook
wb <- wb_load(file = system.file("extdata", "openxlsx2_example.xlsx", package = "openxlsx2"))
## remove column widths in columns 1 to 20
wb_remove_col_widths(wb, 1, cols = 1:20)
Run the code above in your browser using DataLab