简体   繁体   English

如何使用 c# 在 word 文件中处理范围内的列表

[英]How to work on a list in a range in a word file using c#

I am trying to edit a word document using word automation.我正在尝试使用 word 自动化来编辑 word 文档。 In the document, there is a list of references that I want to verify and edit one by one.在文档中,有一个参考列表,我想一一验证和编辑。 I have selected the references part in a range and now I want to loop through the list.我选择了一个范围内的引用部分,现在我想遍历列表。

object start = new Regex(@"(References)\s*:?\s*").Match(wordText).Index;
        object end = wordText.Length;

        Word.Range rngRef = doc.Range(start,end);

This is how I have selected range, now how do I select list and loop through the items?这就是我选择范围的方式,现在我如何 select 列出并循环遍历项目?

I depend how the ordered list is exactly 'formatted' in Word.我取决于有序列表在 Word 中是如何“格式化”的。 If this is just a number of paragraphs one could do (to get the text from the paragraphs):如果这只是一些可以做的段落(从段落中获取文本):

int i = 0;
var paragraphs = rngRef.Paragraphs;
foreach (Word.Paragraph item in paragraphs)
{
     Console.WriteLine("{0}: {1}", ++i, item.Range.Text);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM