Search code examples
kendo-uikendo-asp.net-mvckendo-ui-mvc

Range values extraction in Kendo spreadsheet changes dates to integers


I am using a Kendo spreadsheet to import data from an Excel file so I can plug it into an SQL Server database using Ajax callbacks. The Ajax callbacks work fine, but I have determined that any Date strings are being converted to an integer offset from a base date of 12/30/1899. I have submitted a support ticket to Telerik, but they do not seem to understand the problem.

The data is displayed in the Kendo spreadsheet appropriately as a date. Kendo converts a date input as "12/1/2015" to "12-1-2015".

I am using the latest version of the ASP.NET MVC 5 wrapper, but the JavaScript code is the 2016-1-226-545 version of the JavaScript. The wrapper version seems to be irrelevant, but later versions of the JavaScript have the gulpfile.js, and this conflicts with the Bundleconfig interface on my ASP.NET MVC 5 project, so I simply work with the last version of the JavaScript that works for my setup.

The spreadsheet I am working with is pretty basic to start:

@(
Html.Kendo().Spreadsheet()
.Name("SiteSlotDataSS")
  .Rows(10)
  .Columns(4).ColumnWidth(100)
  .Sheets(sheets =>
  {
   sheets.Add()
     .Name("Study Data");
  }
  )
)

I use the import option to pull in an Excel spreadsheet and use a simple button with a click event routine to copy the data to a string array to send to the Ajax callback. I have confirmed that the data being sent to the server controller is the same as it is on the client side before being sent. The Date conversion to an integer occurs when the values are extracted from the range.

The code in question that selects the values is:

values = sheet.range("A" + headerRows.toString() + ":" + endRange + (headerRows + rows).toString()).values();

This produces the correct translation of every other column except for columns containing dates.

I tried the following to brute-force the issue, without success:

for (var x = 0; x <= rows; x++) {
    sheet.range("K" + (headerRows + x).toString()).format(kendo.spreadsheet.formatting.date);
}

I could try a date function to convert the date back into the original value, but everyone pretty much knows how Telerik's documentation is a bit skimpy and overall simply a nightmare to find answers to questions with.

What is the solution?

It appears that Kendo Spreadsheet stores the date values as an integer offset from 12/30/1899 in days. I determined the "0" value by entering a date of 1/1/1901 to see what came back, then 1/1/1900. The result of the latter was "2", making the base date 12/30/1899. Taking the data and converting it at the server seems to be the best option. I don't really expect much of a response from Telerik.


Solution

  • I have addressed the storage issue with Telerik, and they have acknowledged there is a bug in the spreadsheet widget.

    For now, the solution is to bring the values array one row at a time back to the server and do the data conversion server-side. The integer that is returned in the values array for dates is the way the Kendo Spreadsheet stores the information client-side. Formatting the column simply will not do anything but change the client-side display. It will not change how Kendo returns the values matrix from the spreadsheet range selected.