web
You’re offline. This is a read only version of the page.
close
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();

I have the same question (0)
  • Suggested answer
    Jannik Profile Picture
    50 on at

    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.

  • Jannik Profile Picture
    50 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 467 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans