【发布时间】:2021-06-03 15:27:10
【问题描述】:
我正在使用 TemplateEngine.Docx,模板引擎用于在 Visual Studio for C# 中生成 Word docx。基本上,我正在尝试使用 for 循环将多行添加到已编辑的 Word 文档中的表中。但是,当我遍历 if 语句时,它只会重写刚刚读取的数据。这是我的代码:
if (fieldName == "examrubric")
{
for (; ; )
{
Console.WriteLine("To enter a row to the tabel type 'yes'\n");
string choice = Console.ReadLine();
if (choice == "yes")
{
Console.WriteLine("Enter a value for the question number:\n");
string qnum = Console.ReadLine();
Console.WriteLine("Enter a value for what the question is out of:\n");
string score = Console.ReadLine();
Console.WriteLine("Enter a value for how much was scored:\n");
string qscore = Console.ReadLine();
Console.WriteLine("Enter a value for score:\n");
string score2 = Console.ReadLine();
Console.WriteLine("Enter the total mark:\n");
string total = Console.ReadLine();
valuesToFill = new Content(
new TableContent("examrubric")
.AddRow(
new FieldContent("qnum", qnum),
new FieldContent("score", score),
new FieldContent("qscore", qscore),
new FieldContent("score2", score2),
new FieldContent("total", total)));
}
else
{
break;
}
}
}
【问题讨论】:
标签: c# .net visual-studio openxml