2

特定のポイントからWord文書を読み始める必要があります。そのキーワードは、ドロップダウンコンボボックスから取得されます。キーワードは[何とか何とか、何とか、001]のようなものです

だから、私はそのキーワードから次の見出しまでのコンテンツだけを読む必要があります...

私はこれを使用して見出し番号と行ごとを読み取りましたが、見出し番号が機能していません

string headNum = objparagraph.Range.ListFormat.ListString;
string sLine = objparagraph.Range.Text;
4

2 に答える 2

2
       Word.Application word = new Word.Application();
       Word.Document doc = new Word.Document();
       object fileName = @"C:\wordFile.docx";
        // Define an object to pass to the API for missing parameters
        object missing = System.Type.Missing;                
        doc = word.Documents.Open(ref fileName,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing);
        string ReadValue = string.Empty;
            // Activate the document
        doc.Activate();

         foreach (Word.Range tmpRange in doc.StoryRanges)
         {
            ReadValue += tmpRange.Text;
         }
于 2013-02-25T13:35:59.500 に答える
0

私が正しく理解していれば、あなたはあなたのキーワードから次の見出しまでWord文書を読む必要があります。言い換えれば、次のドキュメントの赤いテキストのようなものです。

ここに画像の説明を入力してください

その場合、GemBox.Documentを使用してこれを実現する方法は次のとおりです。

string keyword = " [blah blah, blah, 001]";
DocumentModel document = DocumentModel.Load("input.docx");

ContentPosition start = document.Content
    .Find(keyword)
    .First()
    .End;

ContentPosition end = new ContentRange(start, document.Content.End)
    .GetChildElements(ElementType.Paragraph)
    .Cast<Paragraph>()
    .First(p => p.ParagraphFormat.Style != null && p.ParagraphFormat.Style.Name.Contains("heading"))
    .Content
    .Start;

string text = new ContentRange(start, end).ToString();

text変数の値は次のようになります。

取得するサンプルテキストコンテンツ。
別のサンプル段落。

また、ここに追加の読書コンテンツの取得の例があり、それらにはいくつかの有用な情報が含まれています。

于 2019-12-04T11:03:21.777 に答える