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

Excel Export - Unreadable Data

2 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kurt Kluth
Top achievements
Rank 1
Kurt Kluth asked on 20 Dec 2016, 10:04 PM

We currently output our data to a Grid and then export to XLSX, however we are experiencing a unique problem with one of the records.  The record in question returns the word "Infinity" and it causes a problem with opening the Excel document.  We receive the following error message:

"Excel found unreadable content in '....aspx'.  Do you want to recover the contents of this workbook?  If you trust the source of this workbook, click Yes."

Clicking Yes will repair the worksheet.  

After doing much testing to narrow down what record it is failing on, we have concluded it is failing on this record with the word "Infinity".  If I change the database record to "Infinity CU", there is no problems and the Excel file will open properly.  If I save the Excel document after all these messages, it will save properly and once reopened it will be successful.  CUName is the field that it fails on. 

I am including the code that displays the grid but might you offer a suggestion on how to remedy this problem?

<telerik:RadGrid ID="_grdInvisibleGridForExcel" runat="server" Visible="false" HeaderStyle-Font-Bold="true" HeaderStyle-BackColor="#4F9A25" HeaderStyle-ForeColor="White"  CellSpacing="-1" GridLines="Both" GroupPanelPosition="Top" AutoGenerateColumns="false" ExportSettings-Excel-Format="ExcelML">
            <MasterTableView>
                <Columns>
                    <telerik:GridDateTimeColumn DataField="Financial Date" HeaderText="Financial Date" UniqueName="FinancialDate" FilterControlAltText="Filter FinancialDate column"></telerik:GridDateTimeColumn>
                    <telerik:GridBoundColumn DataField="charter_Num" HeaderText="Charter #" UniqueName="CharterNum" FilterControlAltText="Filter CharterNum column"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="asi_Num" HeaderText="ASI #" UniqueName="AsiNum" FilterControlAltText="Filter AsiNum column"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="cuName" HeaderText="CU Name" UniqueName="cuName" FilterControlAltText="Filter cuName column"></telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 23 Dec 2016, 01:27 PM
Hi Kurt,

We will investigate this further to fix it if it happens to be a bug.

Meanwhile you may want to set string format to cells belonging to your bound columns based on this example code:
http://www.telerik.com/forums/format-data-when-exporting-to-excel-in-xlsx-format#3AsGnPiIDkCn92CVTOdzPg
protected void RadGrid1_InfrastructureExporting(object sender, GridInfrastructureExportingEventArgs e)
{
    var rows = e.ExportStructure.Tables[0].Rows;
    var rowCount = rows.Count;
    for (int rowIndex = 1; rowIndex <= rowCount; rowIndex++)
    {
        for (int i = 2 /* starting for second since your first column is datetime*/; i <= rows[rowIndex].Cells.Count; i++)
        {
            rows[rowIndex].Cells[i, rowIndex].Format = "@";
        }
    }
}


Regards,
Vasil
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Kurt Kluth
Top achievements
Rank 1
answered on 23 Dec 2016, 01:50 PM

Vasil,

Thank you for the response and we will have to keep this information in mind.  Would this still work if after the 1st 4 columns (not supplied) contained numbers and currency fields?

We ended up rewriting the report using Telerik Reporting and sending the output to Excel and it solved our needs but glad to know we could have solved the problem just a simply using this method.

Tags
Grid
Asked by
Kurt Kluth
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Kurt Kluth
Top achievements
Rank 1
Share this question
or