Reputation: 71
I need to output a data frame into an excel file. The problem is that I would like to merge-center the data only for the first column. This is an easy excel function but would like to know if this is possible directly from R using xlsx or anyother library
Any help will be appreciated.
Edit: I am new to posting questions on StackOverflow so I guess I do not have rights to upload pictures. I have added the two on my google+. The first picture is what the situation is now
The second image is how I would like it to be
Upvotes: 6
Views: 5776
Reputation: 61
This can be done in the xlsx package using:
addMergedRegion(sheet, startRow, endRow, startColumn, endColumn)
Upvotes: 6
Reputation: 98449
One possibility is to use library XLConnect
and function mergeCells()
- only for this function you have to provide reference in for of A2:B3
and so on.
library(XLConnect)
#Create file
wb <- loadWorkbook("file.xlsx", create = TRUE)
# Create a worksheet called 'cars'
createSheet(wb, name = "cars")
#write data cars to sheet
writeWorksheet(wb, cars, sheet = "cars")
# Merge the cells A2:A3 and A4:A5 on the worksheet created above
mergeCells(wb, sheet = "cars", reference = c("A2:A3","A4:A5"))
# Save workbook
saveWorkbook(wb)
Upvotes: 5