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

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.

Related

Writing new data to an existing excel file that has an XML map attached, without losing the XML data in R

I am trying to write to an excel file that needs to be uploaded somewhere. The target software creates an excel file which has an XML map attached to it. I recreated the entire file structure in R using code, but any time I try to write to that excel file, i think R actually deletes the old file and creates a new one instead, because the XML map is gone the moment I start writing any data to it. Loading up the workbook also doesn't seem to bring in the xml map, only the workbook data and sheets.
Is there a way to write data to this existing file within R (or python) without losing the XML map? Now i need to generate a file and manually copy paste the data into the other excel file.
I've been trying with xlsx, readxl, xml2 packages.
In the past Ive deal with a similar problem. To my knowledge, almost all the R packages that interact with excel replace the entire file with a new one. Except the openxlsx package. You can replace specific sheets, and range of cells, whitout touching the rest (data, styling , etc..). One last comment is that I dont know much about XLM maps, but maybe you are lucky.
Here is the vignette:
https://cran.r-project.org/web/packages/openxlsx/vignettes/Introduction.html
Hope it helps

Batch removing the second sheet from many excel sheets in 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

R - Extracting worksheet style and copying into a different workbook

I would like to copy the entire sheet (retaining the style) from one workbook into another workbook.
I tried cloneSheet() from the XLConnect package but I'm not sure if it can be used to clone a worksheet to a different workbook.
I also tried createSheet() to create a new sheet in workbook_1.xlsx then, readWorksheet() in workbook_2.xlsx, and finally writeWorksheet() to write the data from workbook_2 to workbook_1, but only the data gets transferred and not the style.
Thanks in advance for any inputs.

How to remove the first row in every sheet in r?

I have an excel document with multiple sheets. I was curious if there was a way to remove the first row of every sheet as there is a header file on the sheet that isn't necessary but this automatically appears on each sheet. I would rather not open the file and remove the first row as this can cause possible data errors.
"Many functions that read-in data will have a "skip" argument (under some name). E.g., for readxl::read_excel() you can use skip = 1 to skip one line. If you check out the documentation for the function you are using it should help clarify things."
- Andrew

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