翻譯|使用教程|編輯:李顯亮|2019-09-25 09:38:56.920|閱讀 1849 次
概述:使用可視代理(例如Microsoft Word)創建表時,通常會發現使用AutoFit選項之一自動將表調整為所需的寬度。例如,可以使用“自動適應窗口”選項使表格適合頁面的寬度,使用“自動適應目錄”選項允許每個單元格增加或縮小以容納其內容。本文將用示例介紹如何在表格中設置不同的自動調整。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
推薦閱讀:【Aspose.Words for .NET使用表格教程之應用格式——將格式應用于表,行和單元格】
Aspose.Words For .Net是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
接下來我們將進入“使用格式”的介紹,其中包括應用格式、介紹和創建表、添加和拆分表以及使用列和行。本文將為大家講解如何在表格中運用自動調整設置。
>>Aspose.Words for .NET更新至最新版v19.9,歡迎下載體驗
使用可視代理(例如Microsoft Word)創建表時,通常會發現使用AutoFit選項之一自動將表調整為所需的寬度。例如,可以使用“自動適應窗口”選項使表格適合頁面的寬度,使用“自動適應目錄”選項允許每個單元格增加或縮小以容納其內容。
默認情況下,Aspose.Words使用“ 自動調整到窗口”插入一個新表。該表格將調整為頁面上的可用寬度。若要更改此類表或現有表的大小調整行為,可以調用Table.AutoFit方法。
下面的示例自動調整表格以適合頁面寬度。
//文檔目錄的路徑。 string dataDir = RunExamples.GetDataDir_WorkingWithTables(); string fileName = "TestFile.doc"; //打開文檔 Document doc = new Document(dataDir + fileName); Table table = (Table)doc.GetChild(NodeType.Table, 0, true); //將第一個表格自動調整為頁面寬度。 table.AutoFit(AutoFitBehavior.AutoFitToWindow); dataDir = dataDir + RunExamples.GetOutputFilePath(fileName); //將文檔保存到磁盤。 doc.Save(dataDir); Debug.Assert(doc.FirstSection.Body.Tables[0].PreferredWidth.Type == PreferredWidthType.Percent, "PreferredWidth type is not percent"); Debug.Assert(doc.FirstSection.Body.Tables[0].PreferredWidth.Value == 100, "PreferredWidth value is different than 100");
當將對窗口的自動調整應用于表時,實際上是在后臺執行以下操作:
下面的示例將文檔中的表格自動調整為其內容。
//文檔目錄的路徑。 string dataDir = RunExamples.GetDataDir_WorkingWithTables(); string fileName = "TestFile.doc"; Document doc = new Document(dataDir + fileName); Table table = (Table)doc.GetChild(NodeType.Table, 0, true); //自動使表格適合單元格內容 table.AutoFit(AutoFitBehavior.AutoFitToContents); dataDir = dataDir + RunExamples.GetOutputFilePath(fileName); // 將文檔保存到磁盤。 doc.Save(dataDir); Debug.Assert(doc.FirstSection.Body.Tables[0].PreferredWidth.Type == PreferredWidthType.Auto, "PreferredWidth type is not auto"); Debug.Assert(doc.FirstSection.Body.Tables[0].FirstRow.FirstCell.CellFormat.PreferredWidth.Type == PreferredWidthType.Auto, "PrefferedWidth on cell is not auto"); Debug.Assert(doc.FirstSection.Body.Tables[0].FirstRow.FirstCell.CellFormat.PreferredWidth.Value == 0, "PreferredWidth value is not 0");
下面的示例禁用自動擬合并為指定的表格啟用固定寬度。
//文檔目錄的路徑。 string dataDir = RunExamples.GetDataDir_WorkingWithTables(); string fileName = "TestFile.doc"; Document doc = new Document(dataDir + fileName); Table table = (Table)doc.GetChild(NodeType.Table, 0, true); //在此表上禁用自動擬合。 table.AutoFit(AutoFitBehavior.FixedColumnWidths); dataDir = dataDir + RunExamples.GetOutputFilePath(fileName); //將文檔保存到磁盤。 doc.Save(dataDir); //結束 Debug.Assert(doc.FirstSection.Body.Tables[0].PreferredWidth.Type == PreferredWidthType.Auto, "PreferredWidth type is not auto"); Debug.Assert(doc.FirstSection.Body.Tables[0].PreferredWidth.Value == 0, "PreferredWidth value is not 0"); Debug.Assert(doc.FirstSection.Body.Tables[0].FirstRow.FirstCell.CellFormat.Width == 69.2, "Cell width is not correct.");
*想要購買Aspose正版授權的朋友可以哦~
ASPOSE技術交流QQ群已開通,各類資源及時分享,歡迎交流討論!(掃描下方二維碼加入群聊)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn