SlideShare a Scribd company logo
1 of 15
Download to read offline
Import export Excel files
Using XLConnect
Rupak Roy
Working with excel files
R also comes with different packages to support read, write and
manipulate excel files directly without converting them in other
formats.
Some of the common packages used today are
ØXLConnect - uses rjava: a low level R to java interface
ØOpen.xlsx - uses C++ dependencies instead of rjava(java)
ØGdata - with pearl dependencies
ØReadXL, XLSX, readr packages.
Let’s learn each of them in detail.
Rupak Roy
XLCONNECT
ØXLCONNECT: is a connector for R that provides comprehensive
functionality to read, write and format Excel data.
ØImport functions include:
loadWorkbook()
readWorkbook()
readWorkbookFromFile()
ØExport functions inlude:
createSheet()
writeWorkSheet()
saveWorkbook()
Rupak Roy
XLCONNECT:loadWorkbook()
 loadWorkbook(): Loads or create a Microsoft excel workbook in R
for further manipulation.
>loadWorkbook(filename, create = FALSE, password = NULL)
Where
filename = excel workbook to be loaded
create = Specifies if the file should be created if it does not already
exist (default is FALSE)
password = Password to use when opening password protected files.
The default NULL means no password is being used. This
argument is ignored when creating new files using create = TRUE.
XLCONNECT:loadWorkbook()
#install the XLConnect package
>install.packages(“XLConnect”, dependencies = TRUE)
#load the functions from XLConnect package.
>library(XLConnect)
#load the excel file
>xlsx_data<- loadWorkbook("sample.xlsx")
>class(xlsx_data)
To know more about the features of loadWorkbook() use
>?XLConnect::loadWorkbook
Rupak Roy
XLCONNECT:readWorksheet ()
 readWorksheet(): Reads data from worksheets of a loadWorkbook.
>worksheet1<-readWorksheet(object, sheet, startCol, endRow, Header = T,….)
Where
object = name of the workbook from loadWorkbook
sheet = sheet name of the workbook
startCol = The index of the first column to read from. Defaults to 0 meaning that
the start column is determined automatically..
endRow = The index of the last row to read from. Defaults to 0 meaning that the
end row is determined automatically.
startRow = The index of the first row to read from. Defaults to 0 meaning that
the start row is determined automatically.
endCol = The index of the last column to read from. Defaults to 0 meaning that
the end column is determined automatically..
XLCONNECT:readWorksheet()
#install the XLConnect package
>install.packages(“XLConnect”, dependencies = TRUE)
#load the functions from XLConnect package.
>library(XLConnect)
#Read the 1st excel sheet from xlsx_data R object i.e. sample.xlsx file.
>excel_data<- readWorksheet (xlsx_data, “store”, header = T)
>View(excel_data)
#Read the 2nd excel sheet from xlsx_data R object i.e. sample.xlsx file.
>excel_data2<- readWorksheet (xlsx_data,“bike_sharing_program”, endRow = 10,
startCol =3, header = T)
>View(excel_data2)
To know more about the features of loadWorkbook() use
>?XLConnect::readWorksheet
XLCONNECT:readWorksheetFromFile()
 readWorksheetFromFile(): Reads data from a worksheet directly from a
physical excel file.
>worksheet3<-readWorksheetFromFile(file, sheet, startCol, endRow, Header =
T ……. Same Arguments passed to readWorksheet)
Where
file = name of the excel file to be read
sheet = sheet name of workbook
startCol = The index of the first column to read from. Defaults to 0 meaning that
the start column is determined automatically..
endRow = The index of the last row to read from. Defaults to 0 meaning that the
end row is determined automatically.
startRow = The index of the first row to read from. Defaults to 0 meaning that
the start row is determined automatically.
endCol = The index of the last column to read from. Defaults to 0 meaning that
the end column is determined automatically..
XLCONNECT:readWorksheetFromFile()
#install the XLConnect package
>install.packages(“XLConnect”, dependencies = TRUE)
#load the functions from XLConnect package.
>library(XLConnect)
#Read the excel sheet directly from an excel file
>excel_data3<- readWorksheetFromFile (“sample.xlsx”, “store”, header = T)
>View(excel_data3)
XLConnect::readWorksheetFromFile - the only difference between
readWorksheet and readWorksheetFromFile is that in readWorksheet() the
excel file have to be first loaded in R directory using loadWorkbook() in order
to view the data but in readWorksheetFromFile() it reads the excel sheet
directly from a physical file.
To know more about the features of readWorksheetFromFile() use
>?XLConnect::readWorksheetFromFile
XLCONNECT:createSheet()
 createSheet(): Creates new worksheet in a workbook loaded via
