C# 如何使用C获取word文档中的段落编号?

C# 如何使用C获取word文档中的段落编号?,c#,ms-word,docx,C#,Ms Word,Docx,我使用程序集Microsoft.Office.Interop.Word 我的文档是Microsoft.Office.Interop.Word.document对象,我想获取此文档中每个段落的编号 如何执行此操作?在开始使用Microsoft.Office.Interop.Word库/dll之前,您必须阅读该库的文档 请看这里: 此外,还取决于您使用的Office版本。在开始使用Microsoft.Office.Interop.Word库/dll之前,您必须阅读该库的文档 请看这里: 此外,还取决

我使用程序集Microsoft.Office.Interop.Word

我的文档是Microsoft.Office.Interop.Word.document对象,我想获取此文档中每个段落的编号

如何执行此操作?

在开始使用Microsoft.Office.Interop.Word库/dll之前,您必须阅读该库的文档

请看这里:

此外,还取决于您使用的Office版本。

在开始使用Microsoft.Office.Interop.Word库/dll之前,您必须阅读该库的文档

请看这里:


此外,还取决于您使用的Office版本。

如果您有一个文档对象,那么您已经可以获得文档中每个段落的“编号”或“索引”。例如,如果需要获取文档中第二段的文本,可以说:

MSWord.Application app = (MSWord.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
MSWord.Document doc = app.ActiveDocument; //the document that's on screen and 'active'

Console.WriteLine("Paragraph Count: " + doc.Paragraphs.Count); //show total number of paragraphs available in document.
Console.Write Line("Paragraph number 2 text: " + doc.Paragraphs[2].Range.Text);               //show text of paragraph number 2

Console.ReadLine();

如果这没用的话。请…编辑你的问题。在您澄清之前,我们真的无法对此做任何事情。

如果您有一个文档对象,您已经可以获得文档中每个段落的“编号”或“索引”。例如,如果需要获取文档中第二段的文本,可以说:

MSWord.Application app = (MSWord.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
MSWord.Document doc = app.ActiveDocument; //the document that's on screen and 'active'

Console.WriteLine("Paragraph Count: " + doc.Paragraphs.Count); //show total number of paragraphs available in document.
Console.Write Line("Paragraph number 2 text: " + doc.Paragraphs[2].Range.Text);               //show text of paragraph number 2

Console.ReadLine();

如果这没用的话。请…编辑你的问题。在您澄清之前,我们真的无法对此做任何事情。

您需要这样的东西:

    object misValue = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
    object docPth = @"c:\tmp\aDoc.doc";
    Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref docPth, ref misValue, ref misValue,
        ref misValue, ref misValue, ref misValue, ref misValue, ref misValue, ref misValue, ref misValue,
        ref misValue, ref misValue, ref misValue, ref misValue, ref misValue, ref misValue);
    wordApp.Visible = true;
    foreach (Microsoft.Office.Interop.Word.Paragraph aPar in aDoc.Paragraphs)
    {
        Microsoft.Office.Interop.Word.Range parRng = aPar.Range;
        string sText = parRng.Text;
        string sList = parRng.ListFormat.ListString;
        int nLevel = parRng.ListFormat.ListLevelNumber;
        MessageBox.Show("Text = " + sText + " - List = " + sList + " - Level " + nLevel.ToString());
    }

你需要这样的东西:

    object misValue = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
    object docPth = @"c:\tmp\aDoc.doc";
    Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref docPth, ref misValue, ref misValue,
        ref misValue, ref misValue, ref misValue, ref misValue, ref misValue, ref misValue, ref misValue,
        ref misValue, ref misValue, ref misValue, ref misValue, ref misValue, ref misValue);
    wordApp.Visible = true;
    foreach (Microsoft.Office.Interop.Word.Paragraph aPar in aDoc.Paragraphs)
    {
        Microsoft.Office.Interop.Word.Range parRng = aPar.Range;
        string sText = parRng.Text;
        string sList = parRng.ListFormat.ListString;
        int nLevel = parRng.ListFormat.ListLevelNumber;
        MessageBox.Show("Text = " + sText + " - List = " + sList + " - Level " + nLevel.ToString());
    }

我已经阅读了文档,我使用的是visual studio 2008和框架3.5我已经阅读了文档,我使用的是visual studio 2008和框架3.5当你说每个段落的编号时,你的意思是什么?看看这个:,它是用VB.net制作的。我想对cw做同样的事情,你说每段的数字是什么意思?看看这个:,它是用VB.net制作的。我想对CI做同样的事情,我想做一些类似的事情:但是用C,我想做一些类似的事情:但是用C,我想做一些类似的事情,我想做一些类似的事情:但是用C,我想做一些类似的事情,我想做一些类似的事情