Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

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

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');

  • WillWU Profile Picture
    WillWU 22,350 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.

  • Suggested answer
    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans