madan
madan

Reputation: 783

How to get chart type and name of that from a slide?

I have to find following information from a chart. chartType,ChartName in it enter image description here

from the above image I want to find the below information

  1. type: Column
  2. name: clustered Column.

with or with out using interop Till now by using interop I can able to get the type of a chart with property ChartType (Below is the code). but it gives me xlColumnClustered from that I come to know what was that but I want exact name and type.

if (shape.HasChart == MsoTriState.msoTrue)
{
    var val1 = shape.Chart;
    string category = val1.ChartType.ToString();
    Console.WriteLine("Smartart : {0} \tCategory : {1}\t Name : {2}", (i++).ToString(), category, 1);
}

Upvotes: 0

Views: 1588

Answers (1)

sab669
sab669

Reputation: 4104

You're not going to get a more specific value than xlColumnClustered from chart type. This is a list of all the chart types:

https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.xlcharttype.aspx

It's just an enum. So you might be able to access the description, but if not then you'll have to implement your own logic to convert those enum values to a more descriptive text for display.


Then for Chart.Name, it looks like you just get *sheetname* Chart N where N is of course the number of the chart instance on the sheet:

https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.chart.name.aspx

However, there is this bit as well:

Although the Name property is read-only, you can modify a portion of the name by using the P:Microsoft.Office.Interop.Excel.ChartObject.Name property of the parent T:Microsoft.Office.Interop.Excel.ChartObject. The new name you specify replaces the "Chart n" substring in the string returned by the Name property. For example, the following code changes the Name property value of a Chart control from Sheet1 Chart 1 to Sheet1 SalesChart.

Excel.ChartObject chartObjectParent = chart1.Parent as Excel.ChartObject;
chartObjectParent.Name = "SalesChart";

// This message box displays "Sheet1 SalesChart".
MessageBox.Show("The new chart name is: " + chart1.Name);

Upvotes: 1

Related Questions