AXForum  
Go Back   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Forgotten Your Password?
Register Forum Rules FAQ Members List Today's Posts Search Mark Forums Read

 
 
Thread Tools Search this Thread Display Modes
Old 17.12.2009, 20:05   #1  
Blog bot is offline
Blog bot
Участник
 
24,919 / 825 (77) +++++++
Join Date: 28.10.2006
hariprasadp: Import Excel file data in to dynamics AX through Dynamics AX
Источник: http://hariprasadp.spaces.live.com/B...B91F!208.entry
==============
X++:
//--HariPattela--Dynamics AX import table data form Excel to AX table
static void ExcelFile_Import(Args _args)
{
    int i;
    //Excel related declarations
    #excel
    SysExcelApplication SysExcelApplication;
    SysExcelWorksheet SysExcelWorksheet;
    SysExcelWorksheets SysExcelWorksheets;
    SysExcelWorkbooks SysExcelWorkbooks;
    SysExcelWorkbook SysExcelWorkbook;
    SysExcelRange SysExcelRange;
    SysExcelCell SysExcelCell;
    SysExcelCells SysExcelCells;
    SysExcelRange range;
    COMVariant file;

    //progress bar
    #avifiles
    SysOperationProgress simpleProgress;

    //variables used while importing data
    int j, imported,  noofrows, firstrow;
    real ratio;
    str strExample;
    int intExample;

    ;

    //check if file has been selected
    //open the selected excel
    try{
        sysExcelApplication = SysExcelApplication::construct();
        sysExcelApplication.visible(false);
        sysExcelWorkbooks = sysExcelApplication.workbooks();
        file = new COMVariant();
        file.bStr('C:/fg.xls');

        sysExcelWorkbook = sysExcelWorkbooks.add(file);
        SysExcelWorksheets = sysExcelWorkbook.worksheets();
        SysExcelWorksheet = SysExcelWorksheets.itemFromNum(1);
    }
    catch(Exception::Error)
    {
         throw error("cannot open the excel file");
    }

    try
    {

        SysExcelRange = SysExcelWorksheet.cells().range(#ExcelDataRange);

        //Get the number of rows in excel file
        range = SysExcelRange.find("*", null, #xlFormulas, #xlWhole,
                                    #xlByRows, #xlPrevious);
        if(range)
        {
            noofrows = range.row();
        }
        else
        {
            sysExcelApplication.workbooks().close();
            sysExcelApplication.quit();
            throw error('fg.xls');
        }

        //Get the number of columns in excel file
        range = SysExcelRange.find("*", null, #xlFormulas, #xlWhole,
                                    #xlByColumns, #xlPrevious);

        if(range)
        {
            sysExcelApplication.workbooks().close();
            sysExcelApplication.quit();
            throw error('C:/fg.xls');
        }
    }
    catch(Exception::Error)
    {
       sysExcelApplication.workbooks().close();
       sysExcelApplication.quit();
       throw error("Hata!");
    }


    sysExcelCells = sysExcelWorksheet.cells();
    //initialize the progress bar
    ratio = noofrows / 100;
    simpleProgress = SysOperationProgress::newGeneral(#aviUpdate, 'file is importing', 100);

    //importing part
    //Chck currency

    ttsbegin;

    //read rows of excel
    for(j=3; j<=noofrows; j++)
    {
            imported++;
        print(imported);
       
        strExample           = sysExcelCells.item(j, 1).value().bStr();
        intExample           = sysExcelCells.item(j, 4).value().double();
    }
    pause;
    ttscommit;

    //display info
    info(int2str(imported) + " records imported.");

    //close the excel file
    sysExcelApplication.workbooks().close();
    sysExcelApplication.quit();
}
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
This post has been rated by: Gustav (0).
 

Similar Threads
Thread Thread Starter Forum Replies Last Post
emeadaxsupport: List of fixes that improve performance of certain features in Dynamics AX 2009 Blog bot DAX Blogs 0 13.10.2009 19:06
CRM DE LA CREME! Configuring Microsoft Dynamics CRM 4.0 for Internet-facing deployment Blog bot Dynamics CRM: Blogs 0 18.08.2009 11:05
Microsoft Dynamics CRM Team Blog: Data Migration Manager Tips and Tricks Blog bot Dynamics CRM: Blogs 0 02.09.2008 22:05
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
Inside Dynamics AX 4.0: Usage Scenarios Blog bot DAX Blogs 0 04.10.2007 05:15
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Рейтинг@Mail.ru
All times are GMT +3. The time now is 10:31.
Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
Contacts, Advertising.