1

I'm using the "xlsx" package in R to read, modify and write a .xlsm file.

I'm having some problems with border styling to my rows and columns:

I'm adding a dataframe (df) into a sheet and I'm applying some styles to the first column (colnamesStyle) and first row (rownamesStyle).

TABLE_ROWNAMES_STYLE <- CellStyle(wb) + Font(wb, heightInPoints = 8, name = "Arial", isBold=TRUE) + Border(position = "RIGHT", pen = "BORDER_THICK")
TABLE_COLNAMES_STYLE <- CellStyle(wb) + Font(wb, heightInPoints = 8, name = "Arial", isBold=TRUE) 


addDataFrame(df, sheet, startRow=1, startColumn=1, colnamesStyle = TABLE_COLNAMES_STYLE,rownamesStyle = TABLE_ROWNAMES_STYLE)

This works.

However I now want to do two other things:

  • apply a RIGHT 'BORDER_THIN' to all the columns in the sheet
  • apply a BOTTOM 'BORDER_THICK' to a selection of rows in the sheet

First question I've tried to tackle by defining a COL_STYLE:

COL_STYLE = CellStyle(wb) + Font(wb, heightInPoints = 8, name = "Arial") + Border(position = "RIGHT", pen = "BORDER_THIN")

and adding this to my addDataFrame line:

addDataFrame(df, sheet, startRow=1, startColumn=1, colnamesStyle = TABLE_COLNAMES_STYLE, rownamesStyle = TABLE_ROWNAMES_STYLE, colStyle = COL_STYLE)

But this doesn't work.

For the second question I've defined:

rows_border <- c(16,23,30)

which are the rows that need to have a BOTTOM BORDER_THICK. But I don't know how I can add that style to those specific rows?

user1987607
  • 2,057
  • 6
  • 26
  • 53

0 Answers0