I am exporting some code to excel using your very helpful package, and trying to do it to 1 workbook over 3 sheets. However to do this I have repeated each command thrice, this can't be a good way to do it? Where am I going wrong? In addition, while the reprex below shows very short numerical observations, in reality the first column of my table needs to be much wider than the others, as it has a lot of text (while the rest don't). Is there a way to set this, or do i need to drag it across when I open the excel file? Thanks so much!
library(r2excel)
#> Loading required package: xlsx
sample_prime1 <- 1:4
sample_prime2 <- 10:14
sample_prime3 <- 22:26
# Create an Excel workbook.
filename <- "validitycheck.xlsx" #The name of the file that will be saved
wb <- createWorkbook(type="xlsx") #Creating an excel workbook
# Create a sheet in that workbook to contain the data table
sheet1 <- createSheet(wb, sheetName = "prime1")
sheet2 <- createSheet(wb, sheetName = "prime2")
sheet3 <- createSheet(wb, sheetName = "prime3")
# Add table : add a data frame for sheet 1
xlsx.addHeader(wb, sheet1, value="Validty for prime 1")
xlsx.addLineBreak(sheet1, 1)
xlsx.addTable(wb, sheet1, sample_prime1,
fontColor="darkblue", fontSize=14,
rowFill=c("white", "lightblue"),
startCol=2,
row.names=FALSE,
col.names = FALSE)
# Add table : add a data frame for sheet 2
xlsx.addHeader(wb, sheet2, value="Validty for prime 2")
xlsx.addLineBreak(sheet2, 1)
xlsx.addTable(wb, sheet2, sample_prime2,
fontColor="darkblue", fontSize=14,
rowFill=c("white", "lightblue"),
startCol=2,
row.names=FALSE,
col.names = FALSE)
# Add table : add a data frame for sheet 3
xlsx.addHeader(wb, sheet3, value="Validty for prime 3")
xlsx.addLineBreak(sheet3, 1)
xlsx.addTable(wb, sheet3, sample_prime3,
fontColor="darkblue", fontSize=14,
rowFill=c("white", "lightblue"),
startCol=2,
row.names=FALSE,
col.names = FALSE)