preload
Nov 29

A number of my Office automation applications are nothing more than generating status reports on a daily or weekly basis. Some of these can grow to be quite large, so its always nice to be able to highlight the new rows added to the report so folks can jump right to the new information.

Here’s how to add background highlight to an Excel row:

require 'win32ole'

file = Dir.pwd + "/" + @YourFilenameInHere
efile = getAbsolutePathName(file)
xl = WIN32OLE.new('Excel.Application')
xl.visible = true
wb = xl.Workbooks.Open("#{efile}")
ws = wb.Worksheets(1)
ws.Select
...
def highlightRow(ws, row)
   ws.Rows(row).Interior.ColorIndex = 20
   #ws.Rows($startrow+3).Interior.ColorIndex = 15 ## Grey
   #ws.Rows($startrow+7).Interior.ColorIndex = 19 ## Lt. Yellow
   #ws.Rows($startrow+8).Interior.ColorIndex = 20 ## Lt. Green
 end
...
highlightRow(ws, 7)
SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with: