admin管理员组文章数量:1206015
I'm trying to replace the value in column A of an excel with the concatenated string from column A and B combined. I'm looping through the rows to do this but I always get that the string is not in the correct format.
Loop is below:
foreach (Row r in rows.Skip(1))
{
string x = r.Elements<Cell>().ElementAt(0).InnerText;
string y = r.Elements<Cell>().ElementAt(1).InnerText;
string xy = x + '_' + y;
r.Elements<Cell>().ElementAt(0).CellValue = new CellValue(xy);
}
If I replace the last line with either
r.Elements<Cell>().ElementAt(0).CellValue = new CellValue(y);
r.Elements<Cell>().ElementAt(0).CellValue = new CellValue(x);
It works as I'd expected however when joining the strings it doesn't.
I also tried the below:
foreach (Row r in rows.Skip(1))
{
string x = r.Elements<Cell>().ElementAt(0).InnerText;
string y = r.Elements<Cell>().ElementAt(1).InnerText;
string xy = x + '_' + y;
Cell cell = r.Elements<Cell>().ElementAt(0);
cell.CellValue = new CellValue(xy);
cell.DataType = new EnumValue<CellValues>(CellValues.String);
}
This runs but gives me numbers concatenated together rather than the strings I can see when opening the file.
本文标签: cCombining strings in excel Using DocumentFormatOpenXmlStack Overflow
版权声明:本文标题:c# - Combining strings in excel Using DocumentFormat.OpenXml - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738690740a2107089.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论