Friday, January 24, 2014

Export to excel by clicked method

// by clicked Methos

void clicked()
{
       SysExcelApplication  xlsApplication;
       SysExcelWorkBooks    xlsWorkBookCollection;
       SysExcelWorkBook     xlsWorkBook;
       SysExcelWorkSheets   xlsWorkSheetCollection;
       SysExcelWorkSheet    xlsWorkSheet;
       SysExcelRange        xlsRange;
       EmployeeTMP          EmpTmp;
       int                  row = 1;
       str                  fileName;
       Args                    args = new Args();

       //Filename
       fileName = "C:\\Test.xlsx";
       //Initialize Excel instance
       xlsApplication           = SysExcelApplication::construct();
       //Open Excel document
        xlsApplication.visible(true);

       //Create Excel WorkBook and WorkSheet
       xlsWorkBookCollection    = xlsApplication.workbooks();
       xlsWorkBook              = xlsWorkBookCollection.add();
       xlsWorkSheetCollection   = xlsWorkBook.worksheets();
       xlsWorkSheet             = xlsWorkSheetCollection.itemFromNum(1);
       //Excel columns captions
       xlsWorkSheet.cells().item(row,1).value("EmpCode");
       xlsWorkSheet.cells().item(row,2).value("EmpName");
       xlsWorkSheet.cells().item(row,3).value("EmployeeDesgination");
       xlsWorkSheet.cells().item(row,4).value("DateOfJoining");
       xlsWorkSheet.cells().item(row,5).value("DateOfTermination");
       xlsWorkSheet.cells().item(row,6).value("DateOfBirth");
       xlsWorkSheet.cells().item(row,7).value("Age");
       xlsWorkSheet.cells().item(row,8).value("Salary");
       xlsWorkSheet.cells().item(row,9).value("Currency");
       xlsWorkSheet.cells().item(row,10).value("JobType");
       xlsWorkSheet.cells().item(row,11).value("Experience");

       row++;

       while select EmpTmp
       {
         if(row == 20)
           break;
           xlsWorkSheet.cells().item(row,1).value(EmpTmp.EmpCode);
           xlsWorkSheet.cells().item(row,2).value(EmpTmp.EmpName);
           xlsWorkSheet.cells().item(row,3).value(enum2str(EmpTmp.EmployeeDesgination));
           xlsWorkSheet.cells().item(row,4).value(any2date(EmpTmp.DateofJoining));
           xlsWorkSheet.cells().item(row,5).value(any2date(EmpTmp.DateOfTermination));
           xlsWorkSheet.cells().item(row,6).value(any2date(EmpTmp.DateOfBirth));
           xlsWorkSheet.cells().item(row,7).value(EmpTmp.Age);
           xlsWorkSheet.cells().item(row,8).value(EmpTmp.Salary);
           xlsWorkSheet.cells().item(row,9).value(enum2str(EmpTmp.CurrencyValue));
           xlsWorkSheet.cells().item(row,10).value(enum2str(EmpTmp.TypeOfJob));
           xlsWorkSheet.cells().item(row,11).value(EmpTmp.YearsOfExperience);

          row++;

         info(strFmt("%1, %2, %3, %4, %5 %6 %7 %8 %9 %10 %11", EmpTmp.EmpCode,EmpTmp.EmpName,(enum2str(EmpTmp.EmployeeDesgination)),(any2date(EmpTmp.DateofJoining)),(any2date(EmpTmp.DateOfTermination)),(any2date(EmpTmp.DateOfBirth)),EmpTmp.Age,EmpTmp.Salary,(enum2str(EmpTmp.CurrencyValue)),(enum2str(EmpTmp.TypeOfJob)),EmpTmp.YearsOfExperience));
    }
       //Check whether the document already exists
       if(WinApi::fileExists(fileName))
          WinApi::deleteFile(fileName);
       //Save Excel document

       xlsWorkbook.saveAs(fileName);
       //Open Excel document
       xlsApplication.visible(true);
       //Close Excel
       //xlsApplication.quit();
       //xlsApplication.finalize();

    super();
   
}

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...