Word控件Spire.Doc 【页面背景】教程(4) ;如何在word文档的一侧创建垂直表格

首先,请查看Spire.Doc添加的word文档右侧垂直表格的有效截图:

如何在word文档的一侧创建垂直表格

下面介绍如何在C#中创建垂直表格的步骤。

第 1 步:创建一个新文档并在文档中添加一个部分。

Document document = new Document();Section section=document.AddSection();

第 2 步:添加一个包含行和列的表格并设置表格的文本。

Table table = section.AddTable();table.ResetCells(1, 1);TableCell cell = table.Rows[0].Cells[0];table.Rows[0].Height = 150;cell.AddParagraph().AppendText("Draft copy in vertical style");

第 3 步:将表格的 TextDirection 设置为 RightToLeftRotated。

cell.CellFormat.TextDirection = TextDirection.RightToLeftRotated;

第 4 步:设置表格格式。

table.TableFormat.WrapTextAround = true;table.TableFormat.Positioning.VertRelationTo = VerticalRelation.Page;table.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Page;table.TableFormat.Positioning.HorizPosition = section.PageSetup.PageSize.Width- table.Width;table.TableFormat.Positioning.VertPosition = 200;

第 5 步:将文档保存到文件中。

document.SaveToFile("result.docx",FileFormat.docx2013);

C# 中的完整代码:

using Spire.Doc;using Spire.Doc.Documents;namespace CreateVerticalTable{class Program{static void Main(string[] args){Document document = new Document();Section section=document.AddSection();Table table = section.AddTable();table.ResetCells(1, 1);TableCell cell = table.Rows[0].Cells[0];table.Rows[0].Height = 150;cell.AddParagraph().AppendText("Draft copy in vertical style");cell.CellFormat.TextDirection = TextDirection.RightToLeftRotated;table.TableFormat.WrapTextAround = true;table.TableFormat.Positioning.VertRelationTo = VerticalRelation.Page;table.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Page;table.TableFormat.Positioning.HorizPosition = section.PageSetup.PageSize.Width- table.Width;table.TableFormat.Positioning.VertPosition = 200;document.SaveToFile("result.docx",FileFormat.docx2013);}}}


欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询在线客服  


标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年6月2日
下一篇 2022年6月2日

相关推荐

发表回复

登录后才能评论