千位分隔符 - 使用R中的XLConnect格式化excel单元格

时间:2015-02-20 10:43:27

标签: r excel xlconnect

我使用XLConnect将具有大值的表导出到.xlsx。

有没有办法将结果写入带有激活的千位分隔符的excel-cell?

library(XLConnect)
#example for a large value
a <- 10000000000

wb <- loadWorkbook("sof_q.xlsx"), create = TRUE)
    cs <- createCellStyle(wb)
    setDataFormat(cs, format = "0.00")
createSheet(wb, name = "a")
writeWorksheet(wb,a,"a",startRow = 1, startCol = 1, header = TRUE)
    rc = expand.grid(row = 1:2, col = 1:2)
    setCellStyle(wb, sheet = "a", row = rc$row, col = rc$col, cellstyle = cs)
    setColumnWidth(wb, sheet = "a", column = 1:5, width = -1)
saveWorkbook(wb)

在Excel中,a应该如下所示

10.000.000.000

使用

setDataFormat(cs, format = "0,000,000.00")

可能会有效,但在值较短的情况下,我有像

这样的值
0,032,666.29

1 个答案:

答案 0 :(得分:5)

将#用于数字占位符:

setDataFormat(cs, format = "###,###.00")

setDataFormat(cs, format = "###,##0")