0

我有一个提出问题的表格,你在文本框中写下答案。当您点击“下一步”或“添加”时,它应该保存输入并像这样循环,直到您点击保存。无论出于何种原因,它只保存一行而不是后续行。这是我的代码。

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);
    }
4

1 回答 1

2

不确定我是否理解正确。从您的代码中,我发现每次添加新部分时,都会将每个问题和答案添加到文档的新部分中。如果这是问题所在,您可以尝试以下代码:

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");
}

希望能帮助到你。

于 2017-09-20T09:37:29.177 回答