UTIL: Exporta in excel campurile dintr-un tabel

Lasă un comentariu

16 Decembrie 2009 de liviustoica55


static void Export_In_Excel_Campuri_Tabela(Args _args)
{


    sysTableBrowser     sysTableBrowser = new sysTableBrowser();
    tableId                 tableId;
    str                     tableName;

    DictTable               dictTable;
    DictField               dictField;
    int                     fieldCounter;
    int                     rowCounter = 1;

    SysExcelApplication     excelApp = SysExcelApplication::construct();
    SysExcelWorkBooks       excelWorkBooks;
    SysExcelWorkBook        excelWorkBook;
    SysExcelWorkSheets      excelWorkSheets;
    SysExcelWorkSheet       excelWorkSheet;
    SysExcelCells           excelCells;
    SysExcelCell            excelCell;
    COM                     excelRange;
    COM                     excelFont;

    SysOperationProgress    progress = new SysOperationProgress();

    #define.ColumnName(1)
    #define.ColumnLabel(2)
    #define.ColumnConfigKey(3)
    #define.ColumnType(4)
    #define.ColumnHelp(5)
    #define.ColumnSystem(6)

     #define.Tipdebaza(7)
    ;

   tableId = pickTable();

    progress.setCaption('Exporting to Excel');

    excelWorkBooks  = excelApp.workbooks();
    excelWorkBook   = excelWorkBooks.add();
    excelWorkSheets = excelWorkBook.worksheets();
    excelWorkSheet  = excelWorkSheets.itemFromNum(1);
    excelCells      = excelWorkSheet.cells();

    excelCells.item(1, #ColumnName).value("@SYS16033");
    excelCells.item(1, #ColumnLabel).value("@SYS25058");
    excelCells.item(1, #ColumnConfigKey).value("@SYS73212");
    excelCells.item(1, #ColumnType).value(strFmt("%1 / %2", "@SYS72833", 'ENUM'));
    excelCells.item(1, #ColumnHelp).value("@SYS40300");
    excelCells.item(1, #ColumnSystem).value("@SYS4278");

    excelCells.item(1, #Tipdebaza).value("Tip de baza");

   // dictTable = new DictTable(tableNum(tableId));
    dictTable = new DictTable(tableId);
    tableName = dicttable.name();
    progress.setTotal(dictTable.fieldCnt());

    for (fieldCounter = dictTable.fieldNext(0); fieldCounter; fieldCounter = dictTable.fieldNext(fieldCounter))
    {
        rowCounter++;

        dictField = dictTable.fieldObject(fieldCounter);

        progress.setCount(rowCounter-1);
        progress.setText(dictField.label());

        excelCell = excelCells.item(rowCounter, #ColumnName);
        excelCell.value(dictField.name());

        excelCell = excelCells.item(rowCounter, #ColumnLabel);
        excelCell.value(dictField.label());

        excelCell = excelCells.item(rowCounter, #ColumnConfigKey);
        excelCell.value(configurationkeyId2Name(dictField.configurationKeyId()));

        if (dictField.typeId())
        {
            excelCell = excelCells.item(rowCounter, #ColumnType);
            excelCell.value(new DictType(dictField.typeId()).name());
        }
        else
        {
            if (dictField.enumId())
            {
                excelCell = excelCells.item(rowCounter, #ColumnType);
                excelCell.value(new DictEnum(dictField.enumId()).name());
            }
        }

        excelCell = excelCells.item(rowCounter, #ColumnHelp);
        excelCell.value(dictField.help());

        excelCell = excelCells.item(rowCounter, #ColumnSystem);
        excelCell.value(dictField.isSystem() ? 'Yes' : 'No');

    }


        excelCell = excelCells.item(rowCounter, #Tipdebaza);
        excelCell.value(dictField.typeId());


    excelRange = excelWorkSheet.range('A1:E1').comObject();
    excelFont = excelRange.font();
    excelFont.bold(true);

    excelWorkSheet.columns().item(#ColumnName).autoFit();
    excelWorkSheet.columns().item(#ColumnLabel).autoFit();
    excelWorkSheet.columns().item(#ColumnConfigKey).autoFit();
    excelWorkSheet.columns().item(#ColumnType).autoFit();
    excelWorkSheet.columns().item(#ColumnHelp).autoFit();
    excelWorkSheet.columns().item(#ColumnSystem).autoFit();
    excelWorkSheet.name(tableName);
    excelApp.visible(true);
}

Lasă un răspuns

Completează mai jos detaliile despre tine sau dă clic pe un icon pentru autentificare:

Logo WordPress.com

Comentezi folosind contul tău WordPress.com. Dezautentificare / Schimbă )

Poză Twitter

Comentezi folosind contul tău Twitter. Dezautentificare / Schimbă )

Fotografie Facebook

Comentezi folosind contul tău Facebook. Dezautentificare / Schimbă )

Fotografie Google+

Comentezi folosind contul tău Google+. Dezautentificare / Schimbă )

Conectare la %s

%d blogeri au apreciat asta: