我有一个问问题的表格,你在文本框里写一个答案。当你点击‘下一步’或‘添加’,它应该保存输入和循环像这样,直到你点击保存。无论出于什么原因,它只保存一行,而不保存后续行。这是我的密码。
private void add_Click(object sender, EventArgs e)
{
Paragraph question = document.AddSection().AddParagraph();
question.AppendText(questions.Text + " " + answer.Text);
document.SaveToFile(teamMember.Text + ".doc", FileFormat.Doc);
}
private void finish_Click(object sender, EventArgs e)
{
document.SaveToFile(teamMember.Text + ".doc", FileFormat.Doc);
}发布于 2017-09-20 09:37:29
不知道我是否正确地理解了你。从您的代码中,我发现每次添加新的部分时,都会将每个问题和答案添加到文档的一个新部分中。如果这是问题所在,您可以尝试以下代码:
if (doc.Sections.Count == 0)
{
//If the document is null, then add a new section
Section sec = doc.AddSection();
Paragraph para = sec.AddParagraph();
para.AppendText("this is the first para");
}
else
{
//Else add the text to the last paragraph of the document
Paragraph paranew = doc.Sections[0].Paragraphs[doc.Sections[0].Paragraphs.Count - 1];
paranew.AppendText(" " + "this is new para");
}希望能帮上忙。
https://stackoverflow.com/questions/46286785
复制相似问题