小编jku*_*kud的帖子

使用 R 中的 openxlsx 包格式化数字

我正在尝试使用 openxlsx 格式化某些列,以将 r 数据帧写入 Excel 文件。

这是 R 数据框的片段:

在此输入图像描述

“种子”列中的方括号部分用于为 Excel 输出添加上标。

这是我用来编写该文件的代码:


openxlsx::addWorksheet(wb, sheetName = 'data') # add sheet

openxlsx::writeData(wb, sheet ='data', 
                    x=df, xy=c(1, 1),withFilter = T) # write data on workbook

# make quality codes superscript
for(i in grep("\\_\\[([A-z0-9\\s]*)\\]", wb$sharedStrings)){
  # if empty string in superscript notation, then just remove the superscript notation
  if(grepl("\\_\\[\\]", wb$sharedStrings[[i]])){
    wb$sharedStrings[[i]] <- gsub("\\_\\[\\]", "", wb$sharedStrings[[i]])
    next # skip to next iteration
  }
  
  # insert additional formatting in shared string
  wb$sharedStrings[[i]] <- gsub("<si>", …
Run Code Online (Sandbox Code Playgroud)

r openxlsx

5
推荐指数
0
解决办法
1605
查看次数

标签 统计

openxlsx ×1

r ×1