翻譯|使用教程|編輯:李顯亮|2021-06-28 10:40:13.800|閱讀 301 次
概述:本文將演示如何使用 Spire.Doc for .NET 在文本框中垂直放置文本。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一個專業的Word .NET庫,設計用于幫助開發人員高效地開發創建、閱讀、編寫、轉換和打印任何來自.NET( C#, VB.NET, ASP.NET)平臺的Word文檔文件的功能。
本文將演示如何使用 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
效果圖:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn