翻譯|使用教程|編輯:胡濤|2022-12-09 13:47:56.983|閱讀 164 次
概述:本文介紹了如何使用 Spire.Doc 在 Word 中的評論中插入圖片。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
Word 中的評論可以包含文本、圖像、OLE 對象等豐富的元素。本文介紹了如何使用 Spire.Doc 在 Word 中的評論中插入圖片。
第 1 步:初始化 Document 類的實例并加載示例文檔。
Document doc = new Document(); doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.docx");
第 2 步:從第一節中獲取第三段。
Paragraph paragraph = doc.Sections[0].Paragraphs[2];
第 3 步:在段落中附加評論。
Comment comment = paragraph.AppendComment("This is a comment."); comment.Format.Author = "E-iceblue";
第 4 步:在評論正文中插入圖片。
DocPicture docPicture = new DocPicture(doc); Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\logo.png"); docPicture.LoadImage(img); comment.Body.AddParagraph().ChildObjects.Add(docPicture);
第 5 步:保存文件。
doc.SaveToFile("result.docx",FileFormat.Docx2013);
輸出:
完整代碼:
[C#]
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing; namespace InsertPicture { class Program { static void Main(string[] args) { Document doc = new Document(); doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.docx"); Paragraph paragraph = doc.Sections[0].Paragraphs[2]; Comment comment = paragraph.AppendComment("This is a comment."); comment.Format.Author = "E-iceblue"; DocPicture docPicture = new DocPicture(doc); Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\logo.png"); docPicture.LoadImage(img); comment.Body.AddParagraph().ChildObjects.Add(docPicture); doc.SaveToFile("result.docx", FileFormat.Docx2013); } } }
[VB.NET]
Imports Spire.Doc Imports Spire.Doc.Documents Imports Spire.Doc.Fields Imports System.Drawing Namespace InsertPicture Class Program Private Shared Sub Main(args As String()) Dim doc As New Document() doc.LoadFromFile("C:\Users\Administrator\Desktop\sample.docx") Dim paragraph As Paragraph = doc.Sections(0).Paragraphs(2) Dim comment As Comment = paragraph.AppendComment("This is a comment.") comment.Format.Author = "E-iceblue" Dim docPicture As New DocPicture(doc) Dim img As Image = Image.FromFile("C:\Users\Administrator\Desktop\logo.png") docPicture.LoadImage(img) comment.Body.AddParagraph().ChildObjects.Add(docPicture) doc.SaveToFile("result.docx", FileFormat.Docx2013) End Sub End Class End Namespace
以上便是在C#、VB.NET如何在Word的評論中插入圖片,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn