【发布时间】:2020-08-13 11:45:52
【问题描述】:
我正在寻找有关将数据写入 Excel 工作表的代码的帮助。 我目前正在一次将数据写入单个单元格,每个单元格大约需要三秒钟。正如你可以想象的那样,当你开始进入数百个单元格时,这个时间真的开始加起来了。
我知道有一种方法可以保存到一系列单元格,但不完全确定如何执行此操作。
我要写的文档是一个问卷样式的电子表格,其中包含以下列:数字、问题、是、否、NA。 我遍历一个用户控件列表,其中包含用户从我的表单中选择的答案,然后将其写入单元格。
任何帮助表示赞赏,谢谢。
if (QuestionList.Count > 0)
{
//loop round rows
for (int i = 0; i < QuestionList.Count; i++)
{
//check that index is not null
if (!String.IsNullOrEmpty(QuestionList[i].Index))
{
//if the char in index is a letter
if (Char.IsLetter(QuestionList[i].Index[0]))
{
worksheet2.Cells[i + 1, 4].Value2 = QuestionList[i].Yes;
worksheet2.Cells[i + 1, 5].Value2 = QuestionList[i].No;
worksheet2.Cells[i + 1, 6].Value2 = QuestionList[i].NA;
}
}
}
}
【问题讨论】:
-
为了您的利益,请使用 Open XML SDK 生成 excel
标签: c# excel winforms interop winforms-interop