首页 > 解决方案 > 如何将整数或十进制数插入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 ,我会得到像第二个屏幕截图一样的建议。伙计们请帮我解决这个问题。

标签: c#openxml

解决方案


CellValue有两个构造函数一个是默认的另一个是参数化CellValue(String)。因此,您需要将参数转换为string值。

int number = 90;
CellValue cl = new CellValue(Convert.ToString(number));

推荐阅读