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

How to add Excel cell background color file by X++ in Dynamics 365?

(0) ShareShare
ReportReport
Posted on by
0

I'm creating an Excel file by x++, in Dynamics 365 - D365, I would like to add the background color by X++.

I'm using this code

var package = new OfficeOpenXml.ExcelPackage(memoryStream)
var worksheets = package.get_Workbook().get_Worksheets();
var worksheet = worksheets.Add("SHEET");
var cells = worksheet.get_Cells();
var currentRow=1 ;

var cell = cells.get_Item(currentRow,1);
cell.set_Value("__MY__Value");

// NOT Work - compile error
//cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color::FromArgb(190, 0, 0));
//cell.Style.Fill.BackgroundColor.Rgb(Winapi::rgb2int(255,255,255));

How can I use the Background color property about Excel cell, by X++ in right way?

Thanks in advance.

I have the same question (0)
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Because you mentioned X++, you seem to be talking about Dynamics 365 for Finance and Operations. That's why I moved your thread here.

    Please tell us more about the compilation error.

  • Verified answer
    Florian Hopfner Profile Picture
    2,461 on at

    This was answered here: axapta - How to add Excel cell background color file by X++ in Dynamics 365? - Stack Overflow

    The compile error is Invalid token '('.

    It can be resolved by splitting the chain of .NET assembly calls from

    cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color::FromArgb(190, 0, 0));

    to

    ExcelColor backgroundColor = cell.Style.Fill.BackgroundColor; backgroundColor.SetColor(System.Drawing.Color::FromArgb(190, 0, 0));
  • PAX_Daniel Profile Picture
    on at

    Thanks for your reply @Martin Dráb. Below anothe user helped me about the question.

  • PAX_Daniel Profile Picture
    on at

    Thanks, it works.

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 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans