web
You’re offline. This is a read only version of the page.
close
Skip to main content
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();

I have the same question (0)
  • Martin Dráb Profile Picture
    236,017 Most Valuable Professional on at
    RE: What is the best way to work with xls files (x++)

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

  • Saoudi Hatem Profile Picture
    45 on at
    RE: What is the best way to work with xls files (x++)

    Yes that is what I want

  • Martin Dráb Profile Picture
    236,017 Most Valuable Professional on at
    RE: What is the best way to work with xls files (x++)

    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
    RE: What is the best way to work with xls files (x++)

    goshoom no I don't find a way to.

    I would be eternally grateful if you could help me.

  • Martin Dráb Profile Picture
    236,017 Most Valuable Professional on at
    RE: What is the best way to work with xls files (x++)

    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?

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    297,929 Super User 2025 Season 2 on at
    RE: What is the best way to work with xls files (x++)

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 814 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 798 Super User 2025 Season 2

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 622

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans