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
Manisankar,
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
@(Html.EJ().Grid<object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.dataSource) .AllowPaging() . . . .Columns(col => { . . . col.Field("Freight") .HeaderText("Freight") .Template("<a class='clas'>{{:Freight}}</a>").Add(); }) ) |
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>"; } } |