c# - Delete Chart Based On Location? -
Is it possible to delete the excel chart based on the location of the chart in the workbook? For example, I am currently using the code below to remove the chart from their name. But what I whistle is sometimes a different name in the chart. The only consistent thing is that they are in one place. Or anyone can move my code to the location where it will be removed depending on the location:
foreach (["Microsoft.Office.Interop.Excel.Shape oXL.Sheets" Sheet 1 "]. If (shp.Type == MsoShapeType.msoChart) {if (shp.Name ==" Chart 233 "} shp.Name ==" Chart 111 ") {shp.Delete (); }}
Something like this - will delete a chart if its located in the top left corner Is within range B4: D8
// ... by using Office = Microsoft.Office.Core; Using Excel = Microsoft.Office.Interop.Excel; Using IOS = System.Runtime.InteropServices; // ... Private Zero btnDeleteChart_Click (Object Sender, EventArgs e) {Excel.Application xl = GetExcel (); If return (XL == blank); Excel.Workbook wb = xl.ActiveWorkbook; Excel.Worksheet sht = wb.ActiveSheet; Excel.RSrch = sht.Range ["B4: D8"]; Excel.Range rShp; Foreign currency (excel size shp in sht.shap) if (shp.Type == Office.MsoShapeType.msoChart) {rShp = shp.TopLeftCell; If (xl.Intersect (rShp, rSrch) = null!) Shp.Delete (); }} Private Excel Application GetExcel () {Excel.Application xl = (Excel.Application) ios.Marshal.GetActiveObject ("Excel.Application"); If (XL == blank) MessageBox.Show ("no Excel !!"); Return xl; }
Comments
Post a Comment