DateTime错误21-undefined-2014 [英] DateTime error 21-undefined-2014
本文介绍了DateTime错误21-undefined-2014的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码的结果如下:21-undefined-2014不确定缺少什么。请检查并建议。其他一切似乎都在正常工作。谢谢。
function onOpen(){
var ui = DocumentApp.getUi();
//或FormApp或SpreadsheetApp。
ui.createMenu('Custom Menu')
.addItem('Insert Date','insertDate')
.addToUi();
$ b函数insertDate(){
var cursor = DocumentApp.getActiveDocument()。getCursor();
if(cursor){
//尝试在光标位置插入文本。如果插入返回null,
//那么游标的包含元素不允许插入文本。
var month = [JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV , DEC];
var d = new Date();
var dd = d.getDate();
dd = pad(dd,2)
var mm = d.getMonth();
mm = pad(mm,2)
var yyyy = d.getFullYear();
var date = dd + - + month [mm] + - + yyyy;
var element = cursor.insertText(date);
if(element){
element.setBold(true);
} else {
DocumentApp.getUi()。alert('无法在此光标位置插入文本。
}
} else {
DocumentApp.getUi()。alert('在文档中找不到游标。');
$ b函数pad(str,max){
str = str.toString();
return str.length<最大? pad(0+ str,max):str;
解决方案
mm =垫(mm,2)
看看这个确认 http://jsfiddle.net/ baljeetsingh / JMs7t / 2 /
The code below results in: 21-undefined-2014 Not sure what is missing. Please check and advise. Everything else seems to be working correctly. Thank you.
function onOpen() {
var ui = DocumentApp.getUi();
// Or FormApp or SpreadsheetApp.
ui.createMenu('Custom Menu')
.addItem('Insert Date', 'insertDate')
.addToUi();
}
function insertDate() {
var cursor = DocumentApp.getActiveDocument().getCursor();
if (cursor) {
// Attempt to insert text at the cursor position. If insertion returns null,
// then the cursor's containing element doesn't allow text insertions.
var month=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
var d = new Date();
var dd = d.getDate();
dd = pad(dd, 2)
var mm = d.getMonth();
mm = pad(mm, 2)
var yyyy = d.getFullYear();
var date = dd + "-" + month[mm] + "-" + yyyy;
var element = cursor.insertText(date);
if (element) {
element.setBold(true);
} else {
DocumentApp.getUi().alert('Cannot insert text at this cursor location.');
}
} else {
DocumentApp.getUi().alert('Cannot find a cursor in the document.');
}
}
function pad (str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
解决方案
You shouldn't be doing
mm = pad(mm, 2)
Check out this to confirm http://jsfiddle.net/baljeetsingh/JMs7t/2/
这篇关于DateTime错误21-undefined-2014的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文