为什么在R xlsx中无法格式化xlsm?

时间:2019-10-18 16:49:30

标签: r xlsx xlsm

因此,我尝试加载数据并将其写入xlsm,但是格式化似乎不起作用。它正在写无边界的行(即使模板文件已格式化),并且我试图锁定文件以防止编辑。不过,它不会编写格式。

library(xlsx)
data = read.xlsx("my_data.xlsm", startRow=8)
pool_IDs = unique(data$Pay.pool.id)
for (i in pool_IDs) {
  temp = subset(data, Pay.pool.id==i)
  template = loadWorkBook('Template.xlsm')
  sheets = getSheets(template)
  sheet = sheets[[1]]
  cs1 = CellStyle(template) + Font(template)
  cs2 = CellStyle(template) + Font(template)
  cs3 = CellStyle(template) + Font(template) + Border()
  addDataFrame(temp, sheet, col.names=FALSE, row.names=FALSE, startRow=9,
               startColumn=1, colnamesStyle=cs2, rownamesStyle=cs1,
               colStyle=list('2'=cs2, '3'=cs2))
  print(paste("Processed pay pool", i)) 
  saveWorkbook(template, paste(i, ".xlsm", sep=''))
}

有人看过吗?

1 个答案:

答案 0 :(得分:0)

因此,默认情况下,cellStyles不会从工作簿继承。您必须明确定义格式:

cs2 = CellStyle(模板)+字体(模板,color =“ blue”)