Skip to main content

Notifications

Microsoft Dynamics AX forum
Answered

Exporting data into excel file

Posted on by 2,427

Hi All,

I am exporting data into excel.

The execution time to export data is lengthy. so, it is throwing errors or closing AX client abruptly.

Is there any work around for this issue.

Sometimes, It is throwing error as follows though code is correct.

"The number of arguments provided is different from the number of arguments accepted by the method."

Thanks,

Raziq.Ali

  • Verified answer
    Anton Venter Profile Picture
    Anton Venter 5,030 Super User on at
    RE: Exporting data into excel file

    That's exactly what I mean. The data is exported to a CSV file. When the data export is finished, convert the CSV file to XLS. See code below, it converts XLS to CSV but you can modify it to convert CSV to XLS.

    //avent use the Windows Region List Separator value
    public client static void convertXLS2CSV(FileName   _fileNameXLS,
                                             Filename   _fileNameCSV)
    {
        #File
        #Excel
    
        SysExcelApplication excel;
        SysExcelWorkBooks   books;
    
        if (strLen(_fileNameXLS) == 0)
            throw error("Excel file name parameter is invalid.");
    
        if (WinAPI::fileExists(_fileNameXLS) == false)
            throw error(strFmt("The file '%1' already exists.", _fileNameXLS));
    
        if (WinAPI::fileExists(_fileNameCSV))
            WinAPI::copyFile(_fileNameCSV, strFmt('%1~', _fileNameCSV), true);
    
        excel = SysExcelApplication::construct();
        excel.displayAlerts(false);
    
        books = excel.workbooks();
        books.open(_fileNameXLS);
    
        books.item(1).saveAs(_fileNameCSV, #xlCSV);
        excel.quit();
    
        excel = null;
        books = null;
    }
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,000 Super User on at
    RE: Exporting data into excel file

    Yes, these classes use COM objects. It's a useful tool for manipulating Excel spreadsheets at runtime, but a poor choice for large data exports.

  • Mohammad Raziq Ali Profile Picture
    Mohammad Raziq Ali 2,427 on at
    RE: Exporting data into excel file

    As you said, If I export into csv format then excel.

    can you elaborate "convert the text file to a real Excel file at the end"?

    I want data to be separated by column wise but not by comma.

    Thanks,

    Raziq.Ali

  • Mohammad Raziq Ali Profile Picture
    Mohammad Raziq Ali 2,427 on at
    RE: Exporting data into excel file

    I am exporting table data into excel using SysExcelXXX classes.

  • Anton Venter Profile Picture
    Anton Venter 5,030 Super User on at
    RE: Exporting data into excel file

    Hi, I assume you are using the SysExcelXXX classes to export the data. If you export the data to a text file and convert the text file to a real Excel file at the end, it will be a lot faster. This can be done exporting to CSV.

  • Martin Dráb Profile Picture
    Martin Dráb 225,000 Super User on at
    RE: Exporting data into excel file

    How are you exporting data to Excel?

    Based on the error, I guess you're using using COM objects, which indeed isn't very efficient solution. You'll get much better performance from the Data Import Export Framework.

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,682 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,000 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans