c# - 如何将整数或十进制数插入openxml单元格
问题描述
Cell cellName = new Cell();
cellName.DataType = CellValues.Number;
cellName.CellValue = new CellValue(10);
//error i'm getting here: "cannot convert int to string"
newRow.AppendChild(cellName);
在这里我收到错误
无法将 int 转换为字符串
如果我string
在 Excel 文件中将相同的值转换为 then ,我会得到像第二个屏幕截图一样的建议。伙计们请帮我解决这个问题。
解决方案
CellValue
有两个构造函数一个是默认的另一个是参数化CellValue(String)
。因此,您需要将参数转换为string
值。
int number = 90;
CellValue cl = new CellValue(Convert.ToString(number));
推荐阅读
- r - 按子组处理 r 中的数据帧:是否可以摆脱“for”循环?
- android - 共享文件 - 找不到新的 Android 10 范围存储限制的解决方案?
- html - CSS:当向左拉和向右拉不起作用时,将搜索按钮内嵌到输入中
- javascript - 使用 Javascript 创建 Base64 转换器
- django - 如何根据用户的字段更改我的 API 请求?
- snowflake-cloud-data-platform - 雪花中无法识别数值“abc_0011O00001y31VpQAI”
- java - 使用 Java SDK 的 Hyperledger Fabric 背书策略错误
- python - 调整日期列(填补日期空白并更新至特定日期)
- python - OpenCV 实时流式视频捕获很慢。如何丢帧或实时同步?
- 4d-database - 在 4D Write Pro (4D v17 R5) 中以编程方式设置文本样式