Pergunta

I need a ruby script to color all the sheets present in excel workbook with a fixed colour...all at once.... here i need to color this sheet with yellow color but the coloring should be only for cells with filled data.Something lik ethis

enter image description here

Foi útil?

Solução

You need to check the MSDN documentation of UsedRange Property. Also see the 56 Excel ColorIndex Colors to verify the color index of yellow. Look this also Change cell background color using VBA .

I use the Excel sheet as below :

Before running the Ruby program :

Here is the code :

require 'win32ole'

# create an instance of the Excel application object
excel = WIN32OLE.new('Excel.Application')
# make Excel visible
excel.visible = true
# open the excel from the desired path
wb=excel.workbooks.open("C:\\Users\\test.xlsx")
# get the first Worksheet
wbs= wb.worksheets(1)
# fill the column with a specific coloe
wbs.usedrange.interior.colorindex = 6

After running the above script

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top