25 Ocak 2018 Perşembe

Verileri Excelle Aktarma

Verilerinizi excelle aktarmak için. bir buton ekleyip click'ine aşağıdaki kodu eklededikten sonra;
void clicked()
{
    super();

    element.updateFromExcel();


    DRTCreateProdDemandsTable_ds.query().dataSourceTable(tablenum(DRTCreateProdDemandsTable)).sortClear();
    DRTCreateProdDemandsTable_ds.query().dataSourceTable(tablenum(DRTCreateProdDemandsTable)).addSortField(fieldNum(DRTCreateProdDemandsTable,Qty),SortOrder::Descending);
    DRTCreateProdDemandsTable_ds.executeQuery();
}
Formun methods kısmına kodları eklediyip excelinizdeki verileri aktarabilirsiniz.

void updateFromExcel()
{
    #Excel
    #AviFiles

    Dialog                  dialog = new Dialog("Excel veri aktarma");
    DialogField             dialogPath;
    FilenameFilter          filter = ['Excel files 2010','*.xlsx','Excel files 2003', '*.xls' ];
    FilenameOpen            filePath;
    SysExcelApplication     application;
    SysExcelWorkBooks       workBooks;
    SysExcelWorkBook        workBook;
    SysExcelWorkSheets      workSheets;
    SysExcelWorkSheet       workSheet;
    SysExcelCells           cells;
    SysOperationProgress    progress;
    SysExcelRange           range;
    Int                     NoofSheet,i,lastRow,sn;
    DRTCreateProdDemandsTable     ProdDemandsTable;

    void findLastRow(SysExcelWorkSheet _workSheet)
    {
        #define.Star('*')
        #define.Space(' ')

        ;

        range = _workSheet.cells().range(#ExcelTotalRange);

        try
        {
            // Finds the row where the first contents is found.
            range = range.find(#Star, null, #xlFormulas, #xlWhole, #xlByRows, #xlPrevious);
        }
        catch (Exception::Error)
        {
            error("@SYS59926");
        }

        if (range)
        {
            lastRow = range.row();
        }
        else
        {
            lastRow = 0;
        }
    }
    ;

    dialog.filenameLookupFilter(filter);
    dialogPath  = dialog.addField(typeid(FilenameOpen));

    if (dialog.run())
    {
        if(dialog.closedOk())
        {
            filePath            = dialogPath.value();
            application         = SysExcelApplication::construct();
            application.visible(false);
            workBooks           = application.workbooks();
            workBooks.open(filePath,0,true);

            workSheets          = workBooks.item(1).worksheets();
            noOfSheet           = worksheets.count();
            progress = new SysOperationProgress();
            progress.setCaption("Plan aktarılıyor");
            progress.setTotal(lastRow);
            progress.setAnimation(#AviTransfer);
            setprefix("Plan aktarımı başladı");

            try
            {
                For( i = 1; i <= noOfSheet; i++)
                {
                    workSheet       = workSheets.itemFromNum(i);
                    if(workSheet)
                    {
                        findLastRow(workSheet);
                        for(sn = 2;sn <= lastRow;sn++)
                        {
                            ttsbegin;

                            cells = workSheet.cells();
                            ProdDemandsTable.clear();
                            select forupdate ProdDemandsTable
                                where ProdDemandsTable.itemid == cells.item(sn,1).value().bStr();
                            if ( ProdDemandsTable.RecId )
                            {
                                ProdDemandsTable.Qty           = cells.item(sn,2).value().double();
                                ProdDemandsTable.Notes         = cells.item(sn,3).value().bStr();
                                ProdDemandsTable.ConfigId      = cells.item(sn,4).value().bStr();
                                ProdDemandsTable.InventSizeId  = cells.item(sn,5).value().bStr();
                                ProdDemandsTable.InventColorId = cells.item(sn,6).value().bStr();
                                ProdDemandsTable.InventDimId   = cells.item(sn,7).value().bStr(); // MAA
                                ProdDemandsTable.ETGGroupId2   = cells.item(sn,8).value().bStr();
                                ProdDemandsTable.InventDimCombinationName   = cells.item(sn,9).value().bStr();
                                ProdDemandsTable.InventSizeName             = cells.item(sn,10).value().bStr();

                                ProdDemandsTable.doupdate();
                            }
                            else
                                info(strfmt("%1 bulunamadı.", cells.item(sn,1).value().bStr()));

                            ttscommit;
                        }
                    }
                }
            }
            catch
            {
                ttsabort;
                application.quit();
            }
        }
    }
}
exceli görmek için tıklayın.

Hiç yorum yok:

Yorum Gönder

Total ciro

static void MAA_SalesTableTotal(Args _args) { SalesTable SalesTable; utcDateTime dateTime; dateTime ...