[英]Automatically generate a calendar document using Google Drive and Google Apps Script
I have a question regarding Google Docs and Google Apps Script. 我对Google文档和Google Apps脚本有疑问。
Is it possible to use Google Apps Script to 'automatically' create a calendar document in Google Drive with the following document features. 是否可以使用Google Apps脚本在Google云端硬盘中“自动”创建具有以下文档功能的日历文档。
I know Google Apps Script can automatically create documents and add content. 我知道Google Apps脚本可以自动创建文档并添加内容。 I'm just not sure it can "automatically" and "accurately" place dates in the correct locations. 我只是不确定它可以“自动”和“准确”地将日期放置在正确的位置。 I don't want to start down the path if the goal I seek isn't an option. 如果我追求的目标不是一个选择,我不想走这条路。
I threw this together pretty quickly but you should be able to modify it pretty easily. 我很快就将其组合在一起,但是您应该可以轻松地对其进行修改。 You can get the dates to show up in the right columns by getting the day of the week of the first day of the month and then inserting dates into the corresponding cells of a 2D array. 您可以通过获取月份第一天的星期几,然后将日期插入2D数组的相应单元格中,来在右列中显示日期。 Then insert the array as a table. 然后将数组插入为表格。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.