新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
怎么在C#中利用Aspose.Words刪除word中的圖片-創(chuàng)新互聯(lián)
今天就跟大家聊聊有關(guān)怎么在C#中利用Aspose.Words 刪除word中的圖片,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
string tempFile = Application.StartupPath + "\\resource\\templete\\項目建議書模板.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()可以理解為選中這個圖片
IncrementLeft();
方法是要素水平移動,正值 代表向右移動,負(fù)值代表向左移動
IncrementTop();
方法是要素垂直移動,正值代表向下移動,負(fù)值代表向上移動
看完上述內(nèi)容,你們對怎么在C#中利用Aspose.Words 刪除word中的圖片有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
網(wǎng)頁名稱:怎么在C#中利用Aspose.Words刪除word中的圖片-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://www.ef60e0e.cn/article/deedco.html