0

我有一个带有两列布局的word文档。如何在word文档中从第一列读取最后一行并从第二列读取第一行。如果第一列最后一行文本采用特定格式,则向下移动一行,这将自动将文本移动到下一列(第二个)。

请让我知道如何使用 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 的支持/Engangelist 开发人员。

于 2013-02-13T05:59:23.233 回答