-2

I insert the values ​​obtained from the database into the cells. To numeric values ​​and DataTime values, the “'” character is added.

I do not have the opportunity to check each value and bring it to the desired type. The data is always different. The cell format is already defined in the cells of the worksheet.

How to insert data without changes, without placing char “'” ?

Code example:

document.SetCellValue(rowIndex, columnIndex, stringValue);

Result:

enter image description here

Thanks for helping me.

KDV
  • 1
  • 1

1 Answers1

0

I'm not familiar with spreadsheetlight, but the general principal is that the display format is independent of how the data is stored. You need to convert your input to the correct data type. The leading ' can be used to override automatic data conversion if the cell type is general. Assuming the you are using a time based display format try converting your input to DateTime before storing.

There are many ways of doing this. see here for more information.

One method is

string stringDate = "05/05/2019 00:31:00";
DateTime realDate = Convert.ToDateTime(stringDate );
document.SetCellValue(rowIndex, columnIndex, realDate);

This will then display the data according to the format setting of the cell.

Peter Smith
  • 5,528
  • 8
  • 51
  • 77
  • I thought about this solution, but unfortunately this problem is not solved so. 1) I always have different data and quantity. Checking each value for long.TryParse () / DateTime.TryParse () / TimeSpan.TryParse () is not effective. 2) In this example, the value type is TimeSpan. The SetCellValue method does not overload with a TimeSpan type – KDV Jul 15 '19 at 15:12
  • I suspect that the only reliable solution is to check each data type ans set the format appropriately. Adding the prefix is not reliable. – Peter Smith Jul 15 '19 at 15:25