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 merge cells in Excel through x++ code?

(0) ShareShare
ReportReport
Posted on by 45

Hi,

We have a requirement to generate an Excel report in d365, in report we have to merge multiple cells into one, Quick responses are appreciated.

Thanks in Advance.

I have the same question (0)
  • huijij Profile Picture
    19,811 on at
    RE: How to merge cells in Excel through x++ code?

    You can try it to see if it can help:

    Worksheet.get_Cells().get_Item(1, 3);

  • Sowmya170106@gmail.com Profile Picture
    45 on at
    RE: How to merge cells in Excel through x++ code?

    Hi Judy,

    Thanks for the Response,

    I have tried with below code but getting errors as i.e., (the name SysExcelRange does not denote a class or a table or an ExtendedDataType),

    (Method 'cells()' is not found on type 'OfficeOpenXml.ExcelWorksheet').

    #define.xlCenter(-4108)
            DocuFileSaveResult saveResult =
            DocuFileSave::promptForSaveLocation("@ApplicationPlatform:OfficeDefaultWorkbookFileName","xlsx", null, "excel create and export");
            if (saveResult&& saveResult.parmAction() != DocuFileSaveAction::Cancel)
            {
                saveResult.parmOpenParameters('web=1');
                saveResult.parmOpenInNewWindow(false);
                System.IO.Stream
                    workbookStream = new System.IO.MemoryStream();
                System.IO.MemoryStream
                    memoryStream = new System.IO.MemoryStream();
    
                using(var package = new OfficeOpenXml.ExcelPackage(memoryStream))
                {
                    var worksheets = package.get_Workbook().get_Worksheets();
                    var worksheet = worksheets.Add("Sheet1");
                    var cells = worksheet.get_Cells();
                    SysExcelRange  sysExcelRange;
                    sysExcelRange   = workSheet.cells().range('E18:F18');
                    sysExcelRange.comObject().MergeCells(1);
                    SysExcelRange.horizontalAlignment(#xlCenter);
                    package.Save();
                }

  • Suggested answer
    Deepak Agarwal Profile Picture
    8,585 on at
    RE: How to merge cells in Excel through x++ code?

    You can concanate your values in a variable (within x++ code) and assign than to an excel cell.

  • Suggested answer
    huijij Profile Picture
    19,811 on at
    RE: How to merge cells in Excel through x++ code?

    Hi Sowmya170106,

    Please try the code segment to merge cells through X :

    SysExcelRange  sysExcelRange;
    sysExcelRange   = workSheet.cells().range('E18:F18');
    sysExcelRange.comObject().MergeCells(1);
    SysExcelRange.horizontalAlignment(#xlCenter);

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
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,120

#2
Sohaib Cheema Profile Picture

Sohaib Cheema 815 User Group Leader

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans