[英]Read Last line from First column using Aspose.Words v13.1.0
我有一個帶有兩列布局的word文檔。 如何從第一列讀取最后一行並從word文檔的第二列讀取第一行。如果第一列最后一行文本是特定格式,則向下移動一行,這將自動將文本移動到下一列(第二列)。
請告訴我如何使用Aspose.Words V13.1.0在.net中實現此目的
首先,您需要從此鏈接下載脫機樣本包以使用以下代碼示例。 然后提取存檔,並從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開發人員。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.