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, ...
Answered

Export to XLS file: file format and extension don't match

(4) ShareShare
ReportReport
Posted on by 557
Hi all, I am trying to export data to an xls file. It is supposed to export correctly but when I open the file I get the following message: 
 
How can i fix this problem, because i would like to open the file without this warning  and that the information is already structured without being divided by ‘,’.
To export im using this config variables:
Where stream is UnicodeEncoding
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    235,928 Most Valuable Professional on at
    Export to XLS file: file format and extension don't match
    We'd need to know more about your scenario before we can suggest how to filter the entity data. Because it's a different topic than Export to XLS file: file format and extension don't match, please create a new thread and explain your requirements there.
  • Jesús García Profile Picture
    557 on at
    Export to XLS file: file format and extension don't match
    Thank you for your recommendations, i chose to try Data Entity, looking for examples on Internet, but most of them use DMF and well, the exportation works but I would like to know if I can, from an entity I create, use my queryRun to export the data based on the filters it has and then export it.
  • Verified answer
    Martin Dráb Profile Picture
    235,928 Most Valuable Professional on at
    Export to XLS file: file format and extension don't match
    What you should do depends on what you need to achieve. What is the actual business requirement?
     
    You can't meaningfully generate files in the old Excel format, but you could use the new one (.xlsx). Nevertheless it would require throwing away your current solution and starting from scratch. The question is why you've written code for exporting CSV if you don't want CSV. Maybe you do want CSV and the idea of using XLS is a wrong one.
     
    If you want to generate XLSX in F&O, you have two options:
    1. The best approach would be using a data entity instead of writing your own export code. Then you can also change the format (CSV, Excel, XML...) by using a different configuration of your project, which gives you extra flexibility.
    2. You can use EPPlus library to generate an Excel spreadsheet. For example: 
      using OfficeOpenXml;
      
      class TextWrapDemo
      {
          public static void main(Args _args)
          {
              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
              {
                  using (var package = new ExcelPackage(stream))
                  {
                      ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet1");
                  
                      ExcelRange cell = worksheet.Cells.get_Item(1,1);
                      cell.Value = 'abcd';
                  
                      package.Save();
                  }
                  File::SendFileToUser(stream, 'data.xlsx');
              }
          }
      }
       
     
  • Jesús García Profile Picture
    557 on at
    Export to XLS file: file format and extension don't match
    So, knowing that I'm doing it wrong, how should I do it? If it is done differently, I don't know because I have always done it this way.
  • Martin Dráb Profile Picture
    235,928 Most Valuable Professional on at
    Export to XLS file: file format and extension don't match
    Your code creates a text file, not an .xls file. You won't change the format of data just by renaming the file.
  • Jesús García Profile Picture
    557 on at
    Export to XLS file: file format and extension don't match
    Well, when i open the xls file, i have this info:
     
     
    When i was exporting in CSV extension the file was opened with the structured information, without the ‘,’, like this:
     
     
     
    So, what i want to do is mantain the structure of second image but changing the extension from csv to xls.
    And that is the code i developed to export csv file. 
     
     
  • Martin Dráb Profile Picture
    235,928 Most Valuable Professional on at
    Export to XLS file: file format and extension don't match
    Please either confirm what data you have in the file or show us how you generate the file.
  • Jesús García Profile Picture
    557 on at
    Export to XLS file: file format and extension don't match
    Sorry, this comment is an error because in the past, i exported the files in csv extension but now i want to change it to xls
  • Martin Dráb Profile Picture
    235,928 Most Valuable Professional on at
    Export to XLS file: file format and extension don't match
    Your code comment says "Export csv file", while the extension is .xls, which are indeed two different things. Please confirm what data you have in the file.

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 775 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 634 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans