Yes, you can turn a Google Sheet into a working web app with Apps Script. The script reads and writes data in the sheet, and you deploy it as a web app so anyone with the link can use it. This guide walks you through creating a simple form that saves data to a sheet, then deploying it as a web app.
What You'll Need
- A Google account (free).
- A Google Sheet (create a new one).
- Basic familiarity with the Apps Script editor (no coding experience required for this example).
Step-by-Step
- Create a new Google Sheet. Go to sheets.new in your browser and name it something like "Web App Data". In row 1, add headers: Timestamp, Name, Email, Message. These will be the columns your web app writes to.
- Open the Apps Script editor. In the sheet, click Extensions > Apps Script. A new tab opens with a code editor. Delete any placeholder code.
- Paste the server-side code. Replace the code with the following (this handles both showing the form and saving data):
Note: If your sheet tab is not named "Sheet1", change the name in the code.function doGet() { return HtmlService.createHtmlOutputFromFile('Index'); } function processForm(formObject) { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); sheet.appendRow([new Date(), formObject.name, formObject.email, formObject.message]); return 'Thank you, ' + formObject.name + '!'; } - Create the HTML file. In the Apps Script editor, click the plus icon next to "Files" and choose HTML. Name it "Index" (without .html). Paste this code:
<!DOCTYPE html> <html> <head> <base target="_top"> </head> <body> <form id="myForm"> <label>Name:</label><br> <input type="text" name="name" required><br> <label>Email:</label><br> <input type="email" name="email" required><br> <label>Message:</label><br> <textarea name="message" required></textarea><br> <input type="submit" value="Submit"> </form> <div id="output"></div> <script> function handleFormSubmit(event) { event.preventDefault(); var form = event.target; google.script.run.withSuccessHandler(showOutput).processForm(form); } function showOutput(response) { document.getElementById('output').innerHTML = response; document.getElementById('myForm').reset(); } </script> </body> </html> - Save the project. Click the save icon (floppy disk) or press Ctrl+S (Cmd+S on Mac). Give the project a name like "My Web App".
- Deploy as a web app. Click Deploy > New deployment. Click the gear icon next to "Select type" and choose "Web app". Fill in:
- Description: optional.
- Execute as: Me (your email).
- Who has access: Anyone (or Anyone with Google account, depending on your needs).
- Copy the web app URL. After deployment, you'll see a URL like https://script.google.com/macros/s/.../exec. Copy it.
- Test the web app. Open the URL in a new tab. You should see the form. Fill it out and submit. Check your Google Sheet: a new row should appear with the data and timestamp.
- Update the deployment when you change code. If you edit the script later, you must create a new deployment (Deploy > New deployment) or use Deploy > Manage deployments to edit the existing one and select "New version". Otherwise, the web app will still run the old code.
Common Mistakes
- Forgetting to authorize the script. The first time you deploy, you must grant permissions. If you see an error about permissions, re-deploy and complete the authorization flow.
- Using the wrong sheet name. The code references "Sheet1". If your tab has a different name, the script will fail. Either rename the tab or update the code.
- Not updating the deployment after code changes. Many people edit the script, save, and then wonder why the web app still shows the old behavior. You must deploy a new version.
- Assuming the web app is private. If you set access to "Anyone", anyone with the link can submit data. Do not use this for sensitive information without adding authentication.
- Mixing up doGet and doPost. The example uses doGet to serve the form and google.script.run to call the server function. If you try to use doPost without configuring the form method, it won't work as expected.
Tips
- Use
google.script.runfor seamless form submission without page reloads. It's the recommended way to call server functions from the client. - Add validation on both client and server side. The HTML form uses required attributes, but you can also check data in
processFormbefore writing to the sheet. - To display the submitted data in the web app, modify
showOutputto build a table or message. You can also return data from the server and render it. - If you need to read data from the sheet and display it, create a function like
getData()that returns values, and call it withgoogle.script.run.withSuccessHandler(...).getData(). - For debugging, use the Apps Script editor's execution log (View > Logs) to see errors and output from server-side functions.
Troubleshooting
- The web app shows an error or blank page. Check that the HTML file is named exactly "Index" and that the code has no syntax errors. Use the Apps Script editor's debugger or logs.
- Form submission does nothing. Open the browser's developer console (F12) to see JavaScript errors. Ensure the form has
onsubmit="handleFormSubmit(event)"and that the function names match. - Data not appearing in the sheet. Verify the sheet name in the code matches the actual tab name. Also check that the script has permission to edit the sheet (re-authorize if needed).
- Authorization errors. Go to Deploy > Manage deployments, delete the deployment, and create a new one, completing the authorization flow again.
- Changes not reflected. Remember to deploy a new version after editing code. The web app URL stays the same, but the code updates only after deployment.
Frequently Asked Questions
Can I use this web app to collect data from anyone?
Yes, if you set "Who has access" to "Anyone". The web app will be publicly accessible via the link. Be cautious about collecting sensitive information without additional security.
Do I need to pay for Google Apps Script?
No, Apps Script is free with a Google account. There are usage quotas, but they are generous for personal use.
Can I customize the form's appearance?
Yes, you can add CSS styles to the HTML file. You can also use Google's HTML service to include external stylesheets or use templates.
How do I update the web app after changing the code?
Go to Deploy > Manage deployments, click the edit icon (pencil), and under "Version" select "New version". Then click Deploy. The URL remains the same.
What if I need to read data from the sheet and display it?
Create a server function that returns the data (e.g., getData()), then call it from the client using google.script.run.withSuccessHandler(displayData).getData(). Use JavaScript to render the data in the HTML.
Is there a limit to how many rows I can add?
Google Sheets has a limit of 10 million cells per sheet. For a simple form, this is unlikely to be an issue. Apps Script also has daily quotas for script runtime and triggers, which you can check in the Google Cloud Console.