如何使用closedXml将字符串数组添加到工作表

时间:2019-06-06 15:30:36

标签: c# arrays excel closedxml

我有点困惑,试图在c#中使用closedXML将2d [2x4]字符串数组获取到工作表。

我的解决方案适用于整数数组,但是如果我对字符串数组执行相同的操作,它将不起作用。

我要使用以下代码将数据写入Excel工作表:

int[,] test = { { 1, 2, 3, 4 }, { 2, 5, 6, 4 } };
worksheet.Cell(15, 2).InsertData(data: test, transpose: true);

结果:

1 2 3 4

2 5 6 4

->这正是我所期望的。

但是,如果我尝试使用以下方法:

string[,] teststring = { { "a", "b", "c", "d" }, { "e", "f", "g", "h" } };
worksheet.Cell(15, 2).InsertData(data: teststring, transpose: true);

结果:

a b c d e f g h

->所有值都在一行中,我不明白为什么。

有人知道为什么会这样以及如何获得预期的结果吗? (测试字符串的格式是预先确定的,因此不允许更改。)

非常感谢!

0 个答案:

没有答案