AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 05.02.2013, 20:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
bojensen: Dynamics: Import Data into AX from excel file
Источник: http://blogs.bojensen.eu/?p=4667
==============
Import Data into AX from excel file

X++:
static void DataImportToAXFromExcel(Args _args)
{
    SysExcelApplication xlsApplication;
    SysExcelWorkBooks   xlsWorkBookCollection;
    SysExcelWorkBook    xlsWorkBook;
    SysExcelWorksheets  xlsWorkSheetCollection;
    SysExcelWorksheet   xlsWorkSheet;
    SysExcelRange       xlsRange;
    SysExcelCells       Cells;
    SysExcelCell        RCell;
    CommaIO             inFile;
    int                 nRow,i;
    DialogField         dialogPath;
    Dialog              dialog;
    Filename            filename;
    CustTable           custTable;
    CustAccount         custAccount;
    CustGroupId         custGroupId;
    CurrencyCode        currencyCode;
    ;
    dialog = new Dialog();
    dialogPath = dialog.addField(typeid(Filenameopen), File );
    dialog.run();
    if (dialog.run())
    {
        filename = (dialogPath.value());
    }
    inFile = new CommaIO (filename, );
    if (!inFile || infile.status() != IO_Status::Ok )
    {
        throw error (strfmt(@,filename));
    }
    try
    {
        xlsApplication          = SysExcelApplication::construct();
        xlsWorkBookCollection   = xlsApplication.workbooks();
        xlsWorkBookCollection.open(filename);
        xlsWorkSheetCollection  = xlsApplication.worksheets();
        xlsWorkSheet            = xlsWorkSheetCollection.itemFromNum(1);
        Cells                   = xlsWorkSheet.Cells();
        nRow = 2;
        RCell = Cells.Item(nRow, 1);
        while(RCell.value().bStr() != )
        {
            custAccount     = RCell.value().bStr();
            RCell           = Cells.item(nRow,2);
            custGroupId     = RCell.value().bStr();
            RCell           = Cells.item(nRow,3);
            currencyCode    = RCell.value().bStr();
            if(!CustTable::exist(custAccount))
            {
                if(CustGroup::exist(custGroupId) && Currency::exist(currencyCode))
                {
                    custTable.initValue();
                    custTable.AccountNum    = custAccount;
                    custTable.CustGroup     = custGroupId;
                    custTable.Currency      = currencyCode;
                    custTable.insert();
                }
            }
            nRow++;
            RCell = Cells.Item(nRow, 1);
        }
        xlsApplication.quit ();
        xlsApplication.finalize ();
        info(Imported );
    }
    catch( Exception::Error)
    {
        //Close Excel.
        xlsApplication.quit ();
        xlsApplication.finalize ();
        ttsabort;
        info(Unable to process the excel import );
    }
}
Источник: http://blogs.bojensen.eu/?p=4667
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Последний раз редактировалось Poleax; 06.02.2013 в 10:42.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
ax-erp: Creating SSRS-Reports in Dynamics AX 2012 – What’s no longer possible in AX-reports Blog bot DAX Blogs 0 18.07.2012 12:11
dynamics-ax: Microsoft Dynamics AX 2012 Excel Add-in Blog bot DAX Blogs 0 08.06.2011 08:12
Microsoft Dynamics CRM Team Blog: Creating Custom Sample Data for Microsoft Dynamics CRM 2011 Blog bot Dynamics CRM: Blogs 0 07.01.2011 03:15
hariprasadp: Import Excel file data in to dynamics AX through Dynamics AX Blog bot DAX Blogs 0 17.12.2009 20:05
gatesasbait: Dynamics AX 2009 SSRS and SSAS Integration Tips Blog bot DAX Blogs 3 09.07.2009 13:07

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 17:28.