5.2 Common formats

This example shows how to look up the most common formats.

path <- system.file("extdata", "worked-examples.xlsx", package = "unpivotr")
cells <-
  xlsx_cells(path, sheet = "formatting") %>%
  select(row, col, character, style_format, local_format_id, height, width)

formats <- xlsx_formats(path)

bold <- formats$local$font$bold
italic <- formats$local$font$italic
underline <- formats$local$font$underline
strikethrough <- formats$local$font$strike
font_colour <- formats$local$font$color$rgb
fill_colour <- formats$local$fill$patternFill$fgColor$rgb
font_size <- formats$local$font$size
font_name <- formats$local$font$name
border_colour <- formats$local$border$right$color$rgb
border_linetype <- formats$local$border$right$style

mutate(cells,
       bold = bold[local_format_id],
       italic = italic[local_format_id],
       underline = underline[local_format_id],
       strikethrough = strikethrough[local_format_id],
       font_colour = font_colour[local_format_id],
       font_size = font_size[local_format_id],
       font_name = font_name[local_format_id],
       fill_colour = fill_colour[local_format_id],
       border_colour = border_colour[local_format_id],
       border_linetype = border_linetype[local_format_id])
## # A tibble: 14 x 17
##      row   col character style_format local_format_id height width bold  italic underline
##    <int> <int> <chr>     <chr>                  <int>  <dbl> <dbl> <lgl> <lgl>  <chr>    
##  1     1     1 bold      Normal                     6   15    8.71 TRUE  FALSE  <NA>     
##  2     2     1 italic    Normal                     8   15    8.71 FALSE TRUE   <NA>     
##  3     3     1 underline Normal                    51   15    8.71 FALSE FALSE  single   
##  4     4     1 striketh… Normal                    52   15    8.71 FALSE FALSE  <NA>     
##  5     5     1 red text  Normal                    12   15    8.71 FALSE FALSE  <NA>     
##  6     6     1 font siz… Normal                    53   18.8  8.71 FALSE FALSE  <NA>     
##  7     7     1 font ari… Normal                    54   15    8.71 FALSE FALSE  <NA>     
##  8     8     1 yellow f… Normal                    11   15    8.71 FALSE FALSE  <NA>     
##  9     9     1 black bo… Normal                    43   15    8.71 FALSE FALSE  <NA>     
## 10    10     1 thick bo… Normal                    55   15    8.71 FALSE FALSE  <NA>     
## 11    11     1 dashed b… Normal                    56   15    8.71 FALSE FALSE  <NA>     
## 12    12     1 row heig… Normal                     1   30    8.71 FALSE FALSE  <NA>     
## 13    13     2 column w… Normal                     1   15   17.4  FALSE FALSE  <NA>     
## 14    14     1 Bad' sty… Explanatory…              57   15    8.71 FALSE FALSE  <NA>     
## # … with 7 more variables: strikethrough <lgl>, font_colour <chr>, font_size <dbl>,
## #   font_name <chr>, fill_colour <chr>, border_colour <chr>, border_linetype <chr>