Exporting records from master table(D365FO) to excel using X++ code

 we are trying to export data from master table to Excel  through the following job.

Create a job :-

using System.IO;

using OfficeOpenXml;

using OfficeOpenXml.Style;

using OfficeOpenXml.Table;


class BASCustInfoExportJob

{

    /// <summary>

    /// Runs the class with the specified arguments.

    /// </summary>

    /// <param name = “_args”>The specified arguments.</param>

    public static void main(Args _args)

    {

        BAS_Employees employees;

        MemoryStream memoryStream = new MemoryStream();

        using (var package = new ExcelPackage(memoryStream))

        {

            var currentRow = 1;

            Filename fileName = "Emp.xlsx";

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

            var EmployeeTableWorksheet = worksheets.Add("Export");

            var cells = EmployeeTableWorksheet.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 employees

            {

                currentRow ++;


                cell = null;


                cell = cells.get_Item(currentRow, 1);


                cell.set_Value(employees.BAS_EmployeID);


                cell = null;


                cell = cells.get_Item(currentRow, 2);


                cell.set_Value(employees.BAS_FirstName);

            }


            package.Save();


            file::SendFileToUser(memoryStream, fileName);


        }


    }


}


Comments

Popular posts from this blog

How to Create a wizard in x++ d365

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

x++ code to submit and approve and reject the invent movement workflow in d365 F&O