我对Google文档和Google Apps脚本有疑问。
是否可以使用Google Apps脚本在Google云端硬盘中“自动”创建具有以下文档功能的日历文档。
我知道Google Apps脚本可以自动创建文档并添加内容。我只是不确定它能否“自动”和“准确地”将日期放在正确的位置。如果我寻求的目标不是一个选择,我不想开始走下去。
答案 0 :(得分:1)
我很快把它扔到一起,但你应该能够很容易地修改它。您可以通过获取该月第一天的星期几,然后将日期插入到2D阵列的相应单元格中,来显示右侧列中显示的日期。然后将数组作为表格插入。
function create_cal() {
var doc = DocumentApp.create("Calendar"),
body = doc.getBody(),
cells = [
['','','','','','',''],
['','','','','','',''],
['','','','','','',''],
['','','','','','',''],
['','','','','','',''],
['','','','','','','']
],
now = new Date(),
date = new Date(now.getFullYear(), now.getMonth(), 1),
cur_month = now.getMonth(),
row = 0,
col = date.getDay();
while (cur_month == date.getMonth()) {
cells[row][col] = date.getDate();
col += 1;
if (col > 6) {
col = 0;
row += 1;
}
date = new Date(date.getTime() + 1000*60*60*24);
}
body.setText('Calendar Name');
body.appendTable(cells);
}