Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Text Formatting of Excel cells to export data through code

(0) ShareShare
ReportReport
Posted on by 45

Hi All,

Is it possible to format an excel cell to 'Text' before exporting data to excel by x++ code?
For example, a String field value stored in AX as 000011 should be exported to excel without omitting 0's.

Below code only exports 11 to the excel cell without the 0's.
xlsWorkSheet.cells().item(row,1).value(xxxx.abc);

Any help is much appreciated.

Thank you

  • WillWU Profile Picture
    22,357 on at
    RE: Text Formatting of Excel cells to export data through code

    Hi Raghavendra,

    Actually when you export data to excel, text will remain text, numbers will remain numbers, you could open the excel with text to check.

    Did you try to change the format of the cells to text?

  • Raghavendra M Rao Profile Picture
    45 on at
    RE: Text Formatting of Excel cells to export data through code

    Thanks Will. But any idea how we could go about this when the field length is not fixed?

  • Verified answer
    WillWU Profile Picture
    22,357 on at
    RE: Text Formatting of Excel cells to export data through code

    Hi Raghavendra,

    Is the length of your field fixed?

    You could try to set the format like this in Excel.

    pastedimage1594088962264v1.png

  • Raghavendra M Rao Profile Picture
    45 on at
    RE: Text Formatting of Excel cells to export data through code

    Hi Will,

    Thanks for your response.

    Yes the field mentioned is a String field in AX. Let's say the field has data like 000123, 000011, XYZ etc.

    I have below concerns:

    1. Formatting the cell to TEXT in excel after data is exported won't bring back the 0's.

    2. I have referred to the link you shared above. It mainly focuses on number formatting and other type conversions used to extract the data needed to file.

    In my case, I don't need any type conversion as the field is STRING.

    Please help me if you know how to format the column to TEXT by x++ code before extracting data?

    xlsWorkSheet.cells().range(strFmt("H%1:H%1",row)).numberFormat("00000000000000");

    Can the above be somehow applied to TEXT formatting? I tried but to no avail.

    Thanks

  • WillWU Profile Picture
    22,357 on at
    RE: Text Formatting of Excel cells to export data through code

    Hi Raghavendra,

    What's type of the field "xxxx.abc"?

    If it is a string field, you just need to set the format of the column in Excel.

    https://community.dynamics.com/ax/b/hellodax/posts/formating-cells-when-export-to-excel-example-code

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
Martin Dráb Profile Picture

Martin Dráb 353 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 276

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 190 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans