ExcelFile.ChartCount Property
Returns the count of charts on this sheet. Please take note that this method will not return the number of embedded objects with charts inside in a sheet, but just the number of charts in the sheet. In simpler terms, this method will return 0 for all worksheets, and 1 for all chart sheets. This is not a very useful method, but it needs to be this way to be consistent with GetChart. So, looping like this:
for (int i = 1; i <= xls.ChartCount; i++)
{
xls.GetChart(i, null);
}
will loop 0 times for worksheets and 1 time for workbooks.
Syntax
Namespace: FlexCel.Core
public abstract Int32 ChartCount { get; }
Examples
The following example will retrieve all charts that are inserted as objects in a sheet, along with the chart sheets.
public void ProcessAllCharts()
{
XlsFile xls = new XlsFile(true);
xls.Open("filewithcharts.xls");
for (int iSheet = 1; iSheet <= xls.SheetCount; iSheet++)
{
xls.ActiveSheet = iSheet;
//Process charts embedded as objects in worksheets.
for (int iChart = 1; iChart <= xls.ObjectCount; iChart++)
{
TShapeProperties props = xls.GetObjectProperties(iChart, true);
ProcessChart(xls, iChart, props); //We need to process it even if it is not a chart, since it might be a group with a chart inside.
}
//Process chart sheets.
if (xls.SheetType == TSheetType.Chart)
{
ExcelChart chart = xls.GetChart(1, null);
DoSomething(xls, chart);
}
}
xls.Save("changedfilewithcharts.xls");
}
private void ProcessChart(ExcelFile xls, int iChart, TShapeProperties props)
{
if (props.ObjectType == TObjectType.Chart)
{
ExcelChart chart = xls.GetChart(iChart, props.ObjectPath);
DoSomething(xls, chart);
}
for (int i = 1; i <= props.ChildrenCount; i++)
{
TShapeProperties childProp = props.Children(i);
ProcessChart(xls, i, childProp);
}
}