The IndentationControls property is widely used to generate indented Tree View pages, and you can learn about it here: https://docs.microsoft.com/en-us/dynamics-nav/indentationcontrols-property.
In some scenarios, where you need more flexibility and dynamically populate the tree view, you would set the page property ShowAsTree to FALSE and disable the Excel Add-In to fall back to the original Style Sheet Excel export.
At the bottom of this blog post, you’ll find a link to an attachment – it’s a simple page loaded just as proof of concept, based on the CRONUS demonstration company in Dynamics NAV 2017.
When this constellation is enabled (IndentationControls + ShowAsTree = FALSE + Excel Add-in disabled), then the generated XML file is created using the Windows UI concept of a viewport which roughly collapses the columns of the three into a single column. If this happens, then an error might be thrown when you export to Excel, as shown in the following screenshot:
And the Excel Error Log would report the following:
XML ERROR in Worksheet Setting REASON: Bad Value FILE: C:\Users\myname\AppData\Local\Temp\Modifica - Tree Buffer5.xml GROUP: Worksheet TAG: Table ATTRIB: ExpandedColumnCount VALUE: 2
The easiest way to resolve this problem is to simply change ShowAsTree = TRUE, but in some development scenarios this might not be possible.
So here is another suitable workaround: Edit the existing style sheet that will allow the export to succeed for that specific page. The only limitation in the proposed XSLT is related to the fact that columns will be indented and the very fist one would export an integer as indentation value.
NOTE: In this example the header value has been hardcoded for an easy understanding.
In a more real scenario, this could be exported, edited, and uploaded again also through code, if and when necessary.
Below you will find a step by step scenario how to reproduce the problem and apply the workaround.
- Import, save and compile Table, Codeunit and Page 51000 Tree Buffer (TreeBuffer.txt)
- Run Page 51000 Tree Buffer
- Press CTRL+E (or Export to Excel)
- Open the Dynamics NAV Windows client, search for “Manage Style Sheet”, and then open the related link
- Set the Show field to Style sheet for a specific page
- Select Page 51000 Tree Buffer
- Click “Import” action and upload the XSLT (PAG51000_Stylesheet.xslt)
- Run page 51000 Tree Buffer
- Press CTRL+E (or click Export to Excel)
Et voila: A magnificent Excel file is served.
These postings are provided “AS IS” with no warranties and confer no rights. You assume all risk for your use.
Duilio Tacconi (dtacconi)
Microsoft Dynamics Italy
Microsoft Customer Service and Support (CSS) EMEA
We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!