RE: Add SharedStringItem to SharedStringTable in OpenXML using X++. Not possible with X++?
I may have found the/a solution, which seems to work for me. It may not be perfect, but it works:
Sorry about the variables. The names are not good, but I tend to get lazy when trying a solution. I clean it up later. For now, what I do is get the XML of what is represented by sharedStringTable, i.e. what is inside.
The XML contains all the entries in the SharedStringTable so far. So I used the info() Method to find what a single entry looks like.
With this information, I attach a new XML element to the existing XML-Code. And that is saved again.
text1Local = strFmt(
"%1",
_text);
sysString1 = sharedStringTable.get_InnerXml();
text2Local = sysString1;
text1Local = strFmt("%1%2",
text2Local,
text1Local);
sysString2 = text1Local;
sharedStringTable.set_InnerXml(sysString2);
What's more is that it may also be necessary to increment the UniqueCount property of the XML, so it matches the entries. But I found that this must eventually not be correct. Who knows. The Excel file (xlsx) opens perfectly with my written values in either case. Need to make this dynamic, 57 is just static because I only added two SharedStrings for my testing purposes.
cnt = 57;
uniqueCount2 = System.Convert::ToUInt32(cnt);
uniqueCount = new DocumentFormat.OpenXml.UInt32Value();
uniqueCount.set_Value(uniqueCount2);
sharedStringTable.set_UniqueCount(uniqueCount);
Maybe it helps somebody.