Thursday 27 April 2017

Export Vendor To Excel Using X++

void clicked()
{
    SysExcelApplication             application;
    SysExcelWorkbooks               workbooks;
    SysExcelWorkbook                workbook;
    SysExcelWorksheets              worksheets;
    SysExcelWorksheet               worksheet;
    SysExcelCells                   cells;
    SysExcelCell                    cell;
    SysExcelFont                    font;
    int                             row;
    VendTable                       vendTable1;
    DirPartyTable                   dirPartyTable1;
    LogisticsElectronicAddress      logistics;
    LogisticsPostalAddress          postalAddress;
    LogisticsLocation               location;


    // intializing classes to export excel
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    cells.range('A:A').numberFormat('@');

    // Setting Header values
    cell = cells.item(1, 1);
    cell.value('Vendor Account');
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 2);
    cell.value('Vendor Name');
    font = cell.font();
    font.bold(true);
    row = 1;
     cell = cells.item(1, 3);
    cell.value('Vendor Group');
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 4);
    cell.value('Site');
    font = cell.font();
    font.bold(true);
    row = 1;

    cell = cells.item(1, 5);
    cell.value('WareHouse');
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 6);
    cell.value('Currency');
    font = cell.font();
    font.bold(true);
    row = 1;

    cell = cells.item(1, 7);
    cell.value('Terms Of payment');
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 8);
    cell.value('Methods Of Payment');
    font = cell.font();
    font.bold(true);
    row = 1;
    cell = cells.item(1, 9);
    cell.value('Address');
    font = cell.font();
    font.bold(true);
    row = 1;

    cell = cells.item(1, 10);
    cell.value('Description');
    font = cell.font();
    font.bold(true);
    row = 1;

    // inserting data row wise selecting single record----

    select vendTable1 where vendTable1.AccountNum == Identification_AccountNum.valueStr()
                join dirPartyTable1  where   vendTable1.Party == dirPartyTable1.RecId
                        join  location  where  Location.RecId == dirPartyTable1.PrimaryAddressLocation
                                join postalAddress where   postalAddress.Location == location.RecId;
     // inserting data row wise selecting Multiple record----
    //while select vendTable1
                        //join   dirPartyTable1  where   vendTable1.Party == dirPartyTable1.RecId
                            //join    location  where  Location.RecId == dirPartyTable1.PrimaryAddressLocation
                                //join postalAddress where   postalAddress.Location == location.RecId
    {
        row++;
        cell = cells.item(row, 1);
        cell.value(vendTable1.AccountNum);
        cell = cells.item(row, 2);
        cell.value(dirPartyTable1.Name);
        cell = cells.item(row, 3);
        cell.value(vendTable1.VendGroup);
        cell = cells.item(row, 4);
        cell.value(vendTable1.InventSiteId);
        cell = cells.item(row, 5);
        cell.value(vendTable1.InventLocation);
        cell = cells.item(row, 6);
        cell.value(vendTable1.Currency);
        cell = cells.item(row, 7);
        cell.value(vendTable1.PaymTermId);
        cell = cells.item(row, 8);
        cell.value(vendTable1.PaymMode);
        cell = cells.item(row, 9);
        cell.value(postalAddress.Address);
        cell = cells.item(row, 10);
        cell.value(Location.Description);
    }


    application.visible(true);
    super();
}

No comments:

Post a Comment