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, ...
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

I have the same question (0)
  • WillWU Profile Picture
    22,361 on at

    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

  • Raghavendra M Rao Profile Picture
    45 on at

    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

  • Verified answer
    WillWU Profile Picture
    22,361 on at

    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

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

  • WillWU Profile Picture
    22,361 on at

    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?

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
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans