[英]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.我不熟悉
spreadsheetlight
,但一般原则是显示格式与数据的存储方式无关。 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.假设您使用的是基于时间的显示格式,请在存储之前尝试将您的输入转换为
DateTime
。
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.这将根据单元格的格式设置显示数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.