0

2 列レイアウトの Word 文書があります。Word文書の最初の列から最後の行を読み取り、2番目の列から最初の行を読み取る方法.最初の列の最後の行のテキストが特定の形式の場合、1行下に移動すると、テキストは自動的に次の列(2番目)に移動します.

Aspose.Words V13.1.0 を使用して .net でこれを実現する方法を教えてください。

4

1 に答える 1

2

最初に、このリンクからオフライン サンプル パックをダウンロードして、次のコード例を使用する必要があります。次に、アーカイブを抽出し、DocumentLayoutHelper の例から、RenderedDocument および LayoutEntities ソース ファイルをアプリケーションに含めます。

サンプルコードは次のとおりです。

Document doc = new Document(dataDir + "Test.docx");

// This sample introduces the RenderedDocument class and other related classes which provide an API wrapper for
// the LayoutEnumerator. This allows you to access the layout entities of a document using a DOM style API.

// Create a new RenderedDocument class from a Document object.
RenderedDocument layoutDoc = new RenderedDocument(doc);

// Loop through the layout info of each page
foreach (RenderedPage page in layoutDoc.Pages)
{
    if (page.Columns.Count > 1)
    {
        // Find the last line in the first column on the page.
        RenderedLine lastLine = page.Columns.First.Lines.Last;

        // This is the pargraph which belongs to the last line on the page, implement required logic and checks here.
        Paragraph para = lastLine.Paragraph;
        if (para.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1)
        {
            // Insert a blank paragraph before the last paragraph in the column.
            para.ParentNode.InsertBefore(new Paragraph(doc), para);
        }


        // This is how to get the first line in the second column and the related paragraph.
        // Use this if it is required.
        RenderedLine secondColumnLine = page.Columns[1].Lines.First;
        Paragraph secondColumnPara = lastLine.Paragraph;
    }
}

PS、上記の例が要件を満たすことを願っています。私の名前は Nayyer です。Aspose のサポート/エンガンジェリスト開発者です。

于 2013-02-13T05:59:23.233 に答える