X++ code to export the records to Excel Sheet from Table dynamically in D365 F&O

 using System.IO;

using OfficeOpenXml;

using OfficeOpenXml.Style;

using OfficeOpenXml.Table;

class BASExcelExport

{

    /// <summary>

    /// Runs the class with the specified arguments.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

        BASEmployeeDetails employeeDetails;

        MemoryStream memoryStream = new MemoryStream();

        using (var package = new ExcelPackage(memoryStream))

        {

           var currentRow = 1;

            Filename fileName = 'Book1.Xlsx';

            var worksheets = package.get_Workbook().get_Worksheets();

            var CustTableWorksheet = worksheets.Add('Export');

            var cells = CustTableWorksheet.get_Cells();

            OfficeOpenXml.ExcelRange cell = cells.get_Item(currentRow, 1);

            System.String value = 'Employee ID';

            cell.set_Value(value);

            cell = null;

            value = 'Employee Name';

            cell = cells.get_Item(currentRow, 2);

            cell.set_Value(value);

            while select employeeDetails

            {

               currentRow ++;

                cell = null;

                cell = cells.get_Item(currentRow, 1);

                cell.set_Value(employeeDetails.EmpId);

                cell = null;

                cell = cells.get_Item(currentRow, 2);

                cell.set_Value(employeeDetails.EmpName);

            }

            package.Save();

            file::SendFileToUser(memoryStream, fileName);

        }    

    }

}

Comments

Popular posts from this blog

How to Create a wizard in x++ d365

how to post trade agreement journals automatically using x++ code

X++ code to CREATE AND POST A TRADE AGREEMENT IN MICROSOFT DYNAMICS 365 in D365 F & O