简体   繁体   中英

How to insert a value into a cell without converting it to the desired data type?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM