C# Aspose.Words 刪除word中的圖片操作
今天介紹下 Aspose.Words 對 word 中的圖片進(jìn)行刪除
string tempFile = Application.StartupPath + "\\resource\\templete\\項(xiàng)目建議書模板.doc"; Document doc = new Document(tempFile); NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true); foreach (Shape item in shapes) { if (item.HasImage) { item.Remove(); } } doc.Save(docPath);
補(bǔ)充:C#word插入圖片在指定標(biāo)簽位置(附加圖片上下左右移動)
這一篇我就直接講講圖片的添加和移動了
如上圖是直接插入,插入位置是鑲嵌類型,我想讓它浮動在文字下面,且大小也想調(diào)動一下
object Nothing = System.Reflection.Missing.Value; try { //定義該插入圖片是否為外部鏈接 object linkToFile = false; //定義插入圖片是否隨word文檔一起保存 object saveWithDocument = true; //圖片 string replacePic = picture; if (doc.Bookmarks.Exists(bookMark_text) == true) { object bookMark = bookMark_text; //查找書簽 doc.Bookmarks.get_Item(ref bookMark).Select(); //設(shè)置圖片位置 worldApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; //在書簽的位置添加圖片 InlineShape inlineShape = worldApp.Selection.InlineShapes.AddPicture(replacePic, ref linkToFile, ref saveWithDocument, ref Nothing); //設(shè)置圖片大小 inlineShape.Width = 100; inlineShape.Height = 100; inlineShape.Select(); inlineShape.ConvertToShape().IncrementLeft(-60.0f); //將圖片設(shè)置浮動在文字上方 inlineShape.ConvertToShape().WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapBehind; } } catch { doc.Saved = false; //word文檔中不存在該書簽,關(guān)閉文檔 doc.Close(ref Nothing, ref Nothing, ref Nothing); }
其中inlineShape.ConvertToShape()可以理解為選中這個(gè)圖片
IncrementLeft();
方法是要素水平移動,正值 代表向右移動,負(fù)值代表向左移動
IncrementTop();
方法是要素垂直移動,正值代表向下移動,負(fù)值代表向上移動
WdWrapType是一個(gè)枚舉器,里面有鑲嵌類型,即
通過插入和移動就可以達(dá)到插入圖片到自己想要的位置了
結(jié)果:
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
- C#語言MVC框架Aspose.Cells控件導(dǎo)出Excel表數(shù)據(jù)
- C#使用Aspose.Cells導(dǎo)出excel
- C#使用Aspose.Cells創(chuàng)建和讀取Excel文件
- C#使用Aspose.Cells控件讀取Excel
- C# 利用Aspose.Words.dll將 Word 轉(zhuǎn)成PDF
- C# 調(diào)用exe傳參,并獲取打印值的實(shí)例
- 如何利用C#打印九九乘法表
- c# winform 解決PictureBox 無法打印全部圖片的問題
- C#操作Word打印的示例
- C# 打印網(wǎng)頁不顯示頁眉頁腳的實(shí)現(xiàn)方法
- C#實(shí)現(xiàn)掃描槍掃描二維碼并打印(實(shí)例代碼)
- C#利用PrintDocument定制打印單據(jù)的小例子
- c#使用Aspose打印文件的示例
相關(guān)文章
C#使用Socket實(shí)現(xiàn)通信的方法示例
這篇文章主要介紹了C#使用Socket實(shí)現(xiàn)通信的方法示例,文章按照 Socket 的 創(chuàng)建、連接、傳輸數(shù)據(jù)、釋放資源的過程來寫,給出方法、參數(shù)的詳細(xì)信息,文中有詳細(xì)的代碼示例供大家參考,需要的朋友可以參考下2024-06-06c#實(shí)現(xiàn)winform屏幕截圖并保存的示例
這篇文章主要介紹了c#實(shí)現(xiàn)winform屏幕截圖并保存的示例,需要的朋友可以參考下2014-02-02