Google スライド #ページ: 文字列全置換

Google スライド: ページ, 文字列全置換
Google スライド: ページ, 文字列全置換 (Google Slides: Page, Replace Strings)
検索文字列にマッチする全ての文字列を置換文字列に置き換えます。文字列検索では大文字と小文字が区別されます。たとえば、雛形ページのタイトル部分が自動的に置き換えられるといった仕組みを構築できます。
Configs
  • U: HTTP認証設定を選択してください *
  • A: Drive内でのファイルID(FILE-ID)をセットしてください *#{EL}
  • B: スライドページの Object-ID をセットしてください (id.以降の文字列)#{EL}
  • C1: 検索文字列をセットしてください (例 “XXXX-XX-XX”) *#{EL}
  • C2: 置換文字列をセットしてください#{EL}
Script (click to open)
// GraalJS Script (engine type: 2)

//////// START "main()" /////////////////////////////////////////////////////////////////

main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzSetting     = configs.get      ( "AuthzConfU" );   /// REQUIRED
  engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
const strInputfileId      = configs.get      ( "StrConfA1" );    /// REQUIRED
  if( strInputfileId    === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A: FileID} is empty \n" );
  }
let   strPageidOriginal   = configs.get      ( "StrConfB1" );    // NotRequired
const strSearch           = configs.get      ( "StrConfC1" );    /// REQUIRED
const strReplace          = configs.get      ( "StrConfC2" );    // NotRequired
  if( strInputfileId    === "" ){
    engine.log( " AutomatedTask ConfigWarning:" +
                " Replace with empty" );
  }

//// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)


//// == Calculating / 演算 ==

/// Get LastPage ID
/// Google Slides API
/// https://developers.google.com/slides/reference/rest/v1/presentations/get
if( strPageidOriginal === "" ){
  // request0, prepare
  let request0Uri = "https://slides.googleapis.com/v1/presentations/" + strInputfileId;
  let request0    = httpClient.begin(); // HttpRequestWrapper
      request0    = request0.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
      // https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300#HttpRequestWrapper
  // request0, try
  const response0 = request0.get( request0Uri ); // HttpResponseWrapper
  engine.log( " AutomatedTask ApiRequest0 Start: " + request0Uri );
  const response0Code = response0.getStatusCode() + "";
  const response0Body = response0.getResponseAsString() + "";
  engine.log( " AutomatedTask ApiResponse Status: " + response0Code );
  if( response0Code !== "200"){
    throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                      response0Code + "\n" + response0Body + "\n" );
  }
  // response0, parse
  const response0Obj = JSON.parse( response0Body );
  strPageidOriginal = response0Obj.slides[ response0Obj.slides.length - 1 ].objectId;
}

/// Replaces Strings (via batchUpdate Request)
/// Google Slides API
/// https://developers.google.com/slides/reference/rest/v1/presentations/request#replacealltextrequest

// request1, prepare
let request1Uri = "https://slides.googleapis.com/v1/presentations/" +
                  strInputfileId + ":batchUpdate";
let request1Obj = {};
    request1Obj.requests = [];
    request1Obj.requests[0] = {};
    request1Obj.requests[0].replaceAllText = {};
    request1Obj.requests[0].replaceAllText.replaceText = strReplace;
    request1Obj.requests[0].replaceAllText.pageObjectIds = [];
    request1Obj.requests[0].replaceAllText.pageObjectIds[0] = strPageidOriginal;
    request1Obj.requests[0].replaceAllText.containsText = {};
    request1Obj.requests[0].replaceAllText.containsText.text = strSearch;
    request1Obj.requests[0].replaceAllText.containsText.matchCase = true;
let request1    = httpClient.begin(); // HttpRequestWrapper
    request1    = request1.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
    // https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300#HttpRequestWrapper
    request1    = request1.body( JSON.stringify( request1Obj ), "application/json" );
// request1, try
const response1     = request1.post( request1Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + request1Uri );
const response1Code = response1.getStatusCode() + "";
const response1Body = response1.getResponseAsString() + "";
engine.log( " AutomatedTask ApiResponse Status: " + response1Code );
if( response1Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}
// response1, parse
/* 
engine.log( response1Body ); // debug
{
  "presentationId": "1oDCufkoKg3LQeaqBVs5VA0xX3k2d5GxhH8tvmcIXeV4",
  "replies": [
    {
      "replaceAllText": {
        "occurrencesChanged": 1
      }
    }
  ],
  "writeControl": {
    "requiredRevisionId": "J0uK9Uy_biI4Nw"
  }
}
== no match case ==
{
  "presentationId": "1oDCufkoKg3LQeaqBVs5VA0xX3k2d5GxhH8tvmcIXeV4",
  "replies": [
    {
      "replaceAllText": {}
    }
  ],
  "writeControl": {
    "requiredRevisionId": "K1shA0046Fw2Mg"
  }
}
*/
const response1Obj = JSON.parse( response1Body );
if( response1Obj.replies[0].replaceAllText.occurrencesChanged == undefined ){
  engine.log( " AutomatedTask ApiResponse: Occurrences Changed 0" );
}else{
  engine.log( " AutomatedTask ApiResponse: Occurrences Changed " +
             response1Obj.replies[0].replaceAllText.occurrencesChanged );
}


//// == Data Updating / ワークフローデータへの代入 ==
// (nothing)


} //////// END "main()" /////////////////////////////////////////////////////////////////


/*
Notes:
- All replacement processing is executed for the text data in the specified page. GoogleSlidesReplace
    - If no page is specified, the replacement process will be executed for the last page.
    - If the replacement string setting is blank, the search strings will be deleted.
    - You can also restore the slide via "Version history" of Google Slides.
- For example, if you want to automate the notification of "Monthly Sales Report", define as follows:
    - The template page is automatically duplicated (Google Slides: Page, Duplicate)
    - The report text part is automatically replaced (Google Slides: Page, Replace Strings)
    - The embedded graph is automatically updated (Google Slides: Page, Refresh Charts)
    - The slide page is automatically converted to a PNG image (Google Slides: Page, Generate PNG)
    - The email with the PNG image attached will be sent automatically. (ThrowEmail Event)
Notes-ja:
- 指定ページ内のテキストデータに対して、全置換の処理が実行されます。 GoogleSlidesReplace
    - もしページ指定がない場合は、最終ページに対して全置換の処理が実行されます。
    - もし置換文字列の設定が空白であった場合、検索文字列は削除されます。
    - Google Slides の "変更履歴" 機能を使えば、API置換の前状態に復元することも可能です。
- たとえば「月次売上レポート」の通知業務を自動化したい場合は、以下のような業務プロセスを定義します。
    - 雛形ページが自動複製され、(※Google スライド: ページ, 複製)
    - 貼り付けられている埋め込みグラフが自動更新され、(※Google スライド: ページ, 文字列全置換)
    - 報告テキスト部が当月文に自動置換され、(※Google スライド: ページ, 全グラフ更新)
    - 当該スライドページがPNG画像に自動変換され、(※Google スライド: ページ, PNG画像生成)
    - PNG画像が添付されたメールが自動的に送信される。(※ThrowEmail イベント)

APPENDIX-en
- FILE-ID/PresentationID in Drive (Chars following "/d/")
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8
- Object-ID of Slide Page (Chars following "id.")
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8/edit#slide=id.g613777c84a_0_0
- Setting example of "HTTP Authentication" (OAuth2)
    - Authorization Endpoint URL:
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - Token Endpoint URL:
        - https://accounts.google.com/o/oauth2/token
    - Scope:
        - https://www.googleapis.com/auth/presentations
    - Client ID, Consumer Secret:
        - ( from https://console.developers.google.com/ )
        - Redirect URLs: https://s.questetra.net/oauth2callback
APPENDIX-ja
- FILE-ID/PresentationID in Drive ("/d/" 以降の文字列)
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8
- Object-ID of Slide Page ("id." 以降の文字列)
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8/edit#slide=id.g613777c84a_0_0
- "HTTP認証"(OAuth2)の設定例
    - Authorization Endpoint URL:
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - Token Endpoint URL:
        - https://accounts.google.com/o/oauth2/token
    - Scope:
        - https://www.googleapis.com/auth/presentations
    - Client ID, Consumer Secret:
        - ( from https://console.developers.google.com/ )
        - Redirect URLs: https://s.questetra.net/oauth2callback
*/

Download

2021-05-16 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/google-slides-page-replace-strings-2021/
Addonファイルのインポートは Professional でのみご利用いただけます

Notes

  • 指定ページ内のテキストデータに対して、全置換の処理が実行されます。 GoogleSlidesReplace
    • もしページ指定がない場合は、最終ページに対して全置換の処理が実行されます。
    • もし置換文字列の設定が空白であった場合、検索文字列は削除されます。
    • Google Slides の “変更履歴” 機能を使えば、API置換の前状態に復元することも可能です。
  • たとえば「月次売上レポート」の通知業務を自動化したい場合は、以下のような業務プロセスを定義します。
    • 雛形ページが自動複製され、(※Google スライド: ページ, 複製)
    • 貼り付けられている埋め込みグラフが自動更新され、(※Google スライド: ページ, 文字列全置換)
    • 報告テキスト部が当月文に自動置換され、(※Google スライド: ページ, 全グラフ更新)
    • 当該スライドページがPNG画像に自動変換され、(※Google スライド: ページ, PNG画像生成)
    • PNG画像が添付されたメールが自動的に送信される。(※ThrowEmail イベント)

Capture

検索文字列にマッチする全ての文字列を置換文字列に置き換えます。文字列検索では大文字と小文字が区別されます。たとえば、雛形ページのタイトル部分が自動的に置き換えられるといった仕組みを構築できます。
検索文字列にマッチする全ての文字列を置換文字列に置き換えます。文字列検索では大文字と小文字が区別されます。たとえば、雛形ページのタイトル部分が自動的に置き換えられるといった仕組みを構築できます。

Appendix

See also

Google スライド: ページ, 複製

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

Questetra Supportをもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

上部へスクロール