Create duplicates of excel sheets

I have an excel sheet with me with a particular set of variables. My objective is to create multiple sheets in the same workbook. One of the variable is teacher name and ID. I want the variable names to remain the same for all sheets except that the name and ID of instructor must change in each sheet. For example here below, I have the data frame called data. In that data frame, the instructor name is blank. The sheets that I need to create needs to fill that column with the Instructor ID and name taking it from the data frame called instr. Hence the first sheet will have filled with the ID INS001 and the corresponding name. The second sheet will have INS002 and the corresponding name. How can I do this?


  ~ins_id, ~ins_name, ~material, ~kits, ~tlm,
       NA,        NA,        2L,    3L,   5L

   ~Ins_id,   ~Ins_name,
  "INS001",    "Nithin",
  "INS002", "Madhumati",
  "INS003",     "Arjun",
  "INS004",   "Shijith"
common_things <- tibble::tribble(
  ~material, ~kits, ~tlm,
  2L, 3L, 5L

instr <- tibble::tribble(
  ~Ins_id, ~Ins_name,
  "INS001", "Nithin",
  "INS002", "Madhumati",
  "INS003", "Arjun",
  "INS004", "Shijith"
(all_the_data <- expand_grid(instr, common_things) |>
    split(~Ins_id) )

wb <- createWorkbook()

    \(x) {
        sheetName = x$Ins_id
      writeData(wb, sheet = x$Ins_id, x)
saveWorkbook(wb, "example.xlsx", overwrite = TRUE)

Wow.. That was my precise requirement. Thanks a lot.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.