检索Google表格中的行数 [英] Retrieve number of rows in Google Sheets

查看:75
本文介绍了检索Google表格中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种JavaScript方法来计算网页中的Google工作表(用作表单的响应表)中的行数.我一直在网上搜寻有关如何将Google表格制作成数据库的简单教程.

I need a JavaScript method for my webpage to count how many rows are in a Google sheet (it's used as a response sheet for a form). I've been scouring the web for easy tutorials on how to make Google Sheets into a database.

有更简单的方法吗?

我在Google脚本方面经验不足,但是我所需要的只是使用Ajax或类似的JavaScript方法对电子表格进行读取访问的方式.

I don't have much experience in Google scripts, but all I need is a way I can have read access to the spreadsheet using preferably Ajax or some similar JavaScript method.

推荐答案

要检索Google电子表格中的行数,请使用以下命令:

To retrieve the number of rows in your Google Spreadsheet use the following:

var ss = SpreadsheetApp.openById("1qNCf0wKl................");
var sheet = ss.getSheetByName("sheet_name");
var number = sheet.getMaxRows().toString();
var number = number.replace(".0","");
Logger.log(number);

为了对电子表格具有读取权限,以下链接中提供的指导已经足够好:

In order to have read access to a Spreadsheet the guidance provided in the following link is good enough:

使用URL参数查询Google电子表格

例如,如果要在电子表格中获取所有带有单词"budget"的单元格,请使用以下脚本:

For example, if you want to get all the cells with the word «budget» in your Spreadsheet, use the following script:

var id = "1qNCf0wKlx1RF......";
var column = "A";
var query = "budget";
var url = "https://docs.google.com/spreadsheets/d/"+id+"/gviz/tq?tq=SELECT%20*%20where%20"+column+"%20contains%20%22"+query+"%22";
var text = UrlFetchApp.fetch(url).getContentText().toString();
Logger.log(text);

为此,必须先发布电子表格.检索预算"行后,必须对文本进行格式化,但这是另一个问题.

For this, the Spreadsheet has to be published previously. After retrieving the «budget» rows the text has to be formated, but that's another issue.

这篇关于检索Google表格中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