【问题标题】:Add one excel worksheet from one file to another workbook in R将一个文件中的一个excel工作表添加到R中的另一个工作簿
【发布时间】:2022-07-21 02:40:20
【问题描述】:

所以我有一个工作簿 wb,其中一张名为“Ice Data” 我有一个包含 5 张工作表的 excel 文件“path/test.xlsm”,但我只想克隆名为“Pasta”的第一张工作表并将其添加到另一个工作簿 wb。

我不知道该怎么做。我已经查过 openxlsx 但我似乎无法管理。

谢谢

【问题讨论】:

    标签: r excel clone openxlsx


    【解决方案1】:
    library(openxlsx)
    
    ## Open the first workbook,  add a new sheet called Pasta 
    ## and get its sheet number.
    wb1 = loadWorkbook("test1.xlsx")
    addWorksheet(wb1, "Pasta")
    TargetSheet = grep("^Pasta$", names(wb1))[[1]]
    
    ## open the second workbook, find and read the Pasta sheet.
    wb2 = loadWorkbook("test2.xlsx")
    SourceSheet = grep("^Pasta$", names(wb2))[[1]]
    Sheet2Data = readWorkbook(wb2, SourceSheet)
    
    ## Write the data to the new sheet in the first workbook and save. 
    writeData(wb1, TargetSheet, Sheet2Data)
    saveWorkbook(wb1, "Test3.xlsx")
    

    【讨论】:

      猜你喜欢
      • 2021-06-16
      • 1970-01-01
      • 2021-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-23
      • 2023-01-24
      • 1970-01-01
      相关资源
      最近更新 更多