当我尝试通过以下代码使用ruby和win32ole设置冗长的工作表名称时:
require "win32ole"
excel = WIN32OLE.new('Excel.Application')
excel.Visible = 1
puts excel.version
workbook = excel.Workbooks.Add
worksheet1 = workbook.Worksheets.Add
worksheet1.Name = "Pseudopseudohypoparathyroidism" #Length 30, fine
worksheet2 = workbook.Worksheets.Add
worksheet2.Name = "Supercalifragilisticexpialidocious" #Length 34, not fine
我得到以下内容:
12.0
-:9:in `method_missing': (in setting property `Name': ) (WIN32OLERuntimeError)
OLE error code:800A03EC in Microsoft Office Excel
You typed an invalid name for a sheet or chart. Make sure that:
The name that you type does not exceed 31 characters.
The name does not contain any of the following characters: : \ / ? * [ or ]
You did not leave the name blank.
HRESULT error code:0x80020009
Exception occurred.
from -:9:in `<main>'
版本12.0表示我正在运行Excel 2007,但是它抱怨工作表名称太长。我查看了此相关答案中提到的Excel 2007规范和限制,但找不到提及任何此类限制的信息。(尝试手动重命名工作表表明可能存在这种限制,但是)
有限制吗,它是一项硬性限制,还是可以通过更改Excel的配置来更改的限制?