コストを抽出する方法を弾からの情報資料を、wordドキュメント?

StackOverflow https://stackoverflow.com/questions/2302077

  •  21-09-2019
  •  | 
  •  

質問

たい情報を抽出の弾明資料を、wordドキュメント.たいようなこと:その下にテキスト、資料を、wordドキュメント:

手順お車:

  • オープンドア
  • 座内
  • Insertキー
  • など。

その気持ちを抱いて欲しいと思いテキストファイルに以下のように:

手順お車:

<BULET> オープンドア </BULET>

<BULET> 座内 </BULET>

<BULET> 空 </BULET>

<BULET> Insertキー </BULET>

<BULET> など。</BULET>

私C#言語ではないかと思います。

できるエキスパからの資料を、wordドキュメントに直接書きテキストファイルとフォーマットの情報をいかどうかのテキストが大胆には斜体等だから抽出するこ弾。

誰でもできるので教えてくださいい。

かまいません。

役に立ちましたか?

解決 3

私は答えを得た.....

まず私は、段落ごとにドキュメントを変換しました。しかし、その代わりに、我々は、文単位でドキュメントファイルの文を処理する場合、その文が弾丸や形状のか、その文は、テーブルの一部であるかのいずれかの種類が含まれているかどうかを決定することが可能であることを。私たちは、この情報を得ればそう、我々は適切にその文を変換することができます。誰かがソースコードを必要とする場合、私はそれを共有することができます。

他のヒント

あなたはそれぞれの文を読んでそれを行うことができます。 のdoc.Sentences の範囲オブジェクトの配列です。だから、段落から同じRangeオブジェクトを取得することができます。

        foreach (Paragraph para in oDoc.Paragraphs)
        {
            string paraNumber = para.Range.ListFormat.ListLevelNumber.ToString();
            string bulletStr = para.Range.ListFormat.ListString;
            MessageBox.Show(paraNumber + "\t" + bulletStr + "\t" + para.Range.Text);
        }

paraNumberにあなたは段落レベルを取得することができますし、buttetStrに、あなたは文字列として弾丸を得ることができます。

を使用してい この OpenXMLPowerツールエリック-マーティノー(Eric白になります。無料にて承りますNUGetパッケージです。インストールすることができまVisual studioでパッケージマネージャ。enter image description here

彼の提供に使用可能になコードスニペット.このツールに保存していく時間。以下のカスタマイズコードスニペットを使っ必要です。たりのgdpが使用できこれらの方法でご注意願います。

 private static WordprocessingDocument _wordDocument;
 private StringBuilder textItemSB = new StringBuilder();
 private List<string> textItemList = new List<string>();


/// Open word document using office SDK and reads all contents from body of document
/// </summary>
/// <param name="filepath">path of file to be processed</param>
/// <returns>List of paragraphs with their text contents</returns>
private void GetDocumentBodyContents()
{
    string modifiedString = string.Empty;
    List<string> allList = new List<string>();
    List<string> allListText = new List<string>();

    try
    {
_wordDocument = WordprocessingDocument.Open(wordFileStream, false);
        //RevisionAccepter.AcceptRevisions(_wordDocument);
        XElement root = _wordDocument.MainDocumentPart.GetXDocument().Root;
        XElement body = root.LogicalChildrenContent().First();
        OutputBlockLevelContent(_wordDocument, body);
    }
    catch (Exception ex)
    {
        logger.Error("ERROR in GetDocumentBodyContents:" + ex.Message.ToString());
    }
}


// This is recursive method. At each iteration it tries to fetch listitem and Text item. Once you have these items in hand 
// You can manipulate and create your own collection.
private void OutputBlockLevelContent(WordprocessingDocument wordDoc, XElement blockLevelContentContainer)
{
    try
    {
        string listItem = string.Empty, itemText = string.Empty, numberText = string.Empty;
        foreach (XElement blockLevelContentElement in
            blockLevelContentContainer.LogicalChildrenContent())
        {
            if (blockLevelContentElement.Name == W.p)
            {
                listItem = ListItemRetriever.RetrieveListItem(wordDoc, blockLevelContentElement);
                itemText = blockLevelContentElement
                    .LogicalChildrenContent(W.r)
                    .LogicalChildrenContent(W.t)
                    .Select(t => (string)t)
                    .StringConcatenate();
                if (itemText.Trim().Length > 0)
                {
                    if (null == listItem)
                    {
                        // Add html break tag 
                        textItemSB.Append( itemText + "<br/>");
                    }
                    else
                    {
                        //if listItem == "" bullet character, replace it with equivalent html encoded character                                   
                        textItemSB.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + (listItem == "" ? "&bull;" : listItem) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + itemText + "<br/>");
                    }
                }
                else if (null != listItem)
                {
                    //If bullet character is found, replace it with equivalent html encoded character  
                    textItemSB.Append(listItem == "" ? "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&bull;" : listItem);
                }
                else
                    textItemSB.Append("<blank>");
                continue;
            }
            // If element is not a paragraph, it must be a table.

            foreach (var row in blockLevelContentElement.LogicalChildrenContent())
            {                        
                foreach (var cell in row.LogicalChildrenContent())
                {                            
                    // Cells are a block-level content container, so can call this method recursively.
                    OutputBlockLevelContent(wordDoc, cell);
                }
            }
        }
        if (textItemSB.Length > 0)
        {
            textItemList.Add(textItemSB.ToString());
            textItemSB.Clear();
        }
    }
    catch (Exception ex)
    {
        .....
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top