你好,
我想在整篇文档的中间位置插入一段文本, 使用下面的代码插入了文本, 但不是在新段中插入的,而是追加的, 如何按段的方式插入?
还有个问题就是, 如果是多个节, 下面的只会插到第1节的中间, 怎样准确的在多节的段落中间位置后插入新段文本?
谢谢
```
using Spire.Doc;
// 加载文档
Document document = new Document();
document.LoadFromFile(file.FullName);
Section section = document.Sections[0];
// 获取段落数量
int paragraphCount = section.Paragraphs.Count;
Console.WriteLine($"段落数量:{paragraphCount}");
// 计算插入位置(在所有段落的中央位置插入)
int insertIndex = (int)Math.Ceiling(paragraphCount / 2.0);
Console.WriteLine($"插入位置:{insertIndex}");
// 插入段落文本
string textToInsert = "我是添加的文本";
Paragraph paragraph = section.Paragraphs[insertIndex];
TextRange textRange = paragraph.AppendText(textToInsert);
textRange.CharacterFormat.FontName = "微软雅黑";
textRange.CharacterFormat.FontSize = 14;
```