loadWorkbook()
>createSheet (object, name)
Where
object = name of the workbook to use
name = name of the sheet to create
Rupak Roy
XLCONNECT:createSheet()
#install the XLConnect package
>install.packages(“XLConnect”, dependencies = TRUE)
#load the functions from XLConnect package.
>library(XLConnect)
#Create the a new empty excel sheet in the workbook
>createSheet(xlsx_data, “new_sheet”)
XLConnect::createSheet() - Creates a worksheet with the specified name if it
does not already exist. The naming of worksheets needs to be in line with
Excel's convention, otherwise an exception will be thrown. For example,
worksheet names cannot be longer than 31 characters.
To know more about the features of createSheet() use
>?XLConnect::createSheet
Rupak Roy
XLCONNECT:writeWorksheet()
 writeWorksheet(): Creates new worksheet in a workbook loaded via
loadWorkbook()
>writeWorksheet (object, data, sheet=“sheet_name”)
Where
object = name of the worksheet to read
data = data to be written
sheet = The name or index of the sheet to write to
startRow = Index of the first row to write to. The default is startRow = 1
startCol = Index of the first column to write to. The default is startCol = 1
header = Specifies if the column names should be written. Default (TRUE).
XLCONNECT:writeWorksheet()
#install the XLConnect package
>install.packages(“XLConnect”, dependencies = TRUE)
#load the functions from XLConnect package.
>library(XLConnect)
#Write/Copy a workbook sheet directly to a new workbook sheet
>writeWorkSheet(xlsx_data, bike_sharing_program, “new_sheet”)
XLConnect::writeWorksheet() - Writes data to the worksheet specified
by sheet. Data here is assumed to be a data.frame and is coerced to one if this
is not already the case. StartRow and startCol define the top left corner of the
data region to be written.
To know more about the features of writeWorksheet() use
>?XLConnect::writeWorksheet
Rupak Roy
XLCONNECT:saveWorkbook()
 saveWorkbook(): Saves a workbook to the corresponding Excel file. This
method actually writes the workbook object to disk.
>saveWorkbook (object,file)
Where
object = the workbook to save
file = The file to which it will save the workbook ("save as")
>saveWorkbook(xlsx, “document1.xlsx”);
To know more about the saveWorkbook function use
?XLConnect::saveWorkbook
Rupak Roy
Next:
Troubleshooting XLConnect
Import export Excel files
Rupak Roy

More Related Content

What's hot

Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentArun Sial
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query OptimizationBrian Gallagher
 
R Programming: Transform/Reshape Data In R
R Programming: Transform/Reshape Data In RR Programming: Transform/Reshape Data In R
R Programming: Transform/Reshape Data In RRsquared Academy
 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions setMohd Tousif
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlAimal Miakhel
 
MS Excel Pivot Table Reports & Charts
MS Excel Pivot Table Reports & ChartsMS Excel Pivot Table Reports & Charts
MS Excel Pivot Table Reports & Chartsdnbakhan
 
Aggregate Function - Database
Aggregate Function - DatabaseAggregate Function - Database
Aggregate Function - DatabaseShahadat153031
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)Ishucs
 

What's hot (20)

1.2 sql create and drop table
1.2 sql create and drop table1.2 sql create and drop table
1.2 sql create and drop table
 
Sql join
Sql  joinSql  join
Sql join
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab Assignment
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
R Programming: Transform/Reshape Data In R
R Programming: Transform/Reshape Data In RR Programming: Transform/Reshape Data In R
R Programming: Transform/Reshape Data In R
 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions set
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sql
 
Ppt on pivot table
Ppt on pivot tablePpt on pivot table
Ppt on pivot table
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
SQL report
SQL reportSQL report
SQL report
 
MS Excel Pivot Table Reports & Charts
MS Excel Pivot Table Reports & ChartsMS Excel Pivot Table Reports & Charts
MS Excel Pivot Table Reports & Charts
 
Sql joins
Sql joinsSql joins
Sql joins
 
Aggregate Function - Database
Aggregate Function - DatabaseAggregate Function - Database
Aggregate Function - Database
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
MYSQL
MYSQLMYSQL
MYSQL
 

Similar to Import and Export Excel files using XLConnect in R Studio

Import and Export Excel Data using openxlsx in R Studio
Import and Export Excel Data using openxlsx in R StudioImport and Export Excel Data using openxlsx in R Studio
Import and Export Excel Data using openxlsx in R StudioRupak Roy
 
In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfaromalcom
 
How to Read Excel Files in Java (1).pdf
How to Read Excel Files in Java (1).pdfHow to Read Excel Files in Java (1).pdf
How to Read Excel Files in Java (1).pdfSudhanshiBakre1
 
Maxbox starter19
Maxbox starter19Maxbox starter19
Maxbox starter19Max Kleiner
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generationPaul Graham
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationProf Ansari
 
latex-workshop Dr: Mohamed A. Alrshah
latex-workshop Dr: Mohamed A. Alrshahlatex-workshop Dr: Mohamed A. Alrshah
latex-workshop Dr: Mohamed A. AlrshahAbdulazim N.Elaati
 
Yacc topic beyond syllabus
Yacc   topic beyond syllabusYacc   topic beyond syllabus
Yacc topic beyond syllabusJK Knowledge
 
Exploiting JXL using Selenium
Exploiting JXL using SeleniumExploiting JXL using Selenium
Exploiting JXL using SeleniumOSSCube
 
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docxCSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docxfaithxdunce63732
 

Similar to Import and Export Excel files using XLConnect in R Studio (20)

Import and Export Excel Data using openxlsx in R Studio
Import and Export Excel Data using openxlsx in R StudioImport and Export Excel Data using openxlsx in R Studio
Import and Export Excel Data using openxlsx in R Studio
 
Python openpyxl
Python openpyxlPython openpyxl
Python openpyxl
 
In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdf
 
How to Read Excel Files in Java (1).pdf
How to Read Excel Files in Java (1).pdfHow to Read Excel Files in Java (1).pdf
How to Read Excel Files in Java (1).pdf
 
LEX & YACC
LEX & YACCLEX & YACC
LEX & YACC
 
Maxbox starter19
Maxbox starter19Maxbox starter19
Maxbox starter19
 
Linker scripts
Linker scriptsLinker scripts
Linker scripts
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Introduction to Latex
Introduction to LatexIntroduction to Latex
Introduction to Latex
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generation
 
Matlab Manual
Matlab ManualMatlab Manual
Matlab Manual
 
Advance Mobile Application Development class 03
Advance Mobile Application Development class 03Advance Mobile Application Development class 03
Advance Mobile Application Development class 03
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
 
latex-workshop Dr: Mohamed A. Alrshah
latex-workshop Dr: Mohamed A. Alrshahlatex-workshop Dr: Mohamed A. Alrshah
latex-workshop Dr: Mohamed A. Alrshah
 
Yacc topic beyond syllabus
Yacc   topic beyond syllabusYacc   topic beyond syllabus
Yacc topic beyond syllabus
 
Exploiting JXL using Selenium
Exploiting JXL using SeleniumExploiting JXL using Selenium
Exploiting JXL using Selenium
 
Sql loader good example
Sql loader good exampleSql loader good example
Sql loader good example
 
Oracle sql loader utility
Oracle sql loader utilityOracle sql loader utility
Oracle sql loader utility
 
R with excel
R with excelR with excel
R with excel
 
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docxCSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
 

More from Rupak Roy

Hierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLPHierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLPRupak Roy
 
Clustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLPClustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLPRupak Roy
 
Network Analysis - NLP
Network Analysis  - NLPNetwork Analysis  - NLP
Network Analysis - NLPRupak Roy
 
Topic Modeling - NLP
Topic Modeling - NLPTopic Modeling - NLP
Topic Modeling - NLPRupak Roy
 
Sentiment Analysis Practical Steps
Sentiment Analysis Practical StepsSentiment Analysis Practical Steps
Sentiment Analysis Practical StepsRupak Roy
 
NLP - Sentiment Analysis
NLP - Sentiment AnalysisNLP - Sentiment Analysis
NLP - Sentiment AnalysisRupak Roy
 
Text Mining using Regular Expressions
Text Mining using Regular ExpressionsText Mining using Regular Expressions
Text Mining using Regular ExpressionsRupak Roy
 
Introduction to Text Mining
Introduction to Text Mining Introduction to Text Mining
Introduction to Text Mining Rupak Roy
 
Apache Hbase Architecture
Apache Hbase ArchitectureApache Hbase Architecture
Apache Hbase ArchitectureRupak Roy
 
Introduction to Hbase
Introduction to Hbase Introduction to Hbase
Introduction to Hbase Rupak Roy
 
Apache Hive Table Partition and HQL
Apache Hive Table Partition and HQLApache Hive Table Partition and HQL
Apache Hive Table Partition and HQLRupak Roy
 
Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export Rupak Roy
 
Introductive to Hive
Introductive to Hive Introductive to Hive
Introductive to Hive Rupak Roy
 
Scoop Job, import and export to RDBMS
Scoop Job, import and export to RDBMSScoop Job, import and export to RDBMS
Scoop Job, import and export to RDBMSRupak Roy
 
Apache Scoop - Import with Append mode and Last Modified mode
Apache Scoop - Import with Append mode and Last Modified mode Apache Scoop - Import with Append mode and Last Modified mode
Apache Scoop - Import with Append mode and Last Modified mode Rupak Roy
 
Introduction to scoop and its functions
Introduction to scoop and its functionsIntroduction to scoop and its functions
Introduction to scoop and its functionsRupak Roy
 
Introduction to Flume
Introduction to FlumeIntroduction to Flume
Introduction to FlumeRupak Roy
 
Apache Pig Relational Operators - II
Apache Pig Relational Operators - II Apache Pig Relational Operators - II
Apache Pig Relational Operators - II Rupak Roy
 
Passing Parameters using File and Command Line
Passing Parameters using File and Command LinePassing Parameters using File and Command Line
Passing Parameters using File and Command LineRupak Roy
 
Apache PIG Relational Operations
Apache PIG Relational Operations Apache PIG Relational Operations
Apache PIG Relational Operations Rupak Roy
 

More from Rupak Roy (20)

Hierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLPHierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLP
 
Clustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLPClustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLP
 
Network Analysis - NLP
Network Analysis  - NLPNetwork Analysis  - NLP
Network Analysis - NLP
 
Topic Modeling - NLP
Topic Modeling - NLPTopic Modeling - NLP
Topic Modeling - NLP
 
Sentiment Analysis Practical Steps
Sentiment Analysis Practical StepsSentiment Analysis Practical Steps
Sentiment Analysis Practical Steps
 
NLP - Sentiment Analysis
NLP - Sentiment AnalysisNLP - Sentiment Analysis
NLP - Sentiment Analysis
 
Text Mining using Regular Expressions
Text Mining using Regular ExpressionsText Mining using Regular Expressions
Text Mining using Regular Expressions
 
Introduction to Text Mining
Introduction to Text Mining Introduction to Text Mining
Introduction to Text Mining
 
Apache Hbase Architecture
Apache Hbase ArchitectureApache Hbase Architecture
Apache Hbase Architecture
 
Introduction to Hbase
Introduction to Hbase Introduction to Hbase
Introduction to Hbase
 
Apache Hive Table Partition and HQL
Apache Hive Table Partition and HQLApache Hive Table Partition and HQL
Apache Hive Table Partition and HQL
 
Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export
 
Introductive to Hive
Introductive to Hive Introductive to Hive
Introductive to Hive
 
Scoop Job, import and export to RDBMS
Scoop Job, import and export to RDBMSScoop Job, import and export to RDBMS
Scoop Job, import and export to RDBMS
 
Apache Scoop - Import with Append mode and Last Modified mode
Apache Scoop - Import with Append mode and Last Modified mode Apache Scoop - Import with Append mode and Last Modified mode
Apache Scoop - Import with Append mode and Last Modified mode
 
Introduction to scoop and its functions
Introduction to scoop and its functionsIntroduction to scoop and its functions
Introduction to scoop and its functions
 
Introduction to Flume
Introduction to FlumeIntroduction to Flume
Introduction to Flume
 
Apache Pig Relational Operators - II
Apache Pig Relational Operators - II Apache Pig Relational Operators - II
Apache Pig Relational Operators - II
 
Passing Parameters using File and Command Line
Passing Parameters using File and Command LinePassing Parameters using File and Command Line
Passing Parameters using File and Command Line
 
Apache PIG Relational Operations
Apache PIG Relational Operations Apache PIG Relational Operations
Apache PIG Relational Operations
 

Recently uploaded

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 

Recently uploaded (20)

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 

Import and Export Excel files using XLConnect in R Studio

  • 1. Import export Excel files Using XLConnect Rupak Roy
  • 2. Working with excel files R also comes with different packages to support read, write and manipulate excel files directly without converting them in other formats. Some of the common packages used today are ØXLConnect - uses rjava: a low level R to java interface ØOpen.xlsx - uses C++ dependencies instead of rjava(java) ØGdata - with pearl dependencies ØReadXL, XLSX, readr packages. Let’s learn each of them in detail. Rupak Roy
  • 3. XLCONNECT ØXLCONNECT: is a connector for R that provides comprehensive functionality to read, write and format Excel data. ØImport functions include: loadWorkbook() readWorkbook() readWorkbookFromFile() ØExport functions inlude: createSheet() writeWorkSheet() saveWorkbook() Rupak Roy
  • 4. XLCONNECT:loadWorkbook()  loadWorkbook(): Loads or create a Microsoft excel workbook in R for further manipulation. >loadWorkbook(filename, create = FALSE, password = NULL) Where filename = excel workbook to be loaded create = Specifies if the file should be created if it does not already exist (default is FALSE) password = Password to use when opening password protected files. The default NULL means no password is being used. This argument is ignored when creating new files using create = TRUE.
  • 5. XLCONNECT:loadWorkbook() #install the XLConnect package >install.packages(“XLConnect”, dependencies = TRUE) #load the functions from XLConnect package. >library(XLConnect) #load the excel file >xlsx_data<- loadWorkbook("sample.xlsx") >class(xlsx_data) To know more about the features of loadWorkbook() use >?XLConnect::loadWorkbook Rupak Roy
  • 6. XLCONNECT:readWorksheet ()  readWorksheet(): Reads data from worksheets of a loadWorkbook. >worksheet1<-readWorksheet(object, sheet, startCol, endRow, Header = T,….) Where object = name of the workbook from loadWorkbook sheet = sheet name of the workbook startCol = The index of the first column to read from. Defaults to 0 meaning that the start column is determined automatically.. endRow = The index of the last row to read from. Defaults to 0 meaning that the end row is determined automatically. startRow = The index of the first row to read from. Defaults to 0 meaning that the start row is determined automatically. endCol = The index of the last column to read from. Defaults to 0 meaning that the end column is determined automatically..
  • 7. XLCONNECT:readWorksheet() #install the XLConnect package >install.packages(“XLConnect”, dependencies = TRUE) #load the functions from XLConnect package. >library(XLConnect) #Read the 1st excel sheet from xlsx_data R object i.e. sample.xlsx file. >excel_data<- readWorksheet (xlsx_data, “store”, header = T) >View(excel_data) #Read the 2nd excel sheet from xlsx_data R object i.e. sample.xlsx file. >excel_data2<- readWorksheet (xlsx_data,“bike_sharing_program”, endRow = 10, startCol =3, header = T) >View(excel_data2) To know more about the features of loadWorkbook() use >?XLConnect::readWorksheet
  • 8. XLCONNECT:readWorksheetFromFile()  readWorksheetFromFile(): Reads data from a worksheet directly from a physical excel file. >worksheet3<-readWorksheetFromFile(file, sheet, startCol, endRow, Header = T ……. Same Arguments passed to readWorksheet) Where file = name of the excel file to be read sheet = sheet name of workbook startCol = The index of the first column to read from. Defaults to 0 meaning that the start column is determined automatically.. endRow = The index of the last row to read from. Defaults to 0 meaning that the end row is determined automatically. startRow = The index of the first row to read from. Defaults to 0 meaning that the start row is determined automatically. endCol = The index of the last column to read from. Defaults to 0 meaning that the end column is determined automatically..
  • 9. XLCONNECT:readWorksheetFromFile() #install the XLConnect package >install.packages(“XLConnect”, dependencies = TRUE) #load the functions from XLConnect package. >library(XLConnect) #Read the excel sheet directly from an excel file >excel_data3<- readWorksheetFromFile (“sample.xlsx”, “store”, header = T) >View(excel_data3) XLConnect::readWorksheetFromFile - the only difference between readWorksheet and readWorksheetFromFile is that in readWorksheet() the excel file have to be first loaded in R directory using loadWorkbook() in order to view the data but in readWorksheetFromFile() it reads the excel sheet directly from a physical file. To know more about the features of readWorksheetFromFile() use >?XLConnect::readWorksheetFromFile
  • 10. XLCONNECT:createSheet()  createSheet(): Creates new worksheet in a workbook loaded via loadWorkbook() >createSheet (object, name) Where object = name of the workbook to use name = name of the sheet to create Rupak Roy
  • 11. XLCONNECT:createSheet() #install the XLConnect package >install.packages(“XLConnect”, dependencies = TRUE) #load the functions from XLConnect package. >library(XLConnect) #Create the a new empty excel sheet in the workbook >createSheet(xlsx_data, “new_sheet”) XLConnect::createSheet() - Creates a worksheet with the specified name if it does not already exist. The naming of worksheets needs to be in line with Excel's convention, otherwise an exception will be thrown. For example, worksheet names cannot be longer than 31 characters. To know more about the features of createSheet() use >?XLConnect::createSheet Rupak Roy
  • 12. XLCONNECT:writeWorksheet()  writeWorksheet(): Creates new worksheet in a workbook loaded via loadWorkbook() >writeWorksheet (object, data, sheet=“sheet_name”) Where object = name of the worksheet to read data = data to be written sheet = The name or index of the sheet to write to startRow = Index of the first row to write to. The default is startRow = 1 startCol = Index of the first column to write to. The default is startCol = 1 header = Specifies if the column names should be written. Default (TRUE).
  • 13. XLCONNECT:writeWorksheet() #install the XLConnect package >install.packages(“XLConnect”, dependencies = TRUE) #load the functions from XLConnect package. >library(XLConnect) #Write/Copy a workbook sheet directly to a new workbook sheet >writeWorkSheet(xlsx_data, bike_sharing_program, “new_sheet”) XLConnect::writeWorksheet() - Writes data to the worksheet specified by sheet. Data here is assumed to be a data.frame and is coerced to one if this is not already the case. StartRow and startCol define the top left corner of the data region to be written. To know more about the features of writeWorksheet() use >?XLConnect::writeWorksheet Rupak Roy
  • 14. XLCONNECT:saveWorkbook()  saveWorkbook(): Saves a workbook to the corresponding Excel file. This method actually writes the workbook object to disk. >saveWorkbook (object,file) Where object = the workbook to save file = The file to which it will save the workbook ("save as") >saveWorkbook(xlsx, “document1.xlsx”); To know more about the saveWorkbook function use ?XLConnect::saveWorkbook Rupak Roy