Hello, I need a code that automatically adds a new page with the name of the day, for example: โ08 SEP 2024โ, the code would have to check if there is already a page with the current day, and if not create it. So every day that passes a new page is created with the day. I tried to do it with chatgpt but the sheet is not updated, it seems that the information is not sent to the sheet, I already have the API to connect it.
#๐ Add new page every day on google sheet
12 messages ยท Page 1 of 1 (latest)
@sleek kettle
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
This is incredibly simple using Google Apps Script, with a daily timer trigger.
That is, not with Python.
function createDateSheet() {
// Get the active spreadsheet
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// Get today's date and format it as "DD MMM YYYY"
var today = new Date();
var formattedDate = Utilities.formatDate(today, Session.getScriptTimeZone(), "dd MMM yyyy").toUpperCase();
// Check if the sheet with the formatted date already exists
var sheet = spreadsheet.getSheetByName(formattedDate);
// If the sheet doesn't exist, create a new one
if (sheet) {
return
}
spreadsheet.insertSheet(formattedDate);
}
This is the code you need. Go to the Extensions menu, choose 'Apps script'.
Paste the code and save it in their web IDE.
Then under the left menu you'll see a clock, that's 'Triggers'. Add a trigger to run this function (createDateSheet) at whatever time you want it to, daily.
Now Google will go ahead at that time and their cloud Workspace will execute the code and do what you want it to do. No self hosting necessary.
If for some reason you really need to do it with Python because of some sort of requirement/coupling, please ignore all of the above. Your use case wasn't specified ๐
thanks you !
thank you so much!
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.