Tuesday, 24 December 2013

Direct Excel Import in ax 2012

 class SPLPayDirectExcelImport  extends runbase
{
  SPLPayHeadDefination          headDefination;
  ExcelimportADO                excelimportADO;
  str 100                       filename;
  str                           path;
  int                           i;

  Dialog                        filedialog;
  Dialogfield                   dialogFilename;

  #DEFINE.CurrentVersion(1)
  #LOCALMACRO.CurrentList
  filename
  #ENDMACRO

}

Object dialog()
{
    //Object ret;
    filedialog = super();
    filedialog.caption("Select File Name");
    dialogFilename = filedialog.addField(extendedTypeStr(FileNameopen));
    return filedialog;
}

public boolean getFromDialog()
{
;
        filename = dialogFilename.value();
        return true;
}

public container pack()
{
     return [#CurrentVersion,#CurrentList];
}

public void run()
{
  ;
  super();

  excelimportADO  = new Excelimportado(filename);
  excelimportADO.getExcelSheetNames();
  excelimportADO.openFile(false);

  ttsbegin;
  while (!excelimportADO.eof())
  {
        headDefination.HeadID = excelimportADO.getFieldValue(1);

        headDefination.insert();
        excelimportADO.moveNext();
        i++;
  }
  info(strfmt('%1 No of records are imported ',i));
  ttscommit;
}

public boolean unpack(container packedClass)
{
    Integer     _version     = conPeek(packedClass,1);

    switch (_version)
    {
        case(#CurrentVersion) :
            [_version,#CurrentList] = packedClass;
            break;
        default :
            return false;
    }

    return true;
    }

public static void main(Args args)
{

  SPLPayDirectExcelImport                ExcelImport;

  ExcelImport      =   new  SPLPayDirectExcelImport();

  if(ExcelImport.prompt())
  {
       ExcelImport.run();
  }

}

No comments:

Post a Comment