Define Excel's column width with R -
the final product excel csv spreadsheet has more 250 columns. wondering if there way determine column width in excel r?
i using write.csv2, produces column width in excel equal 8,43.
write.csv2(df, na = "", file= "final.csv")
if possible looking trick vary of them @ once or specific ones. running vba r option?
thank help!
please check package xlsx. using generating excel files , pretty good. there method setcolumnwidth can you. check here more detailed example xlsx package functionality.
so here working example using package xlsx
.
df <- data.frame(matrix(rnorm(100),nc=10)) library(xlsx) # must save xls or xlsx file... write.xlsx(df,"final.xlsx", row.names=false) # load wb <- loadworkbook("final.xlsx") sheets <- getsheets(wb) # set widths 20 setcolumnwidth(sheets[[1]], colindex=1:ncol(df), colwidth=20) saveworkbook(wb,"final.xlsx") # autosize column widths autosizecolumn(sheets[[1]], colindex=1:ncol(df)) saveworkbook(wb,"final.xlsx")
Comments
Post a Comment