We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

IndexOutOfRangeException when Exporting ASP.NET MVC Grid to Excel With Column With Format Specified

Thread ID:





125412 Aug 16,2016 01:44 AM UTC Aug 18,2016 01:04 PM UTC ASP.NET MVC 5
Tags: Grid
Jeffrey Stone
Asked On August 16, 2016 01:44 AM UTC

I am exporting a grid to Excel and I am receiving the following error:
Index was outside the bounds of the array.
Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:
Line 133:            exp.Export(gridProperties, rows, fileName, ExcelVersion.Excel2010, true, false, "default-theme", false);

As soon as I remove the following column the error goes away:
col.Field(r => r.Symbol).Format("<a class='symbol'>{Symbol}</a>").Add();

How can I get the grid to export (the format in this case is not important).

Regards, Jeff

Mani Sankar Durai [Syncfusion]
Replied On August 16, 2016 01:31 PM UTC

Hi Jeffrey, 

Thanks for contacting Syncfusion support, 

We are unable to reproduce the issue at our end. Please refer the following documentation and online link on how to export the grid, 
We have also prepared a sample that can be downloaded from the following location.  
Please share the following details, 
1)      Code example of Grid and code behind  
2)      If possible modify the attached sample and replicate the issue.  
The provided information will help us to analyze the issue and provide you the response as early as possible, 

Manisankar Durai. 

Jeffrey Stone
Replied On August 16, 2016 03:06 PM UTC


I had trouble using the attached sample (wrong version of SQL Sever - I have 2014).

Would you be able to change the .Format("{0:C}") to .Format("<a class='symbol'>{Freight}</a>") ?

(I can confirm that .Format("{0:C}") works - as I use it on other columns - while .Format("<a class='symbol'>{Freight}</a>") does not work)

Regards, Jeff

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On August 17, 2016 11:29 AM UTC

Hi Jeffrey, 

We suspect that you would like to place the value in the anchor tag. To define the html elements or other controls, we have template column support which will place any element. Refer to the following code example. 

              . . . 
                .Columns(col => 
                . . . 
                    .Template("<a class='clas'>{{:Freight}}</a>").Add(); 

To include the template column in the exported file, you have to enable isTemplateColumnInclude parameter in the export(). To bind the template column with the mentioned anchor tag, we have used the ServerExcelQueryCellInfo event. Refer to the following code example. 

        public void ExportToExcel(string GridModel) 
            ExcelExport exp = new ExcelExport(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            var DataSource = OrderRepository.GetAllRecords().ToList(); 
            obj.ServerExcelQueryCellInfo = queryCellInfo; 
            exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, true/*template columns include*/, "flat-saffron",false); 
        public void queryCellInfo(object currentCell) {  
            IRange range = (IRange)currentCell; 
            if (range.Column == 3) {// here 3 is the index of Freight/Template columns 
                range.Value = "<a class='symbol'>" + range.Value + "</a>"; 

Note: To populate the template column with the data, you have to mention the field in the columns. 

Refer to the following Help Documents. 

Seeni Sakthi Kumar S. 

Jeffrey Stone
Replied On August 17, 2016 02:31 PM UTC


Thanks. Moving the <a> tag from the Format to the Template worked.

Is there documentation that better explains what the parameters do on ExcelExport.Export?

Regards, Jeff

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On August 18, 2016 01:04 PM UTC

Hi Jeffrey, 

Currently, we don’t have Help Document explaining Export Overload methods. So we have logged a task on it and we will add the Export Overload methods in Exporting sections of following Help Document.  

Seeni Sakthi Kumar S. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon