翻譯|使用教程|編輯:顏馨|2023-05-19 09:44:04.387|閱讀 130 次
概述:本章介紹如何在文本框中設置文本方向,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
技術交流Q群(767755948)
在前面的教程中,我們簡要介紹了如何在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
輸出
以上便是如何在文本框中設置文本方向的教程,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn