繁体   English   中英

使用Google云端硬盘和Google Apps脚本自动生成日历文档

[英]Automatically generate a calendar document using Google Drive and Google Apps Script

我对Google文档和Google Apps脚本有疑问。

是否可以使用Google Apps脚本在Google云端硬盘中“自动”创建具有以下文档功能的日历文档。

  • 传统日历表
  • 准确的月份和年份标题日期
  • 准确地放置在正确的日列中

看例子

我知道Google Apps脚本可以自动创建文档并添加内容。 我只是不确定它可以“自动”和“准确”地将日期放置在正确的位置。 如果我追求的目标不是一个选择,我不想走这条路。

我很快就将其组合在一起,但是您应该可以轻松地对其进行修改。 您可以通过获取月份第一天的星期几,然后将日期插入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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM