Wednesday, October 17, 2018

Range/Formula/Style/Format in Excel cell through Code using OfficeOpenXML Dynamics 365 finance and operation


//Dynamics 365 for finance and operation

//Setting Up range for collection of cells to do style/format
            OfficeOpenXml.ExcelRange cellRange;
            cellRange = Worksheet.get_Cells().get_Item("A4:D5");

            Style.ExcelFont lisStyle = cell.Style.Font;
            lisStyle.Bold = true;
            lisStyle.Size = 12;
            lisStyle.UnderLineType = true;

//Setting Up formula in excel cell
           OfficeOpenXml.ExcelRange  cellRange;
           cellRange =  Worksheet.get_Cells().get_Item(currentRow, 4);
           cellRange.formula = "=SUM(D2:D10)";

//Setting Up format in excel cell
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);


2 comments:

  1. Hi,

    when i setup the formula it gives the value when i click "enable editing in the excel".

    and for number formatting for real can i specify the format such as "0.00" by repalcing the dateformatString..

    Thanks in advance

    ReplyDelete
  2. Hi,

    Mean to say, not able to see formula on EXCEL. Beside its showing value alone?.

    Number formatting for real - Yes

    Thanks

    ReplyDelete

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...