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 :
Microsoft Dynamics AX (Archived)

Change Background Color of Excel Cell in X++

(0) ShareShare
ReportReport
Posted on by

Hello all,

i have this Job where i created Excel Template.

i already made the texts and data needed.

but i need to change the background color of some cell or column. (it is where the user will input data)

i can change font style, etc. but i can't seem to find the code for change background color.

please help me. thanks.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Divya Lakshmi Profile Picture
    745 on at

    Hi,

     Try this out...

     Declarations:

     SysExcelCell    cell;

     COM               comg,comfont;

      void reportHeaderColor()

      {

          comg = cell.comObject();

          comfont=comg.font();

          comfont.bold(2);

          comg.style("Note");

          comfont.color(WINapi::RGB2int(251,0,0));

      }

  • Community Member Profile Picture
    on at

    thanks Divya, it works,

    i know the question in the topic is finished.

    but can i ask also how to make a text center?

    thanks.

  • Suggested answer
    Divya Lakshmi Profile Picture
    745 on at

    Hi,

    Thanks for the reply.

    Try this out for alignments....

    Declaration:

       SysExcelStyle        style;  

    Code:

       // Set orientation

       style.comObject().orientation(90);

       // distribute text

       style.horizontalalignment(-4117);

      // center text

      style.horizontalalignment(-4108);

      // right align text

      style.horizontalalignment(-4152);

      // set indent level

      style.comObject().indentlevel(5);

      // wrap text

      style.comObject().wraptext(true);

  • Community Member Profile Picture
    on at

    Thank you for sharing this solution, but i still need more details if you can help me. So how can i change background with Gray color, because i didn't understand the meaning of style("Note")

  • Divya Lakshmi Profile Picture
    745 on at

    Hi,

    Could you please raise this as a new question please?

    So that I can answer you there and in return you can verify answer if its right.

    I have answer on hand for you .but please raise it as I said above.

    Regards,

    Divya Lakshmi.J

  • Community Member Profile Picture
    on at

    Hi, thank you for replying! i fixed the problem using SysExcelInterior. Thank you!

  • Divya Lakshmi Profile Picture
    745 on at

    Hi,

      Thank you. I'm expecting you to post your finding with explanation on blog for future use.

    Regards,

    Divya Lakshmi.J

  • Community Member Profile Picture
    on at

    Hi, with pleasure

    this is the solution:

       #define.STYLE_BOLD('AX_Bold')   
       SysExcelInterior        interior;
       SysExcelStyles      styles;
       SysExcelStyle       style; 
       SysExcelWorksheets  worksheets;
       SysExcelWorksheet   worksheet;        
    
        styles = workBook.styles();
        style = styles.add(#STYLE_BOLD);
        worksheet.columns().item(i);
        interior = style.interior();
        interior.color(WinApi::RGB2int(207, 201, 188));
        worksheet.columns().item(6).style(#STYLE_BOLD);
    


  • Gokul.S Profile Picture
    2 on at

    what is that "i" in    worksheet.columns().item(i);

    please share the entire 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

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans