r - 为什么在 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=''))
}
有人见过这个吗?
解决方案
因此,默认情况下,cellStyles 不会从工作簿继承。您必须明确定义格式:
cs2 = CellStyle(template) + Font(template, color="blue")
推荐阅读
- android - Android Room 多个字段具有相同的 columnName
- python - 我可以编写一个不可训练/固定权重的 Keras Lambda 层吗?
- node.js - 猫鼬 | 对所有功能保持相同的人口
- r - pandoc 和 RGL 中 knit to html 的问题
- python - Python 说“TrackerMedianFlow_create()”不再是 cv2 的属性,库更新了吗?
- java - CORS:对预检请求的响应未通过访问控制检查:预检请求不允许重定向
- wordpress - 我应该在 WordPress 上为每个页面创建一个新模板吗?
- c# - C# Selenium (0.24) Firefox 新。如何按路径加载配置文件?
- hikaricp - HikariCP/Apache DBCP2 和 PgBouncer
- javascript - 如何每 3 次将一些 HTML 推送到数组以进行输出