This is a migrated thread and some comments may be shown as answers.

Excel Export data starting with a dash creates invalid format or file extension error

2 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 11 Jul 2018, 03:53 PM

When my RadGrid is exported to Excel, if one of the cell's data begins with a dash (-), I get the error message "Excel cannot open the file because the file format or file extension is not valid..." see in the attached Error.png.  If I remove leading dashes from the data by updating the database, or remove leading dashes in code before binding it to the grid, the grid exports as expected.  However this is not an sustainable or ideal solution.

- I have tried setting the excel export to Xlsx, Html, Biff and ExcelIML in both cs code and in the designer (also tried each independent of each other):

            AuthGrid.ExportSettings.Excel.Format = GridExcelExportFormat.Xlsx;
            AuthGrid.MasterTableView.ExportToExcel();

            <ExportSettings>
                <Excel FileExtension="xlsx" Format="Xlsx" />
            </ExportSettings>

- I have tried notes.DataFormatString = "{0}"; and notes.DataFormatString = "&nbsp;{0}";

I started with a slightly older version of these dlls, but also tried upgrading to newer versions:

- Telerik.Web.Spreadsheet version 2016.3.913.40 (upgraded to 2018.3.620.40)

- Telerik.Web.UI version 2016.3.914.45 (upgraded to 2018.2.710.45)

- Telerik.Web.UI.Skins version 2016.3.914.45 (upgraded to 2018.2.710.45)

- Telerik.Windows.Documents.Core version 2016.3.913.40 (upgraded to 2018.2.619.40)

- Telerik.Windows.Documents.Fixed version 2016.3.913.40 (upgraded to 2018.2.619.40)

- Telerik.Windows.Documents.Flow version 2016.3.913.40 (upgraded to 2018.2.619.40)

- Telerik.Windows.Documents.Spreadsheet version 2016.3.913.40 (upgraded to 2018.2.619.40)

- Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXML version 2016.3.913.40 (upgraded to 2018.2.619.40)

- Telerik.Windows.Zip  version 2016.3.913.40 (upgraded to 2018.2.619.40)

2 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 11 Jul 2018, 04:42 PM
Hi Phil,

The minus sign can be treated as a formula beginning and that may be causing Excel to show warnings. The following article shows several ways you can remove such content when exporting so you don't have to touch the actual data: https://www.telerik.com/support/kb/aspnet-ajax/grid/details/we-found-a-problem-with-this-formula-when-exporting-to-xlsx.


Regards,
Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Edward
Top achievements
Rank 1
Veteran
Iron
answered on 06 May 2021, 01:44 PM

I my case, I was getting “Invalid XLS File Format”error each time I tries to open my Excel file. After searching a lot about this error, I finally got this informative post. I hope the solution given I this post will work in your case also.

 

SOURCE:  Fix invalid file format error

Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Edward
Top achievements
Rank 1
Veteran
Iron
Share this question
or