Friday, July 18, 2014

Save File As CSV From Excel through X++

static void SaveAsCSVFileFromExcel(Args _args)
{
    #Excel
      SysExcelApplication excel;
      SysExcelWorkBooks books;
      Filename excelFileName;
      Filename csvFileName;
      ;
    /*
      csvFileName = 'C:\\LedgerData.csv';
      excelFileName = ' C:\\LedgerData.xls';
      excel = SysExcelApplication::construct( );
      excel.displayAlerts (false);
      books = excel.workbooks( );
      books.open(csvFileName,0,false,2,"","",false,#xlWindows,",",false,false,1,false,false,1,false);

      books.item(1).saveAs(excelFileName);
      excel.quit();*/

      csvFileName = 'D:\\LedgerData.csv';
      excelFileName = 'C:\\LedgerData.xlsx';
      excel = SysExcelApplication::construct();
      excel.displayAlerts (false);
      books = excel.workbooks( );
      books.open(excelFileName,0,false,2,"","",false,#xlWindows,",",false,false,1,false,false,1,false);

      books.item(1).saveAs(csvFileName);
      excel.quit();
}

No comments:

Post a Comment