I read a file, change its content, and then I want to write the dataframe
into a new file. The thing that bugs me is that the width of the columns isn't adjustable within Excel (it does not save changes).
I was wondering if it is possible to write the csv file with column width that fits the longest value.
dat <- read.csv("Input.csv")
# Do some processing
#Write the new file
write.csv(dat, "Output.csv", row.names=FALSE)
Edit 1:
dat <- read.csv("Input.csv")
createSheet(wb, "test")
writeWorksheet(wb, dat, "test")
colWidths <- sapply(1:ncol(dat), function(i) max(c(8, nchar(c(names(dat)[i], as.character(dat[, i]))))))
setColumnWidth(wb, "test", 1:ncol(dat), colWidths * 256)
saveWorkbook(wb)
what did I do wrong? It writes an empty file.