web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Unable to read integer value from excel in ax 2012

(0) ShareShare
ReportReport
Posted on by 125

Hi I got into a weird situation. i am trying to import data into the ax from excel sheet. in that particular sheet i have a product number column. i have to read the product number. in the product numbers i have complete integer product number as well as some product numbers are suffixed with a string. so my situation is i can able to read the product numbers which are having suffixed string. unable to read the only integer values.

item-numbers.PNG

above is the sample column for item numbers. the first row consists only number. where as bellow you can see number  suffixed with string.

when i debug my code i can able to see the string values but not the integer values.

integer_2D00_item.PNG

see the row number and item id in above picture. i am getting empty here.

string_2D00_item.PNG

but incase of string item i am getting the value.

my code for this 

static void RES_PROS_ImportMasterProduct(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
Name name;
FileName filename;
//ProductType productType;
InventTable inventTable;
int row;
Dialog dialog;
Dialogfield dialogfield;
str 100 itemID;
str 100 s;
boolean first = true;

;

application = SysExcelApplication::construct();
workbooks = application.workbooks();

//filename = @"C:\Users\Desktop\ImportWareHouse.xlsx";
dialog = new dialog('Excel Import');
dialogfield = dialog.addField(extendedTypeStr(FilenameOpen), 'File Name');

dialog.run();
filename =(dialogfield.value());

try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}

workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
while select forUpdate inventTable
{

do
{
row++;
s = any2str(cells.item(row, 2).value().bStr());

itemID = cells.item(row, 2).value().bStr();
if(itemID == inventTable.ItemId)
{
inventTable.RES_MasterProduct = cells.item(row, 7).value().bStr();
inventTable.doInsert();
}
type = cells.item(row+1, 7).value().variantType();
}while (type != COMVariantType::VT_EMPTY);
row=0;
}
application.quit();
workbooks.close();

info("Done");
}

*This post is locked for comments

I have the same question (0)
  • venkatpasumarthi Profile Picture
    125 on at

    I have tried in that way also. formatted the cells as text. But no luck

  • Verified answer
    venkatpasumarthi Profile Picture
    125 on at

    The Solution to this problem looks strange but it worked. the problem is with Excel formatting. first i need to format all the cells into general or Text format. but it didn't solved my problem latter. i have double clicked on the formatted cell. then that particular cell i can able to read. Strange Right but it works. then i have done the same thing for almost 1000 records in excel.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans