I’m trying to write a dataframe into a googlesheet on google drive using python and I keep getting the same error : “IndexError: At least one sheet must be visible”.
So here’s how my code works :
My file contains three (3) sheets. I’m interested in working on “Data” :
-
I read the file using :
df_cases = pd.read_excel(file_path, sheet_name='Data')
-
I execute the different functions of my main code on the dataframe
-
I try to save back the new
df_cases
to the same sheet using the code :
from openpyxl import Workbook
with pd.ExcelWriter(file_path, engine='openpyxl') as writer:
# Load the existing workbook
writer.book = load_workbook(file_path)
# Write the df_cases DataFrame to the "Data" sheet
df_cases.to_excel(writer, sheet_name='Data', index=False)
But, I get the same error over and over : IndexError: At least one sheet must be visible
PS1 : I’m using google colab
PS2 : I have a part of my code that asks me for access to the drive and all, eventhough I don’t think that’s the problem!.
PS3 : Deleting the whole sheet and rewriting it with the same name is an option, but I need to keep the other 2 sheets
Any ideas on how to fix this?