C# 设置Word文本框中的文字旋转方向

Iklan In-Feed (homepage)

Hello friends social networking, on this occasion the admin wants to share an article entitled C# 设置Word文本框中的文字旋转方向 , we have made good, quality and useful articles for you to read and take information in. hopefully the post content is about which we write you can understand. Alright, happy reading.

在Word中可插入文本框,默认情况下插入的文本框中的文字方向为横向排列,对于一些特殊文档的设计要求,需要改变文字方向,如本次测试中的文档排版为考生试卷类型,考生信息栏的内容为下图中的这种,

本文将以C#程序代码为例,展示如何来实现这种排版。另附VB.NET代码供参考。

 

测试程序环境如下:

  • Visual Studio 2017
  • .net framework 4.8
  • Free spire.doc.dll 7.11
  • 测试word文档:.docx2013

关于dll安装:在程序中通过nuget搜索Free Spire.Doc安装即可。

 

设置文字方向时,可支持多种方式,如图:

本次需要实现的目标格式使用LeftToRight类型即可,如需设置竖排显示则选择LeftToRightRotated类型,其他文字旋转类型同理。

C#

using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;using System.Drawing;namespace SetTextDirection{ class Program {  static void Main(string[] args)  {   //实例化document对象   Document doc = new Document();   //添加一个section   Section section = doc.AddSection();   //设置页面边距   section.PageSetup.Margins.Left = 90;   section.PageSetup.Margins.Right = 90;   Paragraph paragraph = section.AddParagraph();   //添加第一个文本框   TextBox textBox1 = paragraph.AppendTextBox(section.PageSetup.Margins.Left - 20, section.PageSetup.PageSize.Height + 20);   //设置文本框为固定定位   textBox1.Format.HorizontalOrigin = HorizontalOrigin.Page;   textBox1.Format.HorizontalPosition = 0;   textBox1.Format.VerticalPosition = -10f;   textBox1.Format.VerticalOrigin = VerticalOrigin.Page;   //设置文字旋转方向   textBox1.Format.TextAnchor = ShapeVerticalAlignment.Center;   textBox1.Format.LayoutFlowAlt = TextDirection.LeftToRight;//旋转文字方向   //textBox1.Format.LayoutFlowAlt = TextDirection.LeftToRightRotated;//竖排显示     //添加文字并设置字体   Paragraph textboxPara1 = textBox1.Body.AddParagraph();   TextRange txtrg = textboxPara1.AppendText("姓名______________学号______________班级______________");   txtrg.CharacterFormat.FontName = "等线";   txtrg.CharacterFormat.FontSize = 10;   txtrg.CharacterFormat.TextColor = Color.Black;   textboxPara1.Format.HorizontalAlignment = HorizontalAlignment.Center;   //保存文档   doc.SaveToFile("Result.docx",FileFormat.Docx2013);   System.Diagnostics.Process.Start("Result.docx");  } }}

VB.NET

Imports Spire.DocImports Spire.Doc.DocumentsImports Spire.Doc.FieldsImports System.DrawingNamespace SetTextDirection         Class Program                   Private Shared Sub Main(args As String())                            '实例化document对象                            Dim doc As New Document()                            '添加一个section                            Dim section As Section = doc.AddSection()                            '设置页面边距                            section.PageSetup.Margins.Left = 90                            section.PageSetup.Margins.Right = 90                            Dim paragraph As Paragraph = section.AddParagraph()                            '添加第一个文本框                            Dim textBox1 As TextBox = paragraph.AppendTextBox(section.PageSetup.Margins.Left - 20, section.PageSetup.PageSize.Height + 20)                            '设置文本框为固定定位                            textBox1.Format.HorizontalOrigin = HorizontalOrigin.Page                            textBox1.Format.HorizontalPosition = 0                            textBox1.Format.VerticalPosition = -10F                            textBox1.Format.VerticalOrigin = VerticalOrigin.Page                            '设置文字旋转方向                            textBox1.Format.TextAnchor = ShapeVerticalAlignment.Center                            textBox1.Format.LayoutFlowAlt = TextDirection.LeftToRight'旋转文字方向                            'textBox1.Format.LayoutFlowAlt = TextDirection.LeftToRightRotated; '竖排显示                           ......

原文转载:http://www.shaoqun.com/a/824705.html

跨境电商:https://www.ikjzd.com/

square:https://www.ikjzd.com/w/2106

一淘比价网:https://www.ikjzd.com/w/1698

rakuten:https://www.ikjzd.com/w/2718


在Word中可插入文本框,默认情况下插入的文本框中的文字方向为横向排列,对于一些特殊文档的设计要求,需要改变文字方向,如本次测试中的文档排版为考生试卷类型,考生信息栏的内容为下图中的这种,本文将以C#程序代码为例,展示如何来实现这种排版。另附VB.NET代码供参考。测试程序环境如下:VisualStudio2017.netframework4.8Freespire.doc.dll7.11测试wor
【香港端午节放假】2019端午节香港放假吗,端午节去香港人多吗:http://www.30bags.com/a/219537.html
口述实录:开着宝马教女同事学车"妻离子散", 我还能回头吗?:http://lady.shaoqun.com/a/252681.html
女人10句话藏有潜台词 男人要当心女人男人妻子:http://lady.shaoqun.com/m/a/33721.html
被男友按着狂啪 今晚我要爽死你,好硬:http://lady.shaoqun.com/a/248273.html
深圳菊次郎的夏天音乐会演出地址:http://www.30bags.com/a/452900.html
亚马逊产品开发,如何找准亚马逊用户最大的痛点?:https://www.ikjzd.com/tl/95967
跨境电商折扣网站,用户上亿的引流新渠道:https://www.ikjzd.com/tl/95971
亚马逊开case官方邮箱汇总:https://www.ikjzd.com/tl/95983
分手当天我们做了9次 羞羞过程激烈文章:http://lady.shaoqun.com/a/248424.html
口述:邻居在电梯里夺走我第一次:http://lady.shaoqun.com/m/a/17890.html
深圳2021菊次郎的夏天钢琴音乐会演出曲目:http://www.30bags.com/a/452901.html
深圳2021菊次郎的夏天久石让音乐会门票入口:http://www.30bags.com/a/452902.html


That's the article: C# 设置Word文本框中的文字旋转方向
Thank you for visiting my blog, hopefully it can be useful for all of you. Don't forget to share this article with your friends so they also know the interesting info, see you in other article posts.

You are now reading the article C# 设置Word文本框中的文字旋转方向 with link address https://socialnetworkingupdate.blogspot.com/2021/06/c-word.html

More Articles

    #Advertisement

    Post a Comment

    Mas Bago Mas luma