ARIMITRA MAITI
ARIMITRA MAITI

Reputation: 323

xlsx package saveWorkbook function

I have a data frame and I am using the below code

wb <- createWorkbook(type = "xlsx")
sheet1 <- createSheet(wb, sheetName = "sheet1")
addDataFrame(df, sheet1, col.names = TRUE, row.names = FALSE, startRow = 1)
saveWorkbook(wb, file = "filename.xlsx")

I have already set the directory through R studio so need not to mention it explicitly. I have gone through the documentation of write.xlsx which give an error commonly found on the web. The issue is when I download and pen the workbook I see the data like this

Column1 Column2 Column3 Column4 Column5 Column6
c(value1,value2,……) c(value1,value2,……) c(value1,value2,……) c(value1,value2,……) c(value1,value2,……) c(value1,value2,……)

I only find two rows, first row gives the column names and second row has all values of respective column in vector format (i.e. enclosed in c()). I do not want to row.names = TRUE as it would create an extra column with the row numbers.

same problem happens with write.xlsx2 function Any help would be much appreciated.

Upvotes: 1

Views: 2331

Answers (1)

Digvijay Sawant
Digvijay Sawant

Reputation: 1079

I don't think the issue is during download. Rather it's during addDataFrame(). While adding your df, you will need to coerce your dataframe as a list. Example:

addDataFrame(list(df), sheet1, col.names = TRUE, row.names = FALSE, startRow = 1)

Upvotes: 2

Related Questions