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

Excel server export errors on null values

4 Answers 564 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 20 May 2019, 10:31 PM

I'm following the example here: https://demos.telerik.com/aspnet-mvc/grid/server-export

But I'm getting a null pointer if any of the grid values are null. Shouldn't it act like the client export and just put in an empty value?

Is there some workaround for this?

 

 

◢ $exception {"Object reference not set to an instance of an object."} System.NullReferenceException

   at System.Object.GetType()
   at Kendo.Mvc.Export.Helpers.SetCellValue(ICellExporter cell, Object value)
   at Kendo.Mvc.Export.Helpers.CollectionToStream(SpreadDocumentFormat format, IEnumerable data, IList`1 model, String title, Action`1 columnStyleAction, Action`1 rowStyleAction, Action`1 cellStyleAction)
   at Kendo.Mvc.Export.ExportExtensions.ToXlsxStream(IEnumerable instance, IList`1 model, String title, Action`1 columnStyleAction, Action`1 rowStyleAction,

4 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 22 May 2019, 11:06 PM
Hello, Marc,

Thank you for getting in touch to report this behaviour. We have this enhancement already logged and I have now increased its priority. You may follow its progress and find a workaround in this issue:

https://github.com/telerik/kendo-ui-core/issues/4656

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Marc
Top achievements
Rank 1
answered on 23 May 2019, 04:25 PM

Ok, until that change, it would require major refactoring of our models to use the rad streaming library.

Is an accepted workaround to force the client to stream the file through the server via the following code, or are there any know issues with this approach

 

function exportGridToExcel() {
         var grid = $('#@Model.GridName').data('kendoGrid');
         grid.setOptions({
             excel: {
                 fileName: "Export.xlsx",
                 allPages: true,
                 proxyURL: '@Url.Action("Export","Controller")',
                 forceProxy: true              }
         });
         grid.saveAsExcel();
         grid.dataSource.read();
     }

 

 

0
Marc
Top achievements
Rank 1
answered on 23 May 2019, 05:00 PM

Oddly the approach above seems to work unless the grid is groupable. If the groupable option is true. Then I get the following error.

I'm using the latest Kendo library.

 

jquery-1.12.4.js:459 Uncaught TypeError: Cannot read property 'length' of undefined
    at Function.grep (jquery-1.12.4.js:459)
    at ge (kendo.all.js:65612)
    at init._createHeaderCells (kendo.all.js:64143)
    at init._thead (kendo.all.js:64300)
    at init (kendo.all.js:59339)
    at init.setOptions (kendo.all.js:59618)
    at exportGridToExcel (Search:880)
    at HTMLButtonElement.<anonymous> (Search:846)
    at HTMLButtonElement.dispatch (jquery-1.12.4.js:5226)
    at HTMLButtonElement.elemData.handle (jquery-1.12.4.js:4878)

0
Alex Hajigeorgieva
Telerik team
answered on 27 May 2019, 12:53 PM
Hello, Marc,

The Kendo UI Grid can be setup to use the proxy settings in its main configuration.

I am not certain what is the reason to call the setOptions() method, followed by a saveAsExcel() as well as a dataSource read()?

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/configuration/excel

Can you please provide some context in terms of the desired functionality and when the exportGridToExcel method is called so I can suggest a different approach?

Look forward to hearing back from you.

Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Marc
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Marc
Top achievements
Rank 1
Share this question
or