web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • PAX_Daniel Profile Picture
    on at
    RE: How to add Excel cell background color file by X++ in Dynamics 365?

    Thanks, it works.

  • PAX_Daniel Profile Picture
    on at
    RE: How to add Excel cell background color file by X++ in Dynamics 365?

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

  • Verified answer
    Florian Hopfner Profile Picture
    2,451 on at
    RE: How to add Excel cell background color file by X++ in Dynamics 365?

    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));
  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: How to add Excel cell background color file by X++ in Dynamics 365?

    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.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 745 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 597 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans