标签: google-docs

在 Google 网站中嵌入 Google 电子表格时,Google Apps 脚本可帮助解决错误?

电子表格 A 是欢迎新移民来到我们小镇的团队的主数据源。它里面有大量非常敏感的数据,不能公开,哪怕是一点点。(我们谈论的是孩子的姓名和出生日期以及他们在哪里上学……保证电子表格 A 的安全是至关重要的任务。)

因此,电子表格 B 使用 importRange 和查询从电子表格 A 中提取必要的列来填充我们的“成员目录”。

然后,我将电子表格 B 嵌入到该小组的 Google 网站中。(如果您愿意,请随时访问该网站 www.SewickleyNewcomers.com )

而且效果非常好。

但 。。。在我关闭电子表格 A 和 B 几个小时后,如果我尝试打开嵌入了会员目录的网页,嵌入的工作表会显示“#VALUE!”

然后,当我再次打开电子表格 B 时,它显示相同的内容:“#VALUE!”。

直到,我让电子表格 B 静置了几分钟。然后,在它静置几分钟后,突然,所有数据再次填充。

如果我返回到嵌入了会员目录的网页,一切都很好。

据推测,问题在于,如果电子表格 B 未打开,则无法从电子表格 A 中提取数据。

但我无法嵌入电子表格 A,因为如上所述,有些列和工作表无法公开访问。

一些细节:

  • 电子表格 A 和电子表格 B 当前的共享首选项均设置为“知道链接的任何人”。(尽管我理想情况下希望将电子表格 A 恢复为“私有”。)

  • 电子表格 B 通过内置的插入电子表格小部件嵌入到 Google 网站中。

  • 以下是我当前用于将数据从电子表格 A 提取到电子表格 B 的公式:

    =arrayformula(query(importrange(" _ ","Master!A:Z"), "选择 Col3, Col2, Col22, Col18, Col19, Col20, Col21, Col24 其中 Col26='是的,请继续并包含我的联系信息在在线目录和打印目录中。' and (Col4='Yes' or Col4='yes') order by Col3"))

有人对这里发生的事情有什么想法吗?以及其他方式的想法,我可以从电子表格 …

google-docs google-apps-script

2
推荐指数
1
解决办法
3285
查看次数

使用 R 编辑现有的谷歌文档电子表格

我听说并一直在使用 RGoogleDocs R 包进行测试,该包可让您登录帐户并查看 google 文档以及上传或删除它们。我可以采取创建一个新文档然后在销毁旧文档后上传它的路线,但我想要一种更优雅的方式。

我使用 rgoogledocs 来访问我的电子表格。当需要编辑时,我无法更改任何值。

#this line returns the value in the worksheet in column 1 row 1
myworksheet[[1]][1,1]

#this command does nothing, but I would like to change the value to cow
myworksheet[[1]][1,1] = "cow"
Run Code Online (Sandbox Code Playgroud)

r google-docs google-docs-api

2
推荐指数
1
解决办法
681
查看次数

将 Google 表格数据直接导入 R

是否可以在没有授权密钥的情况下直接从 Google 文档将表导入 R?我有一个可共享的谷歌表,我尝试连接到闪亮的应用程序,但找不到合适的方法。

r google-docs google-sheets google-docs-api

2
推荐指数
1
解决办法
1605
查看次数

提取 DOCX 评论

我是一名教师。我想要一份所有对我布置的文章发表评论的学生的名单,以及他们说了什么。Drive API 的东西对我来说太具有挑战性了,但我想我可以将它们作为 zip 下载并解析 XML。

评论被标记在w:comment标签中,w:t用于评论文本和 。这应该很容易,但是 XML (etree) 正在杀死我。

通过教程(和官方 Python 文档):

z = zipfile.ZipFile('test.docx')
x = z.read('word/comments.xml')
tree = etree.XML(x)
Run Code Online (Sandbox Code Playgroud)

然后我这样做:

children = tree.getiterator()
for c in children:
    print(c.attrib)
Run Code Online (Sandbox Code Playgroud)

结果是这样:

{}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}author': 'Joe Shmoe', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}id': '1', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}date': '2017-11-17T16:58:27Z'}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidR': '00000000', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidDel': '00000000', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidP': '00000000', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidRDefault': '00000000', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidRPr': '00000000'}
{}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val': '0'}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val': '0'}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val': '0'}
Run Code Online (Sandbox Code Playgroud)

在此之后,我完全被困住了。我试着element.get()element.findall()没有运气。即使我复制/粘贴值 ( '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val'),我也会得到None回报。

任何人都可以帮忙吗?

python xml docx google-docs openxml

2
推荐指数
3
解决办法
4972
查看次数

在 Google Docs 中获取星期几

我遇到了一个我无法解决的问题。我有一个日志,它定期需要以特定格式更新今天的日期。我试图编写一个脚本来这样做,但基本上我想要的是分配一个键盘快捷键,但进入菜单是可以接受的。我需要的是今天的日期格式

### 星期二 - 16/01/2018

我目前得到的脚本包括这一行

var currentDate = Utilities.formatDate(new Date(), "GMT", "###  - dd/MM/yyyy");
Run Code Online (Sandbox Code Playgroud)

这让我几乎得到了我需要的一切,但在 #s 之后我想要一周中的哪一天。我可以看到一些适用于工作表的函数,它们在那里工作,但是我如何在文档中使用它?

假设我管理当前分配给自定义 UI 菜单,是否也可以将其连接到宏/键盘快捷方式?

谢谢!

google-docs google-apps-script

2
推荐指数
1
解决办法
5794
查看次数

显示嵌入谷歌文档的完整文档长度

如何在 iframe 上没有滚动条的情况下显示嵌入式 google 文档的完整长度?

<html>
<style>
    body { margin: 0; padding: 0; o}
    iframe { margin-left: 2vw; margin-top: 2vh; height: 100%; width: 90vw; }

</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<body>

<iframe srcdoc="" frameborder="0" scrolling="no" height="100%"></iframe>

    <script>
        $(function() {
            $.get("https://docs.google.com/document/d/17OkIgtNdV1flno_783tJm2xWU0NBh7uEmZ5wEXP2E9g/pub?embedded=true", function(html) {
                var contents = $("iframe").contents();

                contents.find("html").html(html);

                setTimeout(function() {
                    contents.find('a[href^="http://"]').attr("target", "_blank");
                    contents.find('a[href^="https://"]').attr("target", "_blank");
                }, 1000); // Actually not sure if timeout is required here...
            });
        });
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

显示屏可能会显示一页半的文本并停止。

html javascript google-docs

2
推荐指数
1
解决办法
3986
查看次数

Google Apps 脚本 UrlFetchApp 返回未经授权的错误 401

这是我正在使用的代码。

function doc_to_html(id)
{
  var url = "https://docs.google.com/feeds/download/documents/export/Export?id="+id+"&exportFormat=html";
var param = 
    {
      method      : "get",
      headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
      muteHttpExceptions:true,
    };
 var html = UrlFetchApp.fetch(url,param).getContentText();
  Logger.log(html);
}
Run Code Online (Sandbox Code Playgroud)

它曾多次进行测试,但现在返回“未经授权的错误 401”。更准确地说,它正在返回:

<html>
<head>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)

我查看了所有能找到的有关 UrlFetchApp 的文档,没有看到任何配额或限制。我检查了脚本范围,并且https://www.googleapis.com/auth/script.external_request已获得授权。

export google-docs urlfetch google-apps-script

2
推荐指数
1
解决办法
2061
查看次数

将 google doc 转换为 pdf 会导致空白 pdf、google 脚本

这是我创建谷歌文档的代码,粘贴一些信息(最终来自电子表格),将其转换为 pdf 并通过电子邮件发送给我自己。

不幸的是,虽然驱动器中的文档具有“此文档是由 Google Apps 脚本创建的”。在其中发表评论,电子邮件中的 pdf 没有。它有正确的标题,但页面的内容丢失了。我已经尝试了几个关于堆栈溢出的例子,但到目前为止还没有一个可以工作。

var ss = SpreadsheetApp.getActive();

function onOpen(){
var ui = SpreadsheetApp.getUi(); 
ui.createMenu('TEST MENU') //creates main menu tab 
   .addItem('pdf', 'pdf') 
   .addToUi(); 
}

function pdf() {
  // Create a new Google Doc named 'Hello, world!'
  var doc = DocumentApp.create('Hello, world!');

  // Access the body of the document, then add a paragraph.
  doc.getBody().appendParagraph('This document was created by Google Apps Script.');

 var pdfContent = doc.getAs('application/pdf');
 var draftMail = GmailApp.createDraft('will@exampleEmail.co.uk',
                                   'Email title', 'Pls see attached', 
                                   {
                                     attachments: …
Run Code Online (Sandbox Code Playgroud)

javascript google-docs google-sheets google-apps-script

2
推荐指数
1
解决办法
1021
查看次数

使用选择的 RangeElements 在 Google Doc 中获取所有嵌套的文本元素

在与上述类似的文档中,我可以使用以下代码获取所有段落:

var paras = body.getParagraphs();

请注意,上面的代码不仅返回顶级段落,还返回ListItems、Tables 等内部的所有子级段落。

如何在选定范围内做同样的事情?以下代码仅返回顶级元素。

const selection = DocumentApp.getActiveDocument().getSelection();
var rangeElements = selection.getRangeElements();
Run Code Online (Sandbox Code Playgroud)

例如,上表包含 9 个非空段落,如果它们在选择中,我想一一处理它们。

我想要实现的目标类似于通过尽可能多地保留格式、表格、列表项等来翻译选择中的文本。

google-docs google-apps-script

2
推荐指数
1
解决办法
714
查看次数

在 Google Docs 中用一个换行符替换多个换行符

Google Sheets 支持基于 Regex 的“查找和替换”中的捕获;我正在努力做这样的事情,可以在 Google Docs 上工作。

在 Google Docs 上查找和替换双换行符

我错过了使用 Docs 这样做的简单方法吗?

regex google-docs

2
推荐指数
1
解决办法
2413
查看次数