Ticket T668759
Visible to All Users

DataGrid - Unable to export tabulation symbols to Excel

created 7 years ago (modified 7 years ago)

Hello!

I`m trying to export data from grid to Excel. Some of cells store the tabulation symbols (see 'grid.png'). After export I open the excel-file and get the following error (see 'excelError.png'). If you choose any of options, file is openning without data (see 'excelFile.png'). How can I export data with this symbol to Excel?

Thanks.

Show previous comments (4)
ED ED
Elena Dovbenko 7 years ago

    Hi Artem,

    In your screenshot this symbol is displaying like a square (quadrangle) in the grid. It`s a tab character, I paste it from my project to this example (if you move on middle dot in this example: https://codepen.io/anon/pen/eLWJbJ?editors=1010 you see "\u7" - tab character). After that I exporting data from grid and appears the same problem with Excel file. Can you copy this symbol from the example above to your example or modify this example and research it?

    Thank you for your help!

    Artem (DevExpress Support) 7 years ago

      Thank you for the clarification. I forwarded this issue to our R&D team for further research. Please bear with us.

      ED ED
      Elena Dovbenko 7 years ago

        Thank you, waiting for your answer.

        Answers approved by DevExpress Support

        created 7 years ago (modified 5 years ago)

        Hi Elena,

        We researched this scenario and found that the ''\u0007' symbol is not a valid format for XML documents by default. Please review Why are “control” characters illegal in XML 1.0? and Invalid Characters in XML for more details. Currently, our exporting mechanism (it internally creates an .xml document that is exported as an Excel file) doesn't have a specific logic to process such symbols. So, this case requires us to implement a custom processing mechanism that will check each cell and parse a string in a different manner if it contains specific symbols. This is not a quick task, and requires a significant amount of time and resources. While I cannot promise any estimates for this improvement, we'll definitely take this case into account for further development.

        Currently, the only solution is to manually remove such symbols before export using the customizeExportData callback. For example, you can use the approaches described at Avoid illegal xml characters with javascript and Detect non valid XML characters (javascript) to check if a cell value contains special symbols.

        Apart from this, we also noticed that the '\u0007' symbol equals ' - BEL'  (see https://en.wikipedia.org/wiki/ASCII ). The 'Tab' symbol has the '\u0009' code and works fine according to my tests. For instance, check the following example - https://codepen.io/ArtemDevExpress/pen/NLgqJG
        Anyway, at the moment, the most reliable approach is to remove such symbols before export to avoid errors when a document is opened in Excel.

        Let us know if you have additional questions.

        See also:

          Comments (2)
          ED ED
          Elena Dovbenko 7 years ago

            Hi Artem,

            Thank you very much for your trying!

            DevExpress Support Team 5 years ago

              Hi,
              Another approach is to call exportDataGrid instead of the default export. exportDataGrid uses ExcelJS. ExcelJS converts 0x0007/0x000b symbols (invalid XML symbols) to ' ' (space, 0x20) and encodes xml symbols like '<'/'>' to </>
              To cancel the default export, use onExporting and turn on cancel:

              JavaScript
              onExporting: e => { var workbook = new ExcelJS.Workbook(); var worksheet = workbook.addWorksheet('Main sheet'); /* The 'DevExpress.excelExporter.exportDataGrid' function uses the ExcelJS library. For more information about ExcelJS, see: - https://github.com/exceljs/exceljs#contents - https://github.com/exceljs/exceljs#browser */ DevExpress.excelExporter.exportDataGrid({ component: e.component, worksheet: worksheet, }).then(function() { workbook.xlsx.writeBuffer().then(function(buffer) { saveAs(new Blob([buffer], { type: "application/octet-stream" }), "DataGrid.xlsx"); }); }); e.cancel = true; },

              Here is a jQuery based sample that illustrates this approach.

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.