Search your query

Thursday, February 9, 2017

X++ Code to upload and read the Excel File in Dynamics 365 (Excel Import)

// <summary>
/// Upload and Read the Excel File in Dynamics 365
/// </summary>

        public void uploadAndReadExcelFile()
        {
            FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult;

            if (result && result.getUploadStatus())
            {
                str ret;

                using (var package = new OfficeOpenXml.ExcelPackage(result.openResult()))
                {
                    var worksheets = package.get_Workbook().get_Worksheets();
                    var worksheet = worksheets.get_Item(1);
                    var cells = worksheet.get_Cells();
                    var cell = cells.get_Item(1,1);
                    ret = cell.get_Value();
                }

                info(ret);
            }

        }

No comments:

Post a Comment