2017-09-18 13 views
0

나는 질문을하고 당신이 텍스트 상자에 대답을 쓰는 양식이 있습니다. '다음'또는 '추가'를 누르면 저장을 클릭 할 때까지 입력 내용을 저장하고주기를 수행해야합니다. 어떤 이유에서 건 그것은 한 줄만 저장하고 후 줄은 저장하지 않습니다. 내가 가진 코드는 다음과 같습니다.Spire.Doc, 입력 저장 이전 입력, Windows 양식을 덮어 씁니다.

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

답변

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

희망이 있습니다.

+0

이것은 작동합니다. 유일한 문제는 텍스트를 다음 줄로 옮기는 것입니다. AddSection()을 사용하여 시도했지만 그 대답은 아닌 것 같습니다. – TomG103

+0

다음과 같이 단락에 줄 바꿈을 추가 할 수 있습니다. paragraph.AppendBreak (BreakType.LineBreak); –

+0

나는 Spire를 사용하지 않기로 결정했습니다. Interop.Word를 사용하는 것보다 더 많은 코드가 작성되어 결국 모든 문서에서 데모의 빨간색 텍스트가 표시되지 않습니다. – TomG103