翻譯|使用教程|編輯:李顯亮|2019-08-14 11:38:43.590|閱讀 610 次
概述:Aspose.Words For .Net是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。接下來我們將進入“使用格式”的介紹,其中包括應用格式、介紹和創建表、添加和拆分表以及使用列和行。本文將對表位、使用表的替代文本、單元格之間的間距進行介紹。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Words For .Net是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
【下載Aspose.Words for .NET最新試用版】
接下來我們將進入“使用格式”的介紹,其中包括應用格式、介紹和創建表、添加和拆分表以及使用列和行。
下面的示例顯示了如何獲取表與其周圍文本之間的距離:
Document doc = new Document(dataDir + "Table.EmptyTable.doc"); Console.WriteLine("\nGet distance between table left, right, bottom, top and the surrounding text."); Table table = (Table)doc.GetChild(NodeType.Table, 0, true); Console.WriteLine(table.DistanceTop); Console.WriteLine(table.DistanceBottom); Console.WriteLine(table.DistanceRight); Console.WriteLine(table.DistanceLeft);
如果表的文本環繞為“周圍”,則可以使用Table.RelativeHorizontalAlignment和Table.RelativeVerticalAlignment屬性獲取表的水平和垂直對齊。 在其他情況下,您可以使用Table.Alignment屬性獲取表的內聯對齊。 下面的示例顯示了如何獲得表格的對齊方式。
Document doc = new Document(dataDir + "Table.Document.doc"); // Retrieve the first table in the document. Table table = (Table)doc.GetChild(NodeType.Table, 0, true); if (table.TextWrapping == TextWrapping.Around) { Console.WriteLine(table.RelativeHorizontalAlignment); Console.WriteLine(table.RelativeVerticalAlignment); } else { Console.WriteLine(table.Alignment); }
下面的示例顯示了如何獲取浮動表的位置:
Document doc = new Document(dataDir + "FloatingTablePosition.docx"); foreach (Table table in doc.FirstSection.Body.Tables) { // 如果表格是浮動類型,那么打印它的定位屬性。 if (table.TextWrapping == TextWrapping.Around) { Console.WriteLine(table.HorizontalAnchor); Console.WriteLine(table.VerticalAnchor); Console.WriteLine(table.AbsoluteHorizontalDistance); Console.WriteLine(table.AbsoluteVerticalDistance); Console.WriteLine(table.AllowOverlap); Console.WriteLine(".............................."); } }
表的標題和描述提供了表中包含的信息的替代的基于文本的表示。 MS Word允許設置此信息(右鍵單擊表,單擊表屬性,單擊Alt Text選項卡,然后設置表的標題和說明)。 使用Aspose.Words,您可以使用Table.Title和Table.Description屬性來實現此目的。這些屬性對符合ISO / IEC 29500的DOCX文檔有意義。下面的代碼示例顯示了如何設置表的標題和描述屬性:
Document doc = new Document(dataDir + "Table.Document.doc"); Table table = (Table)doc.GetChild(NodeType.Table, 0, true); table.Title = "Test title"; table.Description = "Test description"; OoxmlSaveOptions options = new OoxmlSaveOptions(); options.Compliance = OoxmlCompliance.Iso29500_2008_Strict; doc.CompatibilityOptions.OptimizeFor(Settings.MsWordVersion.Word2016); dataDir = dataDir + "Table.SetTableTitleandDescription_out.docx"; //將文檔保存到磁盤。 doc.Save(dataDir, options);
默認情況下,MS Word不會在表格中的單元格之間添加任何額外空格。 您可以在MS Word的表格屬性中找到此選項。 您可以使用Table.AllowCellSpacing屬性獲取或設置“允許單元格之間的間距”選項。 下面的代碼示例顯示如何在單元格之間設置空間:
Document doc = new Document(dataDir + "Table.Document.doc"); Table table = (Table)doc.GetChild(NodeType.Table, 0, true); table.AllowCellSpacing = true; dataDir = dataDir + "Table.AllowCellSpacing_out.docx"; //將文檔保存到磁盤。 doc.Save(dataDir);
*Aspose.Words現已加入“8月省錢式嗨購”,滿額即送office 365正版授權,想要購買Aspose.Words正版授權的朋友可了解詳情哦~
ASPOSE技術交流QQ群已開通,各類資源及時分享,歡迎交流討論!(掃描下方二維碼加入群聊)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn