使用C#从excel文件中删除/删除图像

编程入门 行业动态 更新时间:2024-10-24 08:20:33
本文介绍了使用C#从excel文件中删除/删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从excel文件表中删除特定图片,但我发现什么或我找到的大多数代码与我的方法excel不匹配.Interop! 我尝试过:

Excel.Application APPXL = new Excel.Application(); Excel.Workbook RapportXlWorkBook = APPXL.Workbooks.Open(excelfilePath) Excel.Worksheet RapportXlSheet =(Excel.Worksheet)RapportXlWorkBook.Worksheets [1]; ///删除代码 //RapportXlSheet.Shapes(imageName)。删除!!! ??

我发现如何删除excel文件中的所有形状(图片/图像),但不是特定的形状!

foreach(Rapport.Slpe sh in RapportXlSheet.Shapes) { sh.Delete(); }

解决方案

看起来你有一个VBA / VB.NET代码示例,你需要转换它到C#。尝试:

RapportXlSheet.Shapes [imageName] .Delete();

编辑:如上所述在注释中,索引器未得到正确支持。您必须使用 Item 方法:

RapportXlSheet.Shapes.Item(imageName).Delete() ;

i want to delete specific image from excel file sheet , but i found nothing or most code i found doesn't match with my methode excel.Interop ! What I have tried:

Excel.Application APPXL = new Excel.Application(); Excel.Workbook RapportXlWorkBook = APPXL.Workbooks.Open(excelfilePath) Excel.Worksheet RapportXlSheet = (Excel.Worksheet)RapportXlWorkBook.Worksheets[1]; /// remove code //RapportXlSheet.Shapes(imageName).Delete !!! ??

I found only how to delete ALL shapes (pictures/images) in excel file , but not a specific shape !

foreach (Excel.Shape sh in RapportXlSheet.Shapes) { sh.Delete(); }

解决方案

Looks like you've got a VBA / VB.NET code sample, and you need to convert it to C#. Try:

RapportXlSheet.Shapes[imageName].Delete();

EDIT: As discussed in the comments, the indexer isn't supported properly. You have to use the Item method instead:

RapportXlSheet.Shapes.Item(imageName).Delete();

更多推荐

使用C#从excel文件中删除/删除图像

本文发布于:2023-11-07 22:40:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567635.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   文件   excel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!