//Apply this method in any Button Override Method.
// This method is used to Import the Excel Data to AX Table
//
//
// Excel File Contains 3 Columns which is EquipmentId, Cost, EffectiveDate
// Same way here we have created Code For the particular Three field....
public void ImportData()
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
System.DateTime ShlefDate;
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog;
#AviFiles
// Progress Bar
SysOperationProgress progress = new SysOperationProgress(1, NoYes::Yes);
TestXls _TestXls; // Table name and decleration
str equipId;
str cost;
str effectiveDate;
int datevalue, row = 0;
real costr;
Date dater;
#Excel
str COMVariant2Str(COMVariant _cv,
int _decimals = 1,
int _characters = 0,
int _separator1 = 0,
int _separator2 = 0)
{
switch(_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R4):
return num2str(_cv.float(),
_characters,
_decimals,
_separator1,
_separator2);
case (COMVariantType::VT_R8):
return num2str(_cv.double(),
_characters,
_decimals,
_separator1,
_separator2);
case (COMVariantType::VT_DECIMAL):
return num2str(_cv.decimal(),
_characters,
_decimals,
_separator1,
_separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),
123,
2,
1,
2,
1,
4);
case (COMVariantType::VT_EMPTY):
return "";
default:
throw error(strfmt("@SYS26908",
_cv.variantType()));
}
return "";
}
;
dialog = new Dialog("ExcelUpload");
dialogFilename = dialog.addField(typeId(FilenameOpen));
dialog.filenameLookupFilter(["@SYS28576",#XLS, "@SYS28576",#XLSX]);
dialog.filenameLookupTitle("Upload from Excel");
dialog.caption("Excel Upload");
dialogFilename.value(filename);
if(!dialog.run()) Continue reading →