Minggu, 11 April 2021

Export data to Excel via x++

https://visvashwalia.blogspot.com/2016/10/export-data-to-excel-from-microsoft.html?showComment=1618198356552#c3486349219749749881

Jadi kita sedang mencoba untuk code2 baru teruatam bagaimana export data to excel melalui x++.
dipostingan yang lama saya menggunakan ax2009.

sekarang kita akan menggunakan ax2012

static void ExportDatatoExcel(Args _args)
{
    SysExcelApplication            sysExcelApplication;
    SysExcelWorkbooks              excelWorkbookCollection;
    SysExcelWorkbook               excelWorkbook;
    SysExcelWorksheets             excelWorksheetCollection;
    SysExcelWorksheet              excelWorksheet;
    int                            i =1;
    str                            filename;
    vendTable                      vendTable;
    
    PSMRekapbayarsupplier          CustTableSelected; 
    ;


    // give the file name and save it to c drive
     filename = "C:\\A_Folder\\" + "ItemDetails5" +".xls";
    //"C:\\A_Folder\\" + "ItemDetails" + ".csv";

    // initlize the SysExcelApplication instance
    sysExcelApplication  = SysExcelApplication::construct();

    //create excel workbook and excel worksheet
    excelWorkbookCollection  = sysExcelApplication.workbooks();
    excelWorkbook    = excelWorkbookCollection.add();
    excelWorksheetCollection = excelWorkbook.worksheets();
    excelWorksheet = excelWorksheetCollection.itemFromNum(1);

    // excel column captions

    excelWorksheet.cells().item(i,1).value("Supplier");
    excelWorksheet.cells().item(i,2).value("Atas nama");
    excelWorksheet.cells().item(i,3).value("Bank");
    excelWorksheet.cells().item(i,4).value("No.Rek");
    excelWorksheet.cells().item(i,5).value("Total (Rp)");
    excelWorksheet.cells().item(i,6).value("Biaya transfer(Rp)");
    excelWorksheet.cells().item(i,7).value("Total (Rp)");
    
    i++;
    // fill the excel with vendtable Fields
    while select CustTableSelected
        where CustTableSelected.PSMJournalcashier == "GL21000556"
    {
        //if(i == 50)
         //break;

        excelWorksheet.cells().item(i,1).value(CustTableSelected.PSMName);
        excelWorksheet.cells().item(i,2).value(CustTableSelected.PSMName);
        excelWorksheet.cells().item(i,3).value(CustTableSelected.PSMToBankAccountname);
        excelWorksheet.cells().item(i,4).value(CustTableSelected.PSMToBankAccount);
        excelWorksheet.cells().item(i,5).value(num2str(CustTableSelected.PSMNominal,2,2,2,1));
        excelWorksheet.cells().item(i,6).value(CustTableSelected.PSMPaymFeeAmount);
        excelWorksheet.cells().item(i,7).value(CustTableSelected.PSMNominal+CustTableSelected.PSMPaymFeeAmount);
        
        i++;
    }

    //check the fileName is already exist
     if(WinAPI::fileExists(filename))
         WinAPI::deleteFile(filename);
     // save excel file
     excelWorkbook.saveAs(filename);

    // open excel file
    sysExcelApplication.visible(true);

    // close excel file
 // sysExcelApplication.quit();

}

coba lihat di bagian 

excelWorksheet.cells().item(i,5).value(num2str(CustTableSelected.PSMNominal,2,2,2,1));
excelWorksheet.cells().item(i,6).value(CustTableSelected.PSMPaymFeeAmount);

cell no 5 saya kenakan num2str
cell no 6 tidak.

hasil dari cell no 5 adalah nilai amount lengkap dengan separator decimalnya
sedangkan no 6 tidak ada separator dan decimal. sehingga seperti deret angka biasa.

Tidak ada komentar:

Posting Komentar

Erorr CS1963 - An expression tree may not contain a dynamic operation.

Kali ini saya mendapatkan erorr dengan code CS1963, padahal sebelumnya saya sudah mendefinisikan 'var item in Model' di @foreach(var...