回答編集履歴

4

変数名を修正しました。

2024/02/07 00:55

投稿

YellowGreen
YellowGreen

スコア789

test CHANGED
@@ -41,8 +41,8 @@
41
41
  indexes.forEach(ix => text.deleteText(ix[0], ix[1]));
42
42
 
43
43
  // 段落の先頭をインデント
44
- const getParagraphs = body.getParagraphs();
44
+ const paragraphs = body.getParagraphs();
45
- getParagraphs.forEach(p => p.setIndentFirstLine(indentPoint)); // ポイント指定のインデントを設定
45
+ paragraphs.forEach(p => p.setIndentFirstLine(indentPoint)); // ポイント指定のインデントを設定
46
- // getParagraphs.forEach(p => p.insertText(0, indentSpace)); // 空白でインデントする場合
46
+ // paragraphs.forEach(p => p.insertText(0, indentSpace)); // 空白でインデントする場合
47
47
  }
48
48
  ```

3

コメントの誤記修正

2024/02/06 23:57

投稿

YellowGreen
YellowGreen

スコア789

test CHANGED
@@ -40,7 +40,7 @@
40
40
  // リッチテキストを編集(削除)
41
41
  indexes.forEach(ix => text.deleteText(ix[0], ix[1]));
42
42
 
43
- // 段落の先頭を空白文字でインデント
43
+ // 段落の先頭をインデント
44
44
  const getParagraphs = body.getParagraphs();
45
45
  getParagraphs.forEach(p => p.setIndentFirstLine(indentPoint)); // ポイント指定のインデントを設定
46
46
  // getParagraphs.forEach(p => p.insertText(0, indentSpace)); // 空白でインデントする場合

2

段落のインデントの処理を加えました。

2024/02/06 23:56

投稿

YellowGreen
YellowGreen

スコア789

test CHANGED
@@ -8,11 +8,14 @@
8
8
  文字列の削除は、リッチテキストの方で行うスクリプトです。
9
9
 
10
10
  ```JavaScript
11
+ // 段落番号と文番号を削除して一段落にする
11
- function replaceDocText() {
12
+ function deleteParagraphAndSentenceNumbers() {
12
13
  // 初期設定
13
14
  const maxParagragh = 13;
14
15
  const maxSentence = 6;
16
+ const indentPoint = 11; // インデントをポイントで指定
17
+ // const indentSpace = ' '; // 空白2個でインデントする場合
15
- const doc = DocumentApp.openById('特定のドキュメントID');
18
+ const doc = DocumentApp.openById(特定のドキュメントID);
16
19
  const body = doc.getBody();
17
20
  const text = body.editAsText();
18
21
  const planeText = text.getText();
@@ -36,5 +39,10 @@
36
39
 
37
40
  // リッチテキストを編集(削除)
38
41
  indexes.forEach(ix => text.deleteText(ix[0], ix[1]));
42
+
43
+ // 段落の先頭を空白文字でインデント
44
+ const getParagraphs = body.getParagraphs();
45
+ getParagraphs.forEach(p => p.setIndentFirstLine(indentPoint)); // ポイント指定のインデントを設定
46
+ // getParagraphs.forEach(p => p.insertText(0, indentSpace)); // 空白でインデントする場合
39
47
  }
40
48
  ```

1

説明を修正しました。

2024/02/06 23:23

投稿

YellowGreen
YellowGreen

スコア789

test CHANGED
@@ -1,6 +1,11 @@
1
+ 移植というご質問への回答になっているかどうかわかりませんが、
2
+ 実行結果はご希望のとおりになりますでしょうか。
3
+
1
4
  replaceTextで改行を超えた正規表現の検索ができるかどうか不明でしたので、
2
- 書式情報があっても維持されるようにプレーンテキストで位置を検索してから
5
+ プレーンテキストの方から multiple line オプション付きの正規表現で検索し
6
+ マッチした文字列の位置情報を配列に蓄積しておいて、
7
+ 文字の色やフォントサイズなどの書式情報が維持されるように
3
- リッチテキストから文字を削除するです。
8
+ 文字列の削除は、リッチテキスト方で行うスクリプトです。
4
9
 
5
10
  ```JavaScript
6
11
  function replaceDocText() {