2
votes

How do I read excel files with .xlsx extension in programming language? I have tried installing package but after I run library(xlsx) I get -

Error: package or namespace load failed for ‘xlsx’: .onLoad failed in loadNamespace() for 'rJava', details: call: fun(libname, pkgname) error: JAVA_HOME cannot be determined from the Registry In addition: Warning message: package ‘xlsx’ was built under R version 3.5.3 ".

Further, how can I convert .xlsx file to .csv file?

2
The answers given about readxl are good. The xlsx package also provides capability to write Excel files, which involves much more than you require. It also depends on rJava and having Java's JDK installed on your system. See cran.r-project.org/web/packages/xlsx/readme/README.html, under "Common Problems".Brian Stamper

2 Answers

4
votes

try readxl package:

library(readxl)
read_excel("your_file.xlsx", sheet = yourSheet_number)

You can convert .xlsx to .csv by reading .xlsx and then saving with readr package:

library(readr)
write_csv(yourFile, "yourDirectory")
3
votes

This code should help:

library(readxl)
dataset <- read_xlsx("myfile.xlsx")
write.csv(dataset,"mycsv.csv")