Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Add SharedStringItem to SharedStringTable in OpenXML using X++. Not possible with X++?

(0) ShareShare
ReportReport
Posted on by 50

Hello all,

I am having a bit of a problem using OpenXML with X in AX 2012 R3.

Basically, I need to add strings to the SharedStringTable.
However, no matter what I do, somehow the values are never saved. This results in a corrupt xlsx file.

Anyone ever done this in X , and got it to run? (not in C#, no.)

I am getting the feeling that this simply doesn't work, for whatever reason.

    sharedStringItem = new DocumentFormat.OpenXml.Spreadsheet.SharedStringItem(
        new DocumentFormat.OpenXml.Spreadsheet.Text(_text));

    sharedStringTable.Append(sharedStringItem);
    sharedStringTable.Save();

  • Jannik Profile Picture
    50 on at
    RE: Add SharedStringItem to SharedStringTable in OpenXML using X++. Not possible with X++?

    I forgot to add: After sharedStringTable.set_InnerXml(sysString2);, I still do a SharedStringtable.Save(). Not sure if it is required, but it doesn't hurt.

  • Suggested answer
    Jannik Profile Picture
    50 on at
    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,129 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,895 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans