web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

What is the best way to work with xls files (x++)

(0) ShareShare
ReportReport
Posted on by 45

I want to work with ".xls" files, however EPPlus produces an error when I try to read the ".xls" file.

this my code:

        System.IO.Stream stream;
        ExcelSpreadsheetName sheeet;
        FileUploadBuild fileUpload;
        DialogGroup dlgUploadGroup;
        FileUploadBuild fileUploadBuild;
        FormBuildControl formBuildControl;
        Dialog dialog = new Dialog("Import the data from Excel");
        dlgUploadGroup          = dialog.addGroup("@SYS54759");
        formBuildControl        = dialog.formBuildDesign().control(dlgUploadGroup.name());
        fileUploadBuild         = formBuildControl.addControlEx(classstr(FileUpload), 'Upload');
        fileUploadBuild.style(FileUploadStyle::MinimalWithFilename);
        fileUploadBuild.fileTypesAccepted('.xls');
 
        if (dialog.run() && dialog.closedOk())
        {
            FileUpload fileUploadControl     = dialog.formRun().control(dialog.formRun().controlId('Upload'));
            FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult();
 
            if (fileUploadResult != null && fileUploadResult.getUploadStatus())
            {
                stream = fileUploadResult.openResult();
                using (ExcelPackage Package = new ExcelPackage(stream))
                {
                    int rowCount, i;
                    Package.Load(stream);
                    ExcelWorksheet  worksheet   = package.get_Workbook().get_Worksheets().get_Item(1);
                    OfficeOpenXml.ExcelRange    range       = worksheet.Cells;
                    rowCount                  = worksheet.Dimension.End.Row - worksheet.Dimension.Start.Row   1;
 
                    for (i = 2; i<= rowCount; i  )
                    {
                        info(range.get_Item(i, 1).value);
                        info(range.get_Item(i, 2).value);
                    }
                }
            }
            else
            {
                error("Error here");
            }

I'm wondering whether there is another approach to work with "xls" files.

I saw several code snippets that use SysExcelWorkbook, but they fail with the error "The name 'SysExcelApplication' does not denote a class, a table, or an extended data type."

        SysExcelApplication application;
        SysExcelWorkbooks workbooks;
        SysExcelWorkbook workbook;
        SysExcelWorksheets worksheets;
        SysExcelWorksheet worksheet;
        SysExcelCells cells;
        COMVariantType type;
        int row;
        ItemId itemid;
        Name name;
        FileName filename;
        ;
        application = SysExcelApplication::construct();
        workbooks = application.workbooks();
        //specify the file path that you want to read
        filename = @"C:\Users\hsaoudi\Downloads\crypresenceetcoutparemploye.xls";
        try
        {
            workbooks.open(filename);
        }
        catch (Exception::Error)
        {
            throw error("File cannot be opened.");
        }
        workbook = workbooks.item(1);
        worksheets = workbook.worksheets();
        worksheet = worksheets.itemFromNum(1);
        cells = worksheet.cells();
        do
        {
            row  ;
            itemId = cells.item(row, 1).value().bStr();
            name = cells.item(row, 2).value().bStr();
            info(strfmt('%1 - %2', itemId, name));
            type = cells.item(row 1, 1).value().variantType();
        }
        while (type != COMVariantType::VT_EMPTY);
        application.quit();

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    307,709 Super User 2026 Season 2 on at

    Hi Saoudi,

    Can you tell what EPPlus is and what error you get?

    The SysExcelApplication was an implementation used for AX2012. That was using the client application API which is not possible with a cloud solution. In Dynamics 365 F&O you can work with OpenOfficeXml to read Excel files.

    There are examples on the internet how to use it in Dynamics 365 like this post: Import records from Excel using X++ code in D365FO - Dynamics 365 Finance Community

  • Martin Dráb Profile Picture
    241,353 Most Valuable Professional on at

    EPPLus is a .NET library for working with .xlsx files. It doesn't support the old format (.xls).

    Can't you convert your files to .xlsx?

  • Saoudi Hatem Profile Picture
    45 on at

    goshoom no I don't find a way to.

    I would be eternally grateful if you could help me.

  • Martin Dráb Profile Picture
    241,353 Most Valuable Professional on at

    Unfortunately I'm not sure what you need from me.

    My guess it that you:

    1) Insist on using EPPlus, despite the fact that it can't work with your files.

    2) You can't get files in the newer format.

    3) You want to do the conversion in code.

    Is that correct?

  • Saoudi Hatem Profile Picture
    45 on at

    Yes that is what I want

  • Martin Dráb Profile Picture
    241,353 Most Valuable Professional on at

    There are some .NET APIs you could use. Check out How to convert xls file to xlsx file using C#?, for example.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 539 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 431 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 184

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans