0

I'm using the RubyXL gem to read background colours of cells of an xlsx spreadsheet generated in Excel. This works fine if the file is opened or saved in LibreOffice. The fill colours are all detected as white ('ffffff') on the first read if this is not done.

I have tried to use File.Open as an attempt to replicate the saving of the file before hand, but this was unsuccessful.

I access the background fill colour using cell && cell.fill_color within a loop of each cell in each row.

Currently I have tried to use RubyXL's workbook save to replicate the saving, as below.

book   = RubyXL::Parser.parse(path)
book.save
 book   = RubyXL::Parser.parse(path)
sheet  = book.worksheets[0]
sd     = sheet.sheet_data
i = 0 ; j = 0;
sheet.each { |row|
            row && row.cells.each { |cell|
                    val = cell && cell.value
                    j +=1
                    bg = cell && cell.fill_color
                    puts val.to_s + "|---|" + bg.to_s 
             }
            j = 0 
            i+=1
            }

Is there a way to re-saved the file silently (no GUI, no dialog boxes) programmatically?

  • [mcve] of what you've tried so far, please. Show us your actual code, not just a vague description of the code. – Tom Lord Nov 24 '17 at 13:45
  • Apologies, stripped code added. I have also tried using File.open(path,"w") in place of book.save and redefining Parser. – Alex Arthur Nov 24 '17 at 13:54

1 Answers1

0

Through more intense google-fu with some pointers from another forum I was able to find the soffice group of functions that allows file conversion through libreoffice.

I ran the following terminal command

soffice --headless --convert-to xlsx:"Calc MS Excel 2007 XML" file_path

which was successful in resolving the issue.