简体   繁体   中英

Read Last line from First column using Aspose.Words v13.1.0

I have a word document with two column layout. How to read last line from first column and read first line from second column in a word document.If first column last line text is in specific format, then move one line down which would automaticaly moves the text to next column(second).

Please let me know how to achieve this in .net using Aspose.Words V13.1.0

First you need to download offline samples pack from this link to use the following code example. Then extract the archive and from the DocumentLayoutHelper example, include the RenderedDocument and LayoutEntities source files in to his application.

Here is the sample code:

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, Hope that above example can fulfil your requirements. My name is Nayyer and I am Support/Engangelist developer at Aspose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM