2

What I'm trying to do is exactly like what NSaunder's blog has done: Change a coloured cell in Excell into a category. However, I am using the readxl package whereas NSaunder's post uses the xlsx package. The xlsx package has a function called getCellStyle that returns a list of information that can be used to determine and recategorise cell colour. My question is: Is there a similar approach that can be used when using the readxl package?

Borrowing from NSaunder's blog, again, here is some example data.

M--
  • 25,431
  • 8
  • 61
  • 93
elliot
  • 1,844
  • 16
  • 45

1 Answers1

3
download.file("https://nsaunders.files.wordpress.com/2014/08/test.xlsx", "test.xlsx")

rx <- readxl::read_excel("test.xlsx")

tx <- tidyxl::xlsx_cells("test.xlsx")

rx$cat <- factor(tx$local_format_id[-1], labels = c("A", "B"))

rx
## # A tibble: 10 x 2
##        x cat  
##    <dbl> <fct>
##  1    1. A    
##  2    2. B    
##  3    3. A    
##  4    4. B    
##  5    5. A    
##  6    6. B    
##  7    7. A    
##  8    8. B    
##  9    9. A    
## 10   10. B    

That's a pretty trivial spreadsheet, though, and you'd have to make sure you're only working on the columns/rows you want to in a real world doc.

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205