2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

日記つけるのに、いちいち日付書くの面倒くさくないですか?

Last updated at Posted at 2021-04-19

はじめに

googleドキュメントに日記を綴っているのですが、特にスマートフォン版で見出し(日付)を書くのがちょっと面倒くさい。
for_qiita.png

やること

スクリプトで見出しを追加しておく。具体的には、時間主導型のトリガーで、ドキュメントを開く前に見出しを追加しておく。

コード(3行)

function addHeadDate() {
  // 「(年).(月).(日)」の文字列を作る。
  const title = 
  Utilities.formatDate(new Date(), "Asia/Tokyo", "YYYY.MM.dd");
  // 文書に文字列を追加。
  const head_date = 
  DocumentApp.getActiveDocument().getBody().appendParagraph(title);
  // 追加した文字を大きくする。
  head_date.setHeading(DocumentApp.ParagraphHeading.HEADING2);
}

参考:
formatDate | Class Utilities | Apps Script | Google Developers
Class Paragraph | Apps Script | Google Developers

実行してちゃんと動くか確かめる。

トリガーを設定

image (1).png

おわりに

スマホで見出しを書くのに、10秒前後かかっていたので、これで1年あたり10s×365=約1時間の時間を節約できるはず。うまうま。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?