C # -excel interop - create a chart in a workbook, not in a worksheet

Using the inter C # MS Excel library, I would like to programmatically create a new chart in a book, not a sheet.

The code below allows me to create a chart on an existing sheet (sheet).

using using Microsoft.Office.Interop.Excel;  

_Worksheet sheet;  (assume this is a reference to a valid _Worksheet object)  
ChartObjects charts = (ChartObjects)sheet.ChartObjects(Type.Missing);  
ChartObject chartObject = (ChartObject)charts.Add(10, 80, 300, 250);  
Chart chart = chartObject.Chart;  
chart.ChartType = XlChartType.xlXYScatter;

Does anyone know how best to create a chart in a book (i.e. where the chart is a worksheet).

+5
source share
1 answer

Excel VB (, , , , interop), , . :

  chart.Location(XlChartLocation.xlLocationAsNewSheet, "NewSheetName");

, Excel :

  chart.Location(XlChartLocation.xlLocationAsNewSheet, Type.Missing);
+3

All Articles