You have created an array that could contain just one element and this element will be stored at index 0. Of course if you have more than one instance of class A in your inner loop you need more elements in the array.
Instead of using arrays you could change your code to use a List<string>
using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
{
List<string> allTheSheets = new List<string>();
List<string> allTheData = new List<string>();
S sheets = spreadsheetDocument.WorkbookPart.Workbook.Sheets;
foreach (E sheet in sheets)
{
foreach (A attr in sheet.GetAttributes())
{
string sheetName = attr.Value;
allTheSheets.Add(attr.Value.ToString());
}
}
At the end of this two loops you will have all the A values in your list allTheSheets
and you can use another foreach to look at its content.
Said that, your code looks a bit strange. The index used to store and print the string element is always zero and thus you should not have any Index Out Of Bound
.