技术求助:Google Sheets跨表内容添加函数及学校日报应用开发
Hey there! Sounds like you've made solid progress on your daily announcement app for the school—great job getting those scripts set up for data cleanup, sorting, and template creation. Let's break down how to use Sheets functions to pull content into your target sheet, with options that fit different needs:
1. Basic Full Data Sync (Same Spreadsheet)
If you just need to pull all non-empty rows from your sorted data sheet into the new date-named template sheet, use the QUERY function—it’s dynamic and will auto-update when your data changes.
In your target sheet (the one you created with the date name), pick a starting cell (e.g., A2, since you already added the date at the top) and paste this formula:
=QUERY(DataSheet!A:Z, "SELECT * WHERE A IS NOT NULL", 1)
- Replace
DataSheetwith the actual name of your sorted data sheet A:Zcovers all columns—adjust this to your actual column range (e.g.,A:Fif you only use 6 columns)- The
1at the end tells QUERY to treat the first row of your data sheet as a header WHERE A IS NOT NULLskips any blank rows in your data
2. Filter Content by Announcement Category
If you want to only pull specific categories (e.g., "Staff Updates" or "Student Notices"), modify the QUERY condition to target your category column. Let’s say your category is in column C:
=QUERY(DataSheet!A:Z, "SELECT * WHERE C = 'Staff Updates' AND A IS NOT NULL", 1)
- Swap
'Staff Updates'with your actual category name, and adjust columnCto match your sheet’s structure
3. Auto-Insert the Function via Your Existing Script
Since you already have a script that creates the date-named sheet, you can automate adding this formula so you don’t have to do it manually every time. Add this snippet to your template creation script:
// After creating your new date-named sheet (replace variables to match your code) const newSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Daily_20240520"); // Or use the sheet object from your creation code const dataSheetName = "DataSheet"; // Your sorted data sheet name // Insert the QUERY formula starting at cell A2 newSheet.getRange("A2").setFormula(`=QUERY(${dataSheetName}!A:Z, "SELECT * WHERE A IS NOT NULL", 1)`);
This will automatically populate the content as soon as the new sheet is created.
4. Filter by Date (For Daily-Specific Content)
If you want to only pull submissions from the current day (to keep the daily announcement focused), add a date filter to the QUERY—assuming your submission date is in column D:
=QUERY(DataSheet!A:Z, "SELECT * WHERE D = DATE'"&TEXT(TODAY(), "yyyy-MM-dd")&"' AND A IS NOT NULL", 1)
This will dynamically show only entries from today, no matter when you open the sheet.
Quick Tips
- Test the formula in a dummy sheet first to make sure it pulls the right data
- If you need to format the pulled content (e.g., bold headers, cell colors), you can apply conditional formatting directly to the target sheet
- If your data is in a different spreadsheet, use
IMPORTRANGEinstead ofQUERY(but since you’re syncing via form to the same sheet,QUERYis more efficient)
Let me know if you need help tweaking any of this to match your exact sheet layout or if you want to combine it with your existing sorting/cleanup scripts for a more seamless workflow!
内容的提问来源于stack exchange,提问作者Rob Campbell

