Hello,
I'm very new to R and Rstudio and am just learning. I have tried to search all the topics but did not find this specific case that I'm looking for.
Here is what I have:
I have multiple xlsx files which I need to read. Each file has multiple sheets, I am only going to read specific sheets with "sample" in sheet names.
Then I need to read these very specific sheets and load info to a table in database.
I have the code ready to do all the above. What I need and can not figure out how to do is "How to add sheetName to the list of columns I am loading to DB".
I really appreciate if someone can help.
Thank you
Here is my sample code:
File1 <- "C:/.../File1.xlsx"
File1_read <- readxl::excel_sheets( File1)
sample_File1_read <- sheets[grepl("sample", File1_read, ignore.case = TRUE)]
File1_sheet <- map_dfr(sample_File1_read
, ~read_excel(path = File1
, col_names = c("ColA"
,"ColB" )
,sheet = .x), id = .x)
con<-DBI::dbConnect(odbc::odbc(),
Driver = 'ODBC Driver ***',
Server = "MyServer",
Database = "MyDB",
trusted_connection = 'yes'
)
schemaname <- 'dbo'
tblname_File1 <- 'tRaw_File1'
dbWriteTable(con,
Id(schema = schemaname, table = tblname_File1),
value = File1_sheet,
overwrite = T)
Summary
This text will be hidden