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

How to create a downloadable excel template (XML file) using X++

(0) ShareShare
ReportReport
Posted on by 15

how to create a downloadable excel file(xml) as a template in D365 Finance and OPeration using X++ in visual studio. Im planning to put the codes in a button(get template) in order to provide a template for the user. thanks! 

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: How to create a downloadable excel template (XML file) using X++

    Storing the file locally isn't related to the web server (and the code above). It's handled by the web browser on user's machine.

    It's the same as if you're downloading a file from any other web server. You start downloading a file and choose where you want to store it on your local machine, or you have your web browser configured to automatically store downloaded files in a certain folder.

  • Sam Cristobal Profile Picture
    15 on at
    RE: How to create a downloadable excel template (XML file) using X++

    Hi Martin,

    I tried this code out and there is a problem. The file is not saving in localstorage so probably theres an issue, I dont know if it is the code itself or it needs some functions that can download a file.

  • Verified answer
    Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: How to create a downloadable excel template (XML file) using X++

    There are two separate requirements:

    1. To generate a XLSX file. First of all, ask yourself whether it must be generated in code and you can't simply upload and store the template somewhere. If you need to generate template based on some data at runtime, use OfficeOpenXml.ExcelPackage:
      using OfficeOpenXml;
      
      ...
      
      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 = 'It works';
      	
      		package.Save();
      	}
      }
    2. To allow the user to download the file. Use File::SendFileToUser() for that. For example:
      File::SendFileToUser(stream, 'data.xlsx');
  • Sam Cristobal Profile Picture
    15 on at
    RE: dynamics 365 Finance and Operation-How to create a downloadable excel template (XML file) using X++

    Hi Ms Judy Jee,

    Good day! I want to generate an xlsx file where the user can use as a template/format for sales quotation, and I want to save it automatically in a localdirectory once the user downloaded it.

  • huijij Profile Picture
    19,811 on at
    RE: dynamics 365 Finance and Operation-How to create a downloadable excel template (XML file) using X++

    Hi Sam,

    Would you specify whether you want to create an excel file (xls or xlsx) or an xml file? These are two different file types. You may give more details for your requirements.

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

#2
Martin Dráb Profile Picture

Martin Dráb 597 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans