当我尝试使用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
Run Code Online (Sandbox Code Playgroud)
我得到以下内容:
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>'
Run Code Online (Sandbox Code Playgroud)
版本12.0表明我运行Excel 2007,但它抱怨工作表名称太长.我看了一下Excel 2007中规范和限制中提到的这个相关的答案,我找不到它提及任何这样的限制.(尝试手动重命名工作表表明可能存在这样的限制)
是否有限制,而且它是一个硬性限制或者是一个可以通过改变Excel的配置是否会改变?
mjf*_*tes 101
文件格式允许最多255个字符的工作表名称,但如果Excel UI不要求超过31个字符,请不要尝试超过31个.应用程序充满了奇怪的未记录的限制和怪癖,并提供它的文件在规范范围内但不在测试人员测试过的范围内通常会导致非常奇怪的行为.(个人最喜欢的例子:使用Excel 4.0字节码作为if()函数,在具有Excel 97样式字符串表的文件中,禁用Excel 97中粗体的工具栏按钮.)