Batch removing the second sheet from many excel sheets in R? - r

I have many excel sheets that I need to remove the second sheet before importing them. All files are .xlsx type in one folder and have same format. What kind of function should I use to achieve such?
Before removal, the 'remarks' sheet needs to be removed
Wanted outcome: deleted sheet 'remarks'. need to loop it through all files in the folder
Thanks for your help in advance

Related

How to check if excel file with multiple sheets contains macros/formulas in R after importing?

Once I have imported excel file with multiple sheets into R I want to check if excel sheets contains any formulas/VBA/macros into it.
Also I am not sure whether while importing any excel sheets that contains formulas also gets imported along with file in R or it's only importing values because I am not able find it.
Any help would be appreciated!!!

`openxlsx`: load and apply all formatting from the read file

I try to read in a spreadsheet that consists of one sheet and then add a new sheet to this file. So I read the data into R with openxlsx::read.xlsx, but in doing so I also lose the formatting of the first sheet.
Any ideas on how I can preserve the formatting of the first sheet?
have a look at the loadWorkbook function which reads in the whole Excel file as is and then you can use addWorksheet, writeData and saveWorkbook to add a worksheet, fill it with data and save the whole thing - which should presever the formatting of your original sheets.

Is there a way to read multiple excel files into R, but only up to a certain creation date? (Note: Date does not exist within the actual excel files.)

I have multiple excel files in multiple directories that I am reading into R. However, I don't want to read in EVERY excel file; I only want to read in the most recent ones (for example, only the ones created in the last month). Is there a way to do this?
Currently I am using this to read in all of the excel files, which is working just fine:
filenames <- Sys.glob(file.path('(name of dir)', "19*", "Electrode*02.xlsx")) <br>
elecsheet <- do.call("cbind", lapply(filenames, read_excel))
Somewhere in this second line of code (I think), I need to tell R to look at the metadata and only read in the excel files that have been created since a certain date.
Thank you!

R - How to read last sheet of each excel file?

I have multiple excel files that I would like to read into R, however each file has differing number of sheets and I would like to read only the last sheet in each file into R, is there a way to do this? Thanks.
You can first extract the number of sheets and then only access that sheet:
library(readxl)
sheetNr <- length(excel_sheets(filename))
read_excel(filename, sheet = sheetNr)

how to write multiple dataframe to multiple sheet of one csv excel file in R?

I am trying to write multiple dataframe to a single csv formated file but each in a different sheet of the excel file:
write.csv(dataframe1, file = "file1.csv",row.names=FALSE)
write.csv(dataframe2, file = "file2.csv",row.names=FALSE)
is there any way to specify the sheet along with the csv file in this code and write them all in one file?
thank you in advance,
This is not possible. That is the functionality of csv to be just in one sheet so that you can view it either from notepad or any other such software. If you still try to write it would get over ridden. Just try to open a csv and open a new sheet and just write some values and save it. The values which were already there is erased. one excel file in csv format can have only one sheet.
The xlsx and XLConnect packages will do the trick as well.

Resources