【发布时间】:2018-03-30 00:07:07
【问题描述】:
当我尝试使用以下代码使用 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,但它抱怨工作表名称太长。我查看了this related answer 中提到的Excel 2007 specifications and limits,但我找不到它提到任何这样的限制。 (尝试手动重命名工作表表明可能存在这样的限制)
是否有限制,是硬限制还是可以通过更改 Excel 的配置来更改?
【问题讨论】:
标签: excel