【问题标题】:Change the tab color of excel sheets using ruby使用 ruby​​ 更改 Excel 工作表的选项卡颜色
【发布时间】:2014-03-13 17:08:00
【问题描述】:

我需要用特定颜色更改 excel 工作表的标签颜色...像这样使用 ruby​​ scripting

【问题讨论】:

    标签: ruby windows excel


    【解决方案1】:

    这是使用 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 propertyWorksheet.Tab Property 的文档。

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 2015-07-11
      • 1970-01-01
      • 2020-04-19
      • 1970-01-01
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多