我需要一个红宝石代码来读取a列,并找到该列中最后一个填充的单元格在哪里结束。在上载的图像中,最后一个填充的数据是单元格“ A21”中的i。我需要通过红宝石代码知道这个单元地址。
我会使用Ruby stdlib WIN32OLE
。
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)
# value of the constants I picked up from
# http://techsupt.winbatch.com/ts/T000001033005F9.html
rng = wbs.range("1:1").SpecialCells(11) # value of 'xlCellTypeLastCell' is 11
rng.value # => "i"
rng.address # => "$A$21"
# to get the row and column number
row,col = rng.row,rng.column
[row,col] # => [21,1]
查看的MSDN文档SpecialCells
。
您可以xlCellTypeLastCell
从MSExcel
PC中安装的版本中获得的价值。只需ALT+F11
-> F2
->在此处搜索常量:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句