I need to convert multiple .xlsx file into csv files but the contents of the original .xlsx is modified during conversion.
For example, the starting excel file will look like this
A B C D
1 Foo
2
3 Foo
After conversion, the .csv file will contain this
A B C D
1 X1 X2 X3 X4
2 Foo NA NA NA
3 NA NA NA NA
4 Na Na NA Foo
How can I convert the .xlsx without any changes made to the contents? I've also read that read.xlsx may have issues with dates. Is there a simple way to convert .xlsx to csv?
Here's the code that I'm using.
PathOut<-"C:/Users/Desktop/New folder/"
require(openxlsx)
file_list<-list.files(path = PathOut, pattern='\\.xlsx$')
x=0
for (file in file_list) {
setwd("C:/Users/Desktop/New folder/")
x<-x+1
file.xl <- read.xlsx(file,skipEmptyRows = FALSE,skipEmptyCols = FALSE,colNames = FALSE,rowNames = FALSE)
newname<-paste0(tools::file_path_sans_ext(file),'_',LETTERS[x],'.csv')
write.csv(file.xl, paste(PathOut,newname),row.names = FALSE)
}
Thank you