简体   繁体   English

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

[英]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云端硬盘中“自动”创建具有以下文档功能的日历文档。

  • Traditional calendar table 传统日历表
  • Accurate month and year heading Dates 准确的月份和年份标题日期
  • accurately placed in the correct day columns 准确地放置在正确的日列中

See example 看例子

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.

相关问题 使用Google Apps脚本将Google云端硬盘图片插入文档 - Inserting a Google Drive image into a document using Google Apps Script 使用Google Apps脚本自动生成Google表格的参考号 - Generate Reference Number to Google Sheets automatically using Google Apps Script Google日历-从Google云端硬盘添加附件的Apps脚本 - Google Calendar - Apps Script to Add Attachment from Google Drive 使用Google Apps脚本将文档上传到Google驱动器后,如何对其进行编辑 - How to edit the document after uploading it on google drive using Google Apps Script 使用Apps脚本将图像上传到Google云端硬盘 - Uploading image to Google Drive using Apps Script 使用 Google Apps 脚本共享云端硬盘文档而不通知用户 - Share a Drive document without notifying user with Google Apps Script 使用 Google Apps 脚本创建共享云端硬盘(以前称为团队云端硬盘) - Create a Shared Drive (formerly Team Drive) using Google Apps Script 发送带有附件的电子邮件,并使用Google Apps脚本保存在Google云端硬盘中 - Send an email with attachment and save in Google Drive using Google Apps Script 使用 Google Apps 脚本将文件上传到 Google Drive - Upload files to Google Drive using Google Apps Script 如何使用 Google Apps Script 将 JSON 文件保存到 Google Drive? - How to Save a JSON file to Google Drive using Google Apps Script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM