1
0

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.

GASでGoogleDocumentに見出しを付ける・編集をする

Posted at

はじめに

Googleスプレッドシートのデータを整形して、Googleドキュメントに登録したい。その時に調べてわかったことを紹介します。

この記事でわかること

  • Google Documentに見出しを付ける。
  • Google Documentの編集をする。
  • 指定したファイルをGoogleDrive内でフォルダ移動する。

コード

Docsに見出しを付ける

var body = DocumentApp.getActiveDocument().getBody();

// Append a paragraph, with heading 1.
var par1 = body.appendParagraph("Title");
par1.setHeading(DocumentApp.ParagraphHeading.HEADING1);

Docsを編集する

var body = DocumentApp.getActiveDocument().getBody();

// Use editAsText to obtain a single text element containing
// all the characters in the document.
var text = body.editAsText();

// Insert text at the end of the document.
text.appendText('\nAppended text.');

Docsのファイルを指定したDriveのフォルダに移動

// Docs取得
let document = DocumentApp.create('※シート名を入力※');
// Folder取得
let folder = DriveApp.getFolderById('※フォルダIDを入力※');

// ファイルを指定のフォルダに移動
let docFile = DriveApp.getFileById(document.getId());
folder.addFile(docFile);

参考

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?