Search code examples
ruby-on-railsrubyxl

RubyXL returns HEX Cell code while read a cell


I am trying read a book with RubyXL, but always return me a Hex code like: #<RubyXL::Cell:0x007f8b597c4390>

workbook = RubyXL::Parser.parse("issues.xlsx")
        worksheet = workbook[0]
        worksheet.extract_data  # Produces a simple rectangular array that consists only of cell values (rather than the Cell objects)
        worksheet = workbook[0]
        #worksheet.sheet_data[0][0] # Returns cell A1 in the worksheet
        logger.info worksheet[17][4]

Is necessary return the string text in the cell?


Solution

  • What you are doing is getting the actual cell not it's value. To get the cell value, do this:

    logger.info worksheet[17][4].value
    

    You might need the cell for other information such as the cell styling:

    logger.info worksheet[17][4].font_name
    logger.info worksheet[17][4].font_color
    logger.info worksheet[17][4].font_size
    logger.info worksheet[17][4].border_top
    logger.info worksheet[17][4].is_bolded
    logger.info worksheet[17][4].is_italicized
    logger.info worksheet[17][4].is_struckthrough
    logger.info worksheet[17][4].is_underlined