I am using VSTO to create an Excel add-in.
My plan is to persist objects inside of excel workbooks by serializing them to strings and assigning those strings to be the values of names in the workbook.
However, when I call the API function to add the new name, I get a mysterious exception from the COM library.
More precisely, I am calling
_app.ActiveWorkbook.Names.Add(name, value, true,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
where
name = "an_object"
and
value = "TestTemplate|'Sheet1'!$A$1| 1Cube=(0,1):(1,2)| 2EntryNumber=(1,1):(2,2)| 3Description=(2,1):(3,2)| 4Group=(4,1):(5,2)| 5Repost=(3,1):(4,2)| 6Debit=(13,3):(16,4)| 7Credit=(13,2):(16,3)|Company=(6,1):(7,2)|Company Partner=(7,1):(8,2)|Time Monthly=(8,1):(9,2)|Currency=(9,1):(10,2)|Version=(10,1):(11,2)|Department=(13,0):(16,1)|Account=(13,1):(16,2)|"
A hypothesis is that the value
string does not qualify as a string that can be stored in a name (illegal characters, too long, etc) but I cannot find any documentation about what the restrictions are.
Does anyone know what is going wrong here?
The error message, in case anyone wants it, is Exception from HRESULT: 0x800A03EC
Thanks alot.