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, ...
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
    on at
    RE: How to edit a StyleName of a cell of an export Excel file by code D365

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

  • WillWU Profile Picture
    22,361 on at
    RE: How to edit a StyleName of a cell of an export Excel file by code D365

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,964

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 564 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans