Is it possible to create a public database (spreadsheet) search with Google Scripts?

后端 未结 1 576
甜味超标
甜味超标 2021-02-06 18:32

I\'m trying to create a website where users can come and look for a set of resources, something like a portal, or a database like JSTOR. I am using Weebly; this website will ev

1条回答
  •  天涯浪人
    2021-02-06 19:04

    Yes this is certainly possible, but can achieved in a variety of ways.

    One approach you could take with this is to retrieve all the data from the spreadsheet as JSON format and add it to the DOM as a HTML table. Then you can use a nice plugin like dataTables which has a pretty good native search function. I'll give a basic example below.

    To retrieve the data you can use Googles spreadsheet JSON API. A basic example is below.

    
    
    • Where ID is the spreadsheet's long ID.
    • Where WS is the worksheet number e.g. 1,2,3 etc.
    • Where FN is the function you want to call. In my below function i use importGSS

    Then I've written the below script that adds the data to a HTML table. It first adds the first row to a section and then adds the rest to the section.

    function cellEntries(json, dest) {
        var table = document.createElement('table');
        var thead = document.createElement('thead');
        var tbody = document.createElement('tbody');
        var thr;
        var tr;
        var entries = json.feed.entry;
        var cols = json.feed.gs$colCount.$t;
    
        for (var i=0; i 

    You can then call back the function with ... where #Destination is the

    you want to add the HTML table to.

    function importGSS(json){
       cellEntries(json, '#Destination');
    };
    

    Once all completed you'll see something like the below screenshot, the top the final results and the bottom the original spreadsheet. I've edited out some information. I hope this has been of some help.

    enter image description here

    0 讨论(0)
提交回复
热议问题