Using Google Scripts to Query Multiple Google Sheets to A View

为君一笑 提交于 2021-01-29 10:25:42

问题


I have a Google Spreadsheet that stores employee availability information for my workplace. Every Sheet has the format shown in the example below, with the date fields changing based on the week for which I am collecting availability. Employees submit availability every week by submitting a Google Form that is linked to these Sheets on the backend. My workplace leadership has directed that I limit each Sheet to contain at most one week of data.

09 Jul - 13 Jul Responses

Timestamp         | Email Address   | What is your name? | [Mon Jul 2018] | [Tue Jul 10 2018] | ... | [Fri Jul 13 2018] | Comments
7/9/2018 16:30:48 | johndoe@aol.com | John Doe           | Available      | Not Available     | ... | Available         | Must leave by 3:30 p.m.
7/9/2018 16:32:51 | janedoe@aol.com | Jane Doe           | Not Available  | Available         | ... | Available         | None

The problem I am encountering is that my boss wants me to generate a clean view of employee availability covering an arbitrary date span. In other words, he wants to have the option of selecting a date span and seeing all the employees who are available on each day in that date span. This is problematic for generating, say, a monthly view of availability because it involves parsing multiple sheets each covering a single week.

My intuition says I need to create a Google Web App that allows a user to query my Spreadsheet with two fields: StartDate and EndDate. I'd need some code that then iterates over every record in every spreadsheet to determine who's available on every day in that date span, push those records in object format to a list, and then use those objects to generate an HTML output on the Web App page. This would allow multiple users to generate whatever availability display they want.

What is the best way to allow a user to enter a date span and output all the employees who are available in that date span using Google Scripts?


回答1:


Your current setup where you have records spanning multiple sheets is inefficient from a query standpoint and is going to be difficult to maintain as the data scales up.

I'd move all that data into a true database (google cloud has a number of storage options) and then leverage Apps Script to query said database using a date range and populate a sheet with the results.

Google Sheets are a viable storage solution for relatively small non-relational data sets. But as you scale up and you want to execute more complex queries its limitations become more evident. They can still serve as a platform to display the results of a query, but with respect to storage that needs to scale I'd recommend offloading that to a proper database solution.



来源:https://stackoverflow.com/questions/51325614/using-google-scripts-to-query-multiple-google-sheets-to-a-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!