2014-03-13 40 views
0

更改Excel工作表的標籤顏色我需要改變Excel工作表的標籤顏色與特定的顏色......像這樣使用Ruby腳本enter image description here使用Ruby

回答

3

下面是使用STDLIB WIN32OLE等效的Ruby代碼:

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") 

#iterate through each worksheet and color the tab as you want 
1.upto(3).each do |i| 
    # getting the worksheet 
    wbs = wb.worksheets(i) 
    #color it 
    wbs.tab.color = 255 
end 

輸出

tab color

看文檔Tab.Color propertyWorksheet.Tab Property