Icon

kn_​example_​r_​excel_​remove_​sheet

use R's openxlsx to remove an existing worksheet from an Excel file

use R's openxlsx to remove an existing worksheet from an Excel file

edit: warning! in this example from the first sheet "data1" some features get deleted if you use the Excel Sheet Appender from KNIME. If you saved the file from Excel itself there seems to be no problem.

use R's openxlsx to remove an existing worksheet from an Excel filehttps://forum.knime.com/t/remove-or-update-sheets-on-an-excel-file/19318/2?u=mlauber71edit: warning! in this example from the first sheet "data1" some features get deleted if you use the Excel Sheet Appender from KNIME. If you saved the file from Excel itselfthere seems to be no problem. library(openxlsx)# name and location of excel fileexcelFile <- paste0(knime.flow.in[["context.workflow.absolute-path"]], "/data.xlsx" )wb = loadWorkbook(xlsxFile = excelFile)# load existing sheet namessheet_names <- names(wb)# https://github.com/awalker89/openxlsx/issues/256#issuecomment-281380879# define name of new sheetsheet_to_remove_name <- "data2" #delete sheet if already exists if (any(sheet_names==sheet_to_remove_name)) { removeWorksheet(wb, sheet_to_remove_name) }# !! save the workbook againsaveWorkbook(wb, file = excelFile, overwrite = TRUE)knime.out <- knime.in KNIME and R — installation across operatingsystems — some remarkshttps://medium.com/p/6494a2a498cc locate and create/data/ folderwith absolute pathsdata2openxlsxdata1/data/data.xlsxsheet: data1/data/data.xlsxsheet: data2show all sheetsshow all sheetsdata1 Collect LocalMetadata Table Creator R Snippet Table Creator Excel Writer Excel Writer Read ExcelSheet Names Merge Variables Read ExcelSheet Names Excel Reader use R's openxlsx to remove an existing worksheet from an Excel filehttps://forum.knime.com/t/remove-or-update-sheets-on-an-excel-file/19318/2?u=mlauber71edit: warning! in this example from the first sheet "data1" some features get deleted if you use the Excel Sheet Appender from KNIME. If you saved the file from Excel itselfthere seems to be no problem. library(openxlsx)# name and location of excel fileexcelFile <- paste0(knime.flow.in[["context.workflow.absolute-path"]], "/data.xlsx" )wb = loadWorkbook(xlsxFile = excelFile)# load existing sheet namessheet_names <- names(wb)# https://github.com/awalker89/openxlsx/issues/256#issuecomment-281380879# define name of new sheetsheet_to_remove_name <- "data2" #delete sheet if already exists if (any(sheet_names==sheet_to_remove_name)) { removeWorksheet(wb, sheet_to_remove_name) }# !! save the workbook againsaveWorkbook(wb, file = excelFile, overwrite = TRUE)knime.out <- knime.in KNIME and R — installation across operatingsystems — some remarkshttps://medium.com/p/6494a2a498cc locate and create/data/ folderwith absolute pathsdata2openxlsxdata1/data/data.xlsxsheet: data1/data/data.xlsxsheet: data2show all sheetsshow all sheetsdata1Collect LocalMetadata Table Creator R Snippet Table Creator Excel Writer Excel Writer Read ExcelSheet Names Merge Variables Read ExcelSheet Names Excel Reader

Nodes

Extensions

Links