Wednesday, September 13, 2023

Code to export the data to Excel format in D365f&o

 

using System.IO;

using OfficeOpenXml;

using OfficeOpenXml.Style;

using OfficeOpenXml.Table;

internal final class RunnableClass1

{

   public static void main(Args _args)

   {

       HcmWorker hcmWorker;

       MemoryStream memoryStream = new MemoryStream();

       using (var package = new ExcelPackage(memoryStream))

       {

           var currentRow = 1;

           Filename fileName = "Test.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 = "Personnel Number";

           cell.set_Value(value);

           cell = null;

           value = "Name";

           cell = cells.get_Item(currentRow, 2);

           cell.set_Value(value);

           while select hcmWorker

           {

               currentRow ++;

               cell = null;

               cell = cells.get_Item(currentRow, 1);

               cell.set_Value(hcmworker.PersonnelNumber);

               cell = null;

               cell = cells.get_Item(currentRow, 2);

               cell.set_Value(hcmworker.Name());

           }

           package.Save();

           file::SendFileToUser(memoryStream, fileName);

       }

   }

}

Output :



No comments:

Post a Comment