翻譯|使用教程|編輯:胡濤|2022-09-27 15:59:25.483|閱讀 171 次
概述:本文將向您介紹如何通過(guò)spire.doc,在 C#/VB.NET 中的指定位置插入圖像,歡迎查閱~
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
Spire.Doc for .NET是一款專(zhuān)門(mén)對(duì) Word 文檔進(jìn)行操作的 .NET 類(lèi)庫(kù)。在于幫助開(kāi)發(fā)人員無(wú)需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專(zhuān)業(yè)開(kāi)發(fā)經(jīng)驗(yàn)Spire系列辦公文檔開(kāi)發(fā)工具,專(zhuān)注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。在 C#、VB.NET 中從 Word 中提取圖像。
圖像可以為您的 Word 文檔增添趣味并生效。假設(shè)你寫(xiě)了一篇介紹一個(gè)城市的文章,介紹它美麗的風(fēng)景。僅僅用文字描述,你無(wú)法為你的讀者呈現(xiàn)完美的風(fēng)景,因?yàn)槟且豁?yè)的文字看起來(lái)模糊而沉悶。你需要圖像來(lái)點(diǎn)綴你的風(fēng)景。
Spire.Doc for .NET是一個(gè)專(zhuān)業(yè)的.NET word 組件,無(wú)需使用 MS Office 自動(dòng)化即可快速生成、打開(kāi)、修改和保存 Word 文檔,使用戶(hù)可以使用 C#.NET 將圖像插入 Word 文檔并根據(jù)頁(yè)面設(shè)置其大小. 本指南介紹了如何通過(guò)Spire.Doc for .NET插入圖像的簡(jiǎn)單方法。
首先,新建 Word 文檔并為該文檔添加節(jié)、段。然后,在新創(chuàng)建的段落中插入圖像。您可以設(shè)置此圖像的大小、位置、旋轉(zhuǎn)它并選擇文本的環(huán)繞樣式。下載并安裝 Spire.Doc for .NET。使用以下代碼通過(guò) C# 在 Word 中插入圖像。
示例演示展示了如何將圖像插入到文檔中。
using System; using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing; namespace Insert_image_to_Word_Document { class Program { static void Main(string[] args) { //Open a blank word document as template Document document = new Document(@"Blank.doc"); Section section = document.Sections[0]; Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph(); paragraph.AppendText("The sample demonstrates how to insert an image into a document."); paragraph.ApplyStyle(BuiltinStyle.Heading2); paragraph = section.AddParagraph(); //get original image Bitmap p = new Bitmap(Image.FromFile(@"Word.jpg")); //rotate image and insert image to word document p.RotateFlip(RotateFlipType.Rotate90FlipX); DocPicture picture = document.Sections[0].Paragraphs[0].AppendPicture(p); //set image's position picture.HorizontalPosition = 50.0F; picture.VerticalPosition = 60.0F; //set image's size picture.Width = 200; picture.Height = 200; //set textWrappingStyle with image; picture.TextWrappingStyle = TextWrappingStyle.Through; //Save doc file. document.SaveToFile("Sample.doc", FileFormat.Doc); //Launching the MS Word file. System.Diagnostics.Process.Start("Sample.doc"); } } }
如果您已完成教程Spire.Doc 快速入門(mén),上述步驟會(huì)更簡(jiǎn)單。
使用Spire.Doc,您可以將圖像插入 Word 文檔,并在 ASP.NET、WPF 和 Silverlight 應(yīng)用程序中執(zhí)行更多相同操作,而無(wú)需 Word 自動(dòng)化和任何其他第三方插件。
以上便是如何在 C#/VB.NET 中的指定位置插入圖像,如果您有其他問(wèn)題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請(qǐng)咨詢(xún) ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn