web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to edit a StyleName of a cell of an export Excel file by code D365

(0) ShareShare
ReportReport
Posted on by 5

Hello to all,

I have to manipulate the Style of a cell of an Excel sheet by code D365, not Ax 2012/09.

I have to change the name of the style and set from 'Normal' (standard style), to 'Heading 1' (existing style in excel).

This is my scenario:

1.   OfficeOpenXml.ExcelWorksheets     worksheetsExcel;
2.   OfficeOpenXml.ExcelWorksheet       worksheet;

//create new sheet
3.   worksheet      =      worksheetsExcel.Add("New sheet");
4.   var cells         =      worksheet.get_Cells();

//insert header cell
5.   OfficeOpenXml.ExcelRange     cell = cells.get_Item("B8:B8");
6.   cell.set_Value("Header");                    //set the value show in the cell
7.   cell.set_styleName("Heading 1");       //set StyleName of cell

8.   cell.AutoFitColumns();

//do: extact the excel file

In the 7th line I can try the other code ->  cell.StyleName = 'Heading 1';     //but I havn't good result

In debugger I see that the default value of cell.StyleName = 'Normal' and after my change, the value remains the same.

 

Can anyone tell me if there is another way to manipulate the style of an excel cell?

NB: the code of ax 2012 don't work -> worksheet.range("B8:B8").style('Heading 1');

I have the same question (0)
  • Suggested answer
    Anup Shah MSFT Profile Picture
    Microsoft Employee on at

    If you have stylesheet defined then it uses the default. Maybe see if you can get what styles are available.

  • WillWU Profile Picture
    22,363 on at

    Hi ReKard,

    Your method works for SysExcel, in D365 SysExcel* classes have been deprecated.

    Please have a look at the following link:

    sangeethwiki.blogspot.com/.../rangeformula-in-excel-cell-through-code.html

    var column = cell.get_Worksheet().Column(cell.get_Start().get_Column());

    var columnStyle = column.get_Style();

    var columnNumberFormat = columnStyle.get_Numberformat();

    columnNumberFormat.set_Format(DateFormatString);

    columnStyle.set_HorizontalAlignment(ExcelHorizontalAlignment::Right);

    Hope this helps.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 694

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 646 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 337

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans