彩票走势图

国产Word .NET库组件Spire.Doc系列教程(56):在 C#中的文本框中设置文本方向

翻译|使用教程|编辑:李显亮|2021-06-28 10:40:13.800|阅读 223 次

概述:本文将演示如何使用 Spire.Doc for .NET 在文本框中垂直放置文本。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

Spire.Doc for .NET是一个专业的Word .NET库,设计用于帮助开发人员高效地开发创建、阅读、编写、转换和打印任何来自.NET( C#, VB.NET, ASP.NET)平台的Word文档文件的功能。

本文将演示如何使用 Spire.Doc for .NET 在文本框中垂直放置文本。

点击下载Spire.Doc for .NET最新版

*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,查看折扣价!想要获取更多福利的朋友可以哦~

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;

namespace WordTextbox
{
    class Program
    {
        static void Main(string[] args)
        {
            // Instantiate document object
            Document document = new Document();

            //Add a section 
            Section section = document.AddSection();

            //Set the margin
            section.PageSetup.Margins.Left = 90;
            section.PageSetup.Margins.Right = 90;
            Paragraph paragraph = section.AddParagraph();

            //Add texbox 1
            TextBox textBox1 = paragraph.AppendTextBox(section.PageSetup.Margins.Left - 20, section.PageSetup.PageSize.Height + 20);
           
            //Fix the position of textbox 
            textBox1.Format.HorizontalOrigin = HorizontalOrigin.Page;
            textBox1.Format.HorizontalPosition = 0;
            textBox1.Format.VerticalPosition = -10f;
            textBox1.Format.VerticalOrigin = VerticalOrigin.Page;

            //Set the text vertically
            textBox1.Format.TextAnchor = ShapeVerticalAlignment.Center;
            textBox1.Format.LayoutFlowAlt = TextDirection.LeftToRight;

            //Add text and set the font
            Paragraph textboxPara1 = textBox1.Body.AddParagraph();
            TextRange txtrg = textboxPara1.AppendText("Name_______Number_________Class__________");
            txtrg.CharacterFormat.FontName = "Arial";
            txtrg.CharacterFormat.FontSize = 10;
            txtrg.CharacterFormat.TextColor = System.Drawing.Color.Black;
            textboxPara1.Format.HorizontalAlignment = HorizontalAlignment.Center;

            //Save the document
            document.SaveToFile("Result.docx");

        }
    }
}

VB.NET

Namespace WordTextbox
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            Dim document As Document = New Document
            Dim section As Section = document.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 = -10!
            textBox1.Format.VerticalOrigin = VerticalOrigin.Page
            textBox1.Format.TextAnchor = ShapeVerticalAlignment.Center
            textBox1.Format.LayoutFlowAlt = TextDirection.LeftToRight
            Dim textboxPara1 As Paragraph = textBox1.Body.AddParagraph
            Dim txtrg As TextRange = textboxPara1.AppendText("Name_______Number_________Class__________")
            txtrg.CharacterFormat.FontName= "Arial"
            txtrg.CharacterFormat.FontSize = 10
            txtrg.CharacterFormat.TextColor = System.Drawing.Color.Black
            textboxPara1.Format.HorizontalAlignment = HorizontalAlignment.Center
            document.SaveToFile("Result.docx")
        End Sub
    End Class
End Namespace

效果图:

国产Word .NET库组件Spire.Doc系列教程(56):在 C#中的文本框中设置文本方向


慧都是E-iceblue官方友好合作伙伴,如果您对spire.Doc感兴趣,可以了解具体授权价格和使用机制。

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP