翻譯|使用教程|編輯:顏馨|2023-05-16 09:26:57.457|閱讀 141 次
概述:本章介紹如何將圖像插入文本框,歡迎查閱~
# 界面/圖表報表/文檔/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)
Spire.Doc支持將圖片作為背景圖片或正文內容的一部分插入文本框。本文演示如何通過以下代碼片段實現這些目的。
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing; namespace InsertTextBox { class Program { static void Main(string[] args) { //Create a Word document Document doc = new Document(); Section section = doc.AddSection(); Paragraph paragraph = section.AddParagraph(); //Append a Textbox to paragraph TextBox tb = paragraph.AppendTextBox(120, 200); //Set the position of Textbox tb.Format.HorizontalOrigin = HorizontalOrigin.Page; tb.Format.HorizontalPosition = 50; tb.Format.VerticalOrigin = VerticalOrigin.Page; tb.Format.VerticalPosition = 50; //Set the fill effect of Textbox as picture tb.Format.FillEfects.Type = BackgroundType.Picture; //Fill the Textbox with a picture tb.Format.FillEfects.Picture = Image.FromFile("Background.jpg"); //Save to file doc.SaveToFile("InsertBackgroundImage.docx", FileFormat.Docx2013); } } }
輸出:
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing; namespace InsertTextBox { class Program { static void Main(string[] args) { //Create a Word document Document doc = new Document(); Section section = doc.AddSection(); Paragraph paragraph = section.AddParagraph(); //Append a Textbox to paragraph TextBox tb = paragraph.AppendTextBox(140, 250); //Set the position of Textbox tb.Format.HorizontalOrigin = HorizontalOrigin.Page; tb.Format.HorizontalPosition = 50; tb.Format.VerticalOrigin = VerticalOrigin.Page; tb.Format.VerticalPosition = 50; //Insert an image to body of Textbox Paragraph para1 = tb.Body.AddParagraph(); Image image = Image.FromFile("Shakespeare.jpg"); DocPicture picture = para1.AppendPicture(image); para1.Format.AfterSpacing = 8; para1.Format.HorizontalAlignment = HorizontalAlignment.Center; //Insert text to body of Textbox Paragraph para2 = tb.Body.AddParagraph(); TextRange textRange = para2.AppendText("(26 Apr.1564–§C23 Apr.1616) English poet, playwright, and actor, widely regarded as the greatest writer in the English language and the world's pre-eminent dramatist."); textRange.CharacterFormat.FontName = "Cambria"; textRange.CharacterFormat.FontSize = 9; para2.Format.LineSpacing = 15; para2.Format.HorizontalAlignment = HorizontalAlignment.Left; para2.Format.SuppressAutoHyphens = true; //Save to file doc.SaveToFile("InsertToBody.docx", FileFormat.Docx2013); } } }
輸出:
以上便是如何將圖像插入文本框的教程,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn