Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing *cell-formatting* information from excel file into R

Tags:

r

xlsx

xls

I have been given excel files (.xlsx) where the format of the cell is relevant information which I need to capture. The key formatting of interest are (1) cell color and (2) border (left + right, full box or absent).

Is it possible to read this into R?

like image 221
Ricardo Saporta Avatar asked Jul 23 '13 17:07

Ricardo Saporta


People also ask

Which function is best for importing data directly from Excel to a data frame in R?

xlsx() function from xlsx is used.

Which syntax is used for importing Excel file in R?

The readxl package, developed by Hadley Wickham, can be used to easily import Excel files (xls|xlsx) into R without any external dependencies.

Which R package is best to use for importing Excel data?

Another method to Import Data in R from Excel is using xlsx package, which I used to access Excel files. The first row should contain variable names. It is necessary that while using read. xlsx function, we mention the sheet index or the sheet name.


1 Answers

This is a very old question but still comes up in searches so I think it is useful to point people toward the tidyxl package.

tidyxl::xlsx_cells() reads an Excel spreadsheet in as a data frame where each row represents a single cell of the spreadsheet, with its address (e.g. A1), contents, and properties.

tidyxl::xlsx_formats() returns a nested list of all the different cell formats in the Excel spreadsheet.

The local_format_id column in the data frame returned by xlsx_cells() allows you to look up the formatting information for each cell in the list returned by xlsx_formats().

More information is included in the tidyxl package vignette.

like image 121
qdread Avatar answered Oct 02 '22 15:10

qdread