Category: X++ Development, D365FO Reporting
Exporting data to Excel is a frequent requirement in many D365FO implementations, especially for business users who want to slice and dice the data offline. This article walks you through how to export data to Excel directly from X++ without saving it on the local disk — just stream and go!
✅ Scenario
We’ll create an Excel report from a custom or standard D365FO table (like PurchParmLine
) and allow the user to download it through the UI using the DocuFileSave
utility.
💡 Final Output
-
Excel file generation using
OfficeOpenXml
-
In-memory streaming
-
Download via browser — no physical file save
✅ X++ Code: Modern Version
🔍 Notes:
-
This version uses renamed buffers like
parmLineBuffer
andexportLine
instead of reusing the same ones. -
DocuFileSave::promptForSaveLocation
prompts the user for download — so no local server path issues! -
System.IO.MemoryStream
handles file creation in memory without file system dependency.
📌 Conclusion
This approach keeps your export logic clean, avoids unnecessary local file dependencies, and keeps users happy with a simple, browser-based download prompt.
0 Comments