I am using gspread to interact with my Google spreadsheets and pandas to manipulate that data. I have set up a Google API account and have done all the authentication following this article. I am able to retrieve the data except for the comments from cells. In my Google Sheets dataset, I have certain columns and there are some comments that exist on certain cells. My end target is to convert the spreadsheet data into an array of objects where each object represents a single row record and if a comment exists in any of the cells then I need to extract that as well.
I have tried pygsheets but it's not supporting the comment feature and also not able to find anything in gpsread to extract comments.
I have tested openpyxl by giving the local path of my Google Work Sheet and it does extract comments but I need to figure out how it can be along with Google Sheet API.
Sample Code:
with open("automate-0738852.json", 'r') as j:
service_account_info = json.loads(j.read())
credentials = service_account.Credentials.from_service_account_info(service_account_info)
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
creds_with_scope = credentials.with_scopes(scope)
client = gspread.authorize(creds_with_scope)
gc_client = pygsheets.authorize(custom_credentials=creds_with_scope)
spreadsheet = client.open_by_url('https://docs.google.com/spreadsheets/d/spreadsheetID/edit?usp=sharing')
worksheet = spreadsheet.get_worksheet(0)
records_data = worksheet.get_all_records(head=6)
records_df = pd.DataFrame.from_dict(records_data)
# Removing the empty title header
records_df.columns = records_df.columns.astype(str).str.strip()
records_df.drop(columns=[''], errors='ignore', inplace=True)