Consider selecting the Sheet by name rather than index. For example using a free library that does not require Excel to be installed and is easy to read and write cell data.
https://www.nuget.org/packages/SpreadsheetLight/
Or
https://www.nuget.org/packages/SpreadsheetLight.Core/
/// <summary>
/// Open file to specific sheet
/// </summary>
/// <param name="fileName">Existing Excel file name</param>
/// <param name="sheetName">Existing Sheet name in file</param>
public static void Work(string fileName, string sheetName)
{
using (var document = new SLDocument(fileName, sheetName))
{
// some code do write to the cells of selected sheet
}
}