翻譯|使用教程|編輯:胡濤|2022-10-09 10:41:23.227|閱讀 232 次
概述:本文將向您展示如何在 C# 中將文本環繞在圖像周圍,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。在 C#、VB.NET 中從 Word 中提取圖像。
當我們將圖像添加到word文檔中時,我們當然希望將它準確地移動到我們想要使頁面整潔美觀的位置。借助 Spire.Doc,我們可以設置環繞樣式來調整圖像的位置。通常有七種環繞樣式:In Line with Text、Square、Tight、Through、Top and Bottom、Behind the Text、In Front of Text,Spire.Doc 都支持。本文將向您展示如何在 C# 中將文本環繞在圖像周圍。步驟如下:
第 1 步:創建一個新的 word 文檔并從文件中加載文檔。
Document document = new Document(); document.LoadFromFile("Sample.docx");
第 2 步:為第一部分添加一個段落。
Paragraph paragraph = document.Sections[0].AddParagraph();
第 3 步:在段落中添加圖片。
DocPicture picture = paragraph.AppendPicture(Image.FromFile("image.jpg"));
第 4 步:將文本環繞樣式設置為方形。
picture.TextWrappingStyle = TextWrappingStyle.Square;
第 5 步:將文本環繞類型設置為兩者。
picture.TextWrappingType = TextWrappingType.Both;
第 6 步:將文檔保存到文件并進行處理。
document.SaveToFile(output,FileFormat.Docx); System.Diagnostics.Process.Start(output);
圖像周圍扭曲文本的有效截圖:
完整代碼:
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing; namespace wrap_text_around_image { class Program { static void Main(string[] args) { Document document = new Document(); document.LoadFromFile("Sample.docx"); Paragraph paragraph = document.Sections[0].AddParagraph(); DocPicture picture = paragraph.AppendPicture(Image.FromFile("image.jpg")); picture.TextWrappingStyle = TextWrappingStyle.Square; picture.TextWrappingType = TextWrappingType.Both; string output = "output.docx"; document.SaveToFile(output,FileFormat.Docx); System.Diagnostics.Process.Start(output); } } }
以上便是如何在 C# 中將文本環繞在圖像周圍,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn