本文介绍了使用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文件中删除/删除图像
发布评论