我尝试将一些段落自动放入 Word 文档中,但它总是将其放在文档的末尾,而不是放在书签中。
public void createStepTable(Word.Document _myDoc, DataGridView dgv, Testcaselist _testcaselist)
{
int namecount = 1;
object oMissing = System.Reflection.Missing.Value;
Word.Bookmark myBookmark = _myDoc.Bookmarks.get_Item("TextMarkeEinzelheiten");
MessageBox.Show(myBookmark.Start.ToString());
Word.Range myRange = _myDoc.Range(myBookmark.Start,myBookmark.End);
Word.Field myfield = _myDoc.Fields.Add(myRange);
Word.Selection mySelection = myRange.Se
foreach (Testchannellist testChannelListToFind in _testcaselist.Testchannellist)
{
Word.Paragraph pText = _myDoc.Paragraphs.Add(myRange);
pText.Format.SpaceAfter = 10f;
pText.Range.Text = String.Format("This is headline #{0}",namecount);
pText.Range.InsertParagraphAfter();
int stepcount = 0;
foreach (Teststeplist testStepListToFind in testChannelListToFind.Teststeplist)
{
var sText = _myDoc.Paragraphs.Add(myRange);
sText.Format.SpaceAfter = 10f;
sText.Range.Text = String.Format("This is testfall #{0}", stepcount);
sText.Range.InsertParagraphAfter();
for (int i = 0; i < testStepListToFind.requirementlist.Count; i++)
{
var rText = _myDoc.Paragraphs.Add(myRange);
rText.Range.ListFormat.ApplyBulletDefault();
rText.Range.InsertBefore(testStepListToFind.requirementlist[i].ToString() );
}
dgv.DataSource = testStepListToFind.repTest;
var tText = _myDoc.Paragraphs.Add(myRange);
tText.Format.SpaceAfter = 10f;
tText.Range.Text = String.Format("This is Tabelle #{0}", stepcount );
tText.Range.InsertParagraphAfter();
stepcount++;
}
}
}
所有那些自动创建的段落都应该在“TextMarkeEinzelheiten”书签中,但每次尝试都会一团糟。