rexceltextr-xlsx

R - Add text to merged cell using xlsx package


I have created a merged cell in an excel file using the xlsx package in R. I'd like to write text in this merged cell and have tried the code below, however this leaves the cell blank, with no text anywhere in that worksheet.

wb = createWorkbook()

sheet = createSheet(wb, "READ_ME")
addMergedRegion(sheet=sheet, startRow = 1, endRow = 10, startColumn = 1, endColumn = 10)
addDataFrame("Testing", sheet=sheet)

How can I add text to this merged cell?


Solution

  • Only specify row.names and col.names arguments.

    library(xlsx)
    
    wb = createWorkbook()
    
    sheet = createSheet(wb, "READ_ME")
    addMergedRegion(sheet=sheet, startRow = 1, endRow = 10, startColumn = 1, endColumn = 10)
    addDataFrame("Testing", sheet=sheet, col.names = F, row.names = F)
    xlsx::saveWorkbook(wb, "eso.xlsx")