从Google电子表格中获取一系列单元格 [英] Take a range of cells from a Google spreadsheet

查看:55
本文介绍了从Google电子表格中获取一系列单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里编码菜鸟,尝试学习...

Coding noob here, trying to learn...

我正在尝试在一个Google电子表格中获取一系列单元格(不与任何页面/工作表边框相邻),将范围转换为pdf,然后将pdf作为电子邮件附件通过电子邮件发送到指定地址.我可以使用预写的插件,但是我不会学习.一个人只能通过提问来学习.

I'm trying to take a range of cells in one google spreadsheet (not contiguous to any page/sheet border), convert the range to pdf, then email the pdf as an email attachment to a specified address. I can use a prewritten addin, but then I won't learn. A person only learns by asking questions.

我用Google搜索了答案,然后转到了该网站( https://ctrlq.org/code/19869-email-google-spreadsheets-pdf ).麻烦的是,此脚本将所有工作表发送到一个zip文件中.我不想这么做我只想以PDF格式发送仅位于第一张工作表中的一系列选定单元格,而不是以zip文件格式发送为pdf.

I googled for answers, and got to this website (https://ctrlq.org/code/19869-email-google-spreadsheets-pdf). Trouble is, this script sends all of the sheets in a zip file. I don't want to do this. I just want to send, as a pdf, a range of selected cells located in only the first sheet and as a pdf, NOT a zip file.

我几乎不存在的javascript知识告诉我,我的脚本使用以下代码片段来获取相关数据:(显然,我可能错了...)

My almost nonexistent javascript education tells me that my script uses the following code snippet to obtain the relevant data: (Obviously, I might be wrong...)

// Get the currently active spreadsheet URL (link)
// Or use SpreadsheetApp.openByUrl("<<SPREADSHEET URL>>");
var ss = SpreadsheetApp.getActiveSpreadsheet();

我不知道我是否有正确的代码段,这就是为什么我包含其源URL的原因.无论如何,我只是想发送一个从第2行第3列开始到第31行第12列结束的范围.7天后,我想使用另一个脚本发送另一个范围.

I don't know if I've got the correct snippet, which is why I included the URL of its source. Anyhow, I simply want to send a range starting at row 2 column 3 and ending at row 31 column 12. 7 days later, I want to use another script to send a different range.

如何修改此脚本以实现我的目标?

How can I modify this script to achieve my goal?

感谢所有能提供帮助的人!

Thanks to everyone who can help!

推荐答案

首先,您需要了解您的要求和真正的要求.

First of all you need to understand what you are asking for and what it's really called.

Robin Gertenbach 在评论中所述,您应该查看

As noted in the comment by Robin Gertenbach you should look at the Google Documentation first. Only after you have exhausted the information there should you look elsewhere for code snippets etc. The reason I am saying this is that a range is most likely not what you think it is. The range object itself is not data you need but is a class that you can use to obtain the information instead.

例如,如果您想要值,则可以执行类似 SpreadsheetApp.getActiveRange().getValues()之类的操作,该方法将返回2个字符串值数组.但是,没有这样的方法来将字符串输出为pdf.从逻辑上讲,PDF是一个文档,因此要获取PDF,您需要导出一个文档.最低的文档类型是实际的电子表格,在文档中,您可以看到

For example if you want values you would do something like SpreadsheetApp.getActiveRange().getValues() which would return an 2 array of string values. However, there is no such method to output a string of characters as a pdf. Logically a PDF is a document, so to get a PDF you need to export a document. The lowest document type is the actual spreadsheet and in the documentation you can see that here

您可以想到的所有其他内容都将来自Javascript,而不是Google Apps Script,因此您可以在其中查找.唯一的替代方法是创建一个新的电子表格并将其另存为pdf,然后删除该电子表格.

Anything else you can think off will come from Javascript and not Google Apps Script, so that is where you could look. The only alternative here is to create a new spreadsheet and save it as a pdf, then delete the spreadsheet.

您拥有的代码片段只是创建一个以整个电子表格为对象的变量.

The snippet you have is simply creating a variable with the entire spreadsheet as the object.

这篇关于从Google电子表格中获取一系列单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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