How to use the X++ program to convert a CSV file to an Excel Worksheet in Microsoft Dynamics AX 4.0

Applies to: Microsoft Dynamics AX 4.0

Source: Microsoft Support

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION THAT IS CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED TO SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

INTRODUCTION


This article describes how to use the X++ program to convert a Comma Separated Values (CSV) file to an Excel Worksheet in Microsoft Dynamics AX 4.0.

More Information


To convert a CSV file to an Excel Worksheet in Microsoft Dynamics AX 4.0, you can use the X++ program. The following X++ code is an example that is used to CSV file to an Excel Worksheet.

static void Job1(Args _args)
{
#Excel
SysExcelApplication excel;
SysExcelWorkBooks books;
Filename excelFileName;
Filename csvFileName;
;
csvFileName = 'C:\\<File_Name>.csv';
excelFileName = ' C:\\<File_Name>.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() ;
}
Note In the code, the <File_Name> placeholder represents the actual file name.

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, THE RELIABILITY OR THE ACCURACY OF THE INFORMATION THAT IS CONTAINED IN THE DOCUMENTS AND THE RELATED GRAPHICS PUBLISHED ON THIS WEB SITE (THE “MATERIALS”) FOR ANY PURPOSE.

THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON-INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.