如何在Google Appscript上获取今日约会?
我需要在一个单元格中编写一个输入日期的代码
function changeDate(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(GA_CONFIG);
var date = //Today´s date!?!?!!?
var endDate = date;
sheet.getRange(5, 2).setValue(endDate);
}
Run Code Online (Sandbox Code Playgroud) 我想使用Google Spreadsheets和Google Apps脚本创建一个刮刀.我知道这是可能的,我已经看过一些关于它的教程和线程.
主要想法是使用:
var html = UrlFetchApp.fetch('http://en.wikipedia.org/wiki/Document_Object_Model').getContentText();
var doc = XmlService.parse(html);
Run Code Online (Sandbox Code Playgroud)
然后开始使用这些元素.但是,方法
XmlService.parse()
Run Code Online (Sandbox Code Playgroud)
对某些页面不起作用.例如,如果我尝试:
function test(){
var html = UrlFetchApp.fetch("https://www.nespresso.com/br/pt/product/maquina-de-cafe-espresso-pixie-clips-preto-lima-neon-c60-220v").getContentText();
var parse = XmlService.parse(html);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error on line 225: The entity name must immediately follow the '&' in the entity reference. (line 3, file "")
Run Code Online (Sandbox Code Playgroud)
我试图用来string.replace()
消除显然导致错误的字符,但它不起作用.出现所有其他错误.以下代码为例:
function test(){
var html = UrlFetchApp.fetch("https://www.nespresso.com/br/pt/product/maquina-de-cafe-espresso-pixie-clips-preto-lima-neon-c60-220v").getContentText();
var regExp = new RegExp("&", "gi");
html = html.replace(regExp,"");
var parse = XmlService.parse(html);
}
Run Code Online (Sandbox Code Playgroud)
给我以下错误:
Error on line 358: The content of elements must …
Run Code Online (Sandbox Code Playgroud) javascript parsing html-parsing google-sheets google-apps-script
我用它ArrayFormula()
来简化我创建报告的方式.
而不必建立在每个单元格(参考例如,=C1
,=C2
,=C3
,=C4
在每个单元中,我只是用=arrayformula(C1:C4)
一个单细胞,它不正是相同的工作,但要简单得多,这让事情变得更有条理,因为我只需要在一个单元格中查找可能的错误.
当我必须将范围引用到另一个范围时,例如将C1:C4的值引入A1:A4范围时,它的效果很好.在A1单元格中,我会写=arrayformula(C1:C4)
,它会发挥其魔力.
当范围长度不同时,它确实有点棘手,但它仍然是可行的.例如,如果我想在B1:B3的顶部堆叠两个或更多范围链接C1:C4,则在单元格A1上我可以写入=arrayformula({C1:C4;B1:B3})
.
我的问题是arrayFormula()
用于复制重复模式.例如,如果我想复制单元格C1的内容4次,我会使用=arrayformula({C1;C1;C1;C1})
.
这将起作用并将达到预期的效果.但是,我想知道是否有更好的方法来做到这一点.像=arrayformula({C1}*12)
这种模式会重复12次.这也使我能够拥有一个动态公式,例如=arrayformula({C1}*count(D:D))
模式根据某个变量重复的位置.
你是否有任何关于如何使用原生公式(没有javascript)实现这一目标的想法?
在为Google电子表格编写代码时,是否可以在google apps脚本中使用本机电子表格函数(如sum()或today())?如果是这样,我该怎么办?
抱歉这个愚蠢的问题.
我知道如何使用VBA for Excel进行编程,但我很难在Google Spreadsheet中完成最简单的工作,而且我无法在线找到任何好的教程.
我的问题是关于细胞.在VBA写入单元格我会做:
cells(1,1) = 2 //that would write the number 2 in the first row of the first column
Run Code Online (Sandbox Code Playgroud)
在VBA中,我还可以将一个单元格分配给变量,例如:
dim something as long
something = cells(1,1)
Run Code Online (Sandbox Code Playgroud)
如何在Google SpreadSheet中应用相同的原则?
非常感谢你!
我试过你们的建议.现在我有一个跟进问题.
我试图修改特定范围内的单元格.我试过这段代码:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var board = sheet.getRange(2,2,9,9);
board[0][0].setValue(2);
Run Code Online (Sandbox Code Playgroud)
但显然我不能使用数组表示法.我不确定.setValeu或.getRange是否有问题.但有没有办法可以使用数组符号来表达一个单元格?
再次感谢!
对不起,对于这个愚蠢的问题,但我搜索了整个互联网,我找不到一个好的教程来学习如何在Google SpreadSheet Script中编程.
我想为练习做一个非常简单的功能.
function simplesum(input) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets();
var range = sheet.getRange(input);
var x = 0;
for (var i = 1; i <= range.getNumRows(); i++) {
for (var j = 1; j <= range.getNumColumns(); j++) {
var cell = range.getCell(i, j);
x += (cell.getValue());
}
}
return x;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用= sum()做同样的事情.这里的想法是学习如何编程.
当我尝试在单元格中使用我的函数时:(即:= simplesum((A1:A8))它给出一个错误说:"TypeError:在对象表中找不到函数getRange.(第4行)"
我该怎么办?
再一次,抱歉这个愚蠢的问题....
我需要将Google SpreadSheet上的工作表复制到另一个SpreadSheet文档.
我已经完成了我的研究,我找到了两种方法来做到这一点,但是两者都存在我不知道如何修复的问题.
第一种方法使用格式复制工作表,但它保留了引用的单元格,因此我在新文档(#ref)中得到引用错误.我需要一个复制格式和值(不是引用)的函数.
function copySheet() {
var source = SpreadsheetApp.getActiveSpreadsheet();
var sheet = source.getSheets()[0];
var destination = SpreadsheetApp.openById("15ucPbZrIYXZAOCYVdpK6OA0oyQT1NcsmuiJmDRfdpHQ");
sheet.copyTo(destination);
}
Run Code Online (Sandbox Code Playgroud)
第二种方法复制没有引用的值,但它只复制值,没有格式.
function copySheetValues()
{
var source = SpreadsheetApp.getActiveSheet();
var sourcename = source.getSheetName();
var sourceDataRange = source.getDataRange();
var sourceSheetValues = sourceDataRange.getValues();
var sourceRows = sourceDataRange.getNumRows();
var sourceColumns = sourceDataRange.getNumColumns();
var destination = SpreadsheetApp.openById('15ucPbZrIYXZAOCYVdpK6OA0oyQT1NcsmuiJmDRfdpHQ');
destination.insertSheet(sourcename, 0);
destination.getDataRange().offset(0, 0, sourceRows, sourceColumns).setValues(sourceSheetValues);
}
Run Code Online (Sandbox Code Playgroud)
如何编写保留格式并复制值的函数?
我在我的代码中尝试了一些东西并且它不起作用(编译时的错误是"本地变量fundo永远不会被读取").我做了一些改变并且它有效,但我想知道它为什么不起作用.
我有一个名为Setor的类,在我的代码中我试图在Vendedor类中创建该类的对象
这是我的第一个代码:
class Vendedor{
void abreTeatro(int codigoCamarote, int capacidadeCamarote, int precoCamarote, int codigoFrente,
int capacidadeFrente, int precoFrente, int codigoMeio, int capacidadeMeio, int precoMeio, int codigoFundo,
int capacidadeFundo, int precoFundo)
{
Setor camarote = new Setor(codigoCamarote, capacidadeCamarote, precoCamarote);
Setor frente = new Setor(codigoFrente, capacidadeFrente, precoFrente);
Setor meio = new Setor(codigoMeio, capacidadeMeio, precoMeio);
Setor fundo = new Setor(codigoFundo, capacidadeFundo, precoFundo);
};
}
Run Code Online (Sandbox Code Playgroud)
如果我在方法之外创建对象,它可以正常工作,如下所示:
class Vendedor{
Setor camarote;
Setor frente;
Setor meio;
Setor fundo;
void abreTeatro(int codigoCamarote, int capacidadeCamarote, int precoCamarote, int …
Run Code Online (Sandbox Code Playgroud) 我想使用谷歌应用程序脚本在谷歌电子表格中创建一个简单的自定义总和公式。
\n\n function somaDias(range, days) {\n var sum = 0;\n\n for(i=0; i<days; i++){\n sum = sum + range[i];\n }\n\n\n return soma;\n }\n
Run Code Online (Sandbox Code Playgroud)\n\n我将在报告中使用此函数,该报告有一列包含每月每一天的货币值。这个想法是选择整列值,将其作为范围传递,然后将这些值求和到该月的某一天。我知道有问题
\n\n sum = sum + range[i];\n
Run Code Online (Sandbox Code Playgroud)\n\n因为,当我用只有 1 的列测试它时...返回是“0111111”
\n\n=somaDias(C9:C15;6) // 应该返回 6,但它返回 0111111
\n\n我不想使用 =sum(),因为范围根据日期而变化。我想传递该月 30 天的范围,然后传递我想要求和的天数。如果我使用 sum,我就必须每天重新选择范围......
\n\n我\xc2\xb4m 做错了什么?
\n我知道可以通过网络界面将数据费用上传到Google Analytics .但是,我想让这个过程更加自动化,所以我考虑使用谷歌电子表格和谷歌应用程序脚本来缩短这个过程.
我的想法是在spreadSheet上获取我要上传到Google Analytics的数据,然后使用Google Apps Script Advanced Services将数据费用上传到我的Google Analytics(分析)财产.遗憾的是,Google App Script Advanced Services上的文档非常有限.所以我跳了一些人可以帮助我.这是迄今为止所做的:
function uploadDataCost() {
var accountId = "XXXXXXXX";
var webPropertyId = "UA-XXXXXXX";
var customDataSourceId = "XXXXXXXXXXXXX";
var csvData = convertRangeToCSVString();
var mediaData = Utilities.newBlob([]); //This variable is my main problem.
Analytics.Management.Uploads.uploadData(accountId, webPropertyId, customDataSourceId, mediaData);
}
Run Code Online (Sandbox Code Playgroud)
我找到了一个代码,将范围转换为CSV作为字符串.但我不知道如何获取此字符串并将其转换为blob,因此我可以将其用作方法中的mediaData参数Analytics.Management.Uploads.uploadData(accountId, webPropertyId, customDataSourceId, mediaData);
.
我相信调用这个方法可以解决问题,但我不知道如何传递mediaData参数中的数据,正如我所说,我找不到任何解释这种方法是如何工作的文档.我知道mediaData应该是Blob类型,但我找不到任何解释如何创建一个CSV文件的Blob的例子.
csv google-analytics google-sheets google-apps-script google-spreadsheet-api
javascript ×2
class ×1
constructor ×1
csv ×1
formulas ×1
html-parsing ×1
java ×1
methods ×1
parsing ×1