Aspose.Words for .NET使用教程:如何使用腳註和尾註並設置每頁行字數

Aspose.Words For .Net是一種高級Word文檔處理API,用於執行各類文檔管理和操做任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。此外,API支持全部流行的Word處理文件格式,並容許將Word文檔導出或轉換爲固定佈局文件格式和最經常使用的圖像/多媒體格式。佈局

【下載Aspose.Words for .NET最新試用版】字體

設置每頁行數和每行字符數


若是要設置每行的字符數,請使用PageSetup.CharactersPerLine屬性。此屬性的最小值爲1,最大值取決於Normal樣式的頁面寬度和字體大小。最小字符間距是字體大小的90%。例如,具備1英寸邊距的Letter頁面的每行的最大字符數爲43。默認狀況下,該屬性具備一個值,其中字符間距等於Normal樣式的字體大小。ui

咱們還能夠爲Word文檔設置每頁的行數。請使用PageSetup.LinesPerPage屬性來獲取或設置文檔網格中每頁的行數。屬性的最小值爲1,最大值取決於Normal樣式的頁面高度和字體大小。最小線間距是字體大小的136%。例如,具備1英寸邊距的Letter頁面的每頁最大行數爲39。默認狀況下,該屬性具備一個值,其中行間距比Normal樣式的字體大小大1.5倍。spa

下面的示例顯示如何設置Word文檔的每行字符數和每頁行數:orm

//指向documents目錄的路徑。
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
Document doc = new Document(dataDir + "Document.doc");

//設置容許定義文檔網格行爲的部分的佈局模式
//注意,若是任何亞洲語言被定義爲編輯語言,文檔網格選項卡在MS Word的頁面設置對話框中是可見的。
doc.FirstSection.PageSetup.LayoutMode = SectionLayoutMode.Grid;
//設置文檔網格中每行字符的數量。
doc.FirstSection.PageSetup.CharactersPerLine = 30;
//設置文檔網格中每頁的行數。
doc.FirstSection.PageSetup.LinesPerPage = 10;

dataDir = dataDir + "Document.PageSetup_out.doc";
doc.Save(dataDir);

 

使用腳註和尾註


▲插入Endnote和Set Numbering選項資源

若是要在Word文檔中插入腳註或尾註,請使用DocumentBuilder.InsertFootnote方法。此方法將腳註或尾註插入到文檔中。EndnoteOptionsFootnoteOptions類表示腳註和尾註的編號選項。下面的代碼示例顯示如何將endnote插入到文檔中並設置其編號選項:文檔

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

DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Some text");

builder.InsertFootnote(FootnoteType.Endnote, "Eootnote text.");

EndnoteOptions option = doc.EndnoteOptions;
option.RestartRule = FootnoteNumberingRule.RestartPage;
option.Position = EndnotePosition.EndOfSectio

dataDir = dataDir + "TestFile_Out.doc";

//將文檔保存到磁盤。
doc.Save(dataDir);

 

▲如何設置腳註佈局欄數get


咱們能夠使用腳註選項設置腳註佈局列的數量。列屬性。若是此屬性的值爲0,則腳註區域將根據顯示頁面上的列數使用若干列進行格式化。下面的示例顯示如何設置腳註佈局的列數:string

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

//指定用於格式化腳註區域的列數。
doc.FootnoteOptions.Columns = 3;
dataDir = dataDir + "TestFile_Out.doc";

//將文檔保存到磁盤。
doc.Save(dataDir);

 

如何設置腳註和尾註的位置it

腳註位置能夠在每頁的底部,也能夠在每頁的文字下方。尾註位置能夠在節的末尾,也能夠在文檔的末尾。下面的例子展現瞭如何設置腳註和尾註的位置:

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

//設置腳註和端點位置。
doc.FootnoteOptions.Position = FootnotePosition.BeneathText;
doc.EndnoteOptions.Position = EndnotePosition.EndOfSection;
dataDir = dataDir + "TestFile_Out.doc";

//將文檔保存到磁盤。
doc.Save(dataDir);

爲你推薦:Aspose專題 - Aspose最新資源合集


歡迎加入ASPOSE技術交流QQ羣(642018183),各種資源及時分享,與同行資深用戶交流討論!

相關文章
相關標籤/搜索