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

Notifications

Announcements

No record found.

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! 

  • Verified answer
    Martin Dráb Profile Picture
    225,155 Moderator 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
    225,155 Moderator 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,801 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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

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

Product updates

Dynamics 365 release plans