當我嘗試使用紅寶石設置一個稍長的工作表名稱,並用下面的代碼WIN32OLE:Excel工作表名稱長度是否有限制?
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的配置改變?
https://excelribbon.tips.net/T013175_Using_Very_Long_Worksheet_Tab_Names.html可能會引起興趣,但不是最近的。 – pnuts 2018-02-25 17:21:04