Hi I am writing a C# code to generate chart in an excel sheet, fetching data from SQL server.
Writing the following code to to declare chart. It is giving exception for Index. Help me solve this.
Worksheet sheet1 = workbook.Worksheets[0];
Worksheet sheet2 = workbook.Worksheets[1];
Chart chart = sheet2.Charts[0];
Exception is in chart declaration.
Thanks in advance
Exception is probably occurring because the the Charts collection of sheet2 is empty.
Check to see if the count of sheet2.Charts is greater than zero before calling Charts[0]: