Search code examples
rr-xlsx

how to get cell fill colors


I am trying to get the string value of a cell from a workbook, using xlsx package. Using the getFillBackgroundColorColor() and getFillForegroundColorColor() methods I get back Java-Object gibberish, like "Java-Object{org.apache.poi.hssf.usermodel.HSSFPalette$CustomColor@7ec7ffd3}". Does 7ec7ffd3 hide the hex values of the color? Any ideas how I extract the color name? Thanks.


Solution

  • I think those numbers are just an object identifier. What you need is the getRgb method.

    Added steps This is how I set things up before steps in the original answer:

    wb = loadWorkbook(file="Test.xlsx")
    SheetList = getSheets(wb)
    Rows = getRows(SheetList[[1]])
    Cells = getCells(Rows)
    

    Original Answer

    Style = getCellStyle(Cells[["2.1"]])
    Style$getFillForegroundColorColor()$getRgb()
    [1] 00 b0 50
    as.character(Style$getFillForegroundColorColor()$getRgb())
    [1] "00" "b0" "50"