Class Utilities

ユーティリティ

このサービスは、文字列のエンコード/デコード、日付の形式設定、JSON の操作、その他のさまざまなタスクのユーティリティを提供します。

プロパティ

プロパティタイプ説明
CharsetCharset
DigestAlgorithmDigestAlgorithm
MacAlgorithmMacAlgorithm
RsaAlgorithmRsaAlgorithm

メソッド

メソッド戻り値の型概要
base64Decode(encoded)Byte[]base-64 でエンコードされた文字列を UTF-8 バイト配列にデコードします。
base64Decode(encoded, charset)Byte[]base-64 でエンコードされた文字列を特定の文字セットのバイト配列にデコードします。
base64DecodeWebSafe(encoded)Byte[]base-64 のウェブセーフなエンコード文字列を UTF-8 バイト配列にデコードします。
base64DecodeWebSafe(encoded, charset)Byte[]base-64 ウェブセーフ エンコード文字列を特定の文字セットのバイト配列にデコードします。
base64Encode(data)String指定されたバイト配列から Base64 でエンコードされた文字列を生成します。
base64Encode(data)String指定された文字列から base-64 でエンコードされた文字列を生成します。
base64Encode(data, charset)String特定の文字セットの指定された文字列から base-64 でエンコードされた文字列を生成します。
base64EncodeWebSafe(data)String指定されたバイト配列から base-64 ウェブセーフ エンコード文字列を生成します。
base64EncodeWebSafe(data)String指定された文字列から base-64 ウェブセーフ エンコード文字列を生成します。
base64EncodeWebSafe(data, charset)String特定の文字セットの指定された文字列から、base-64 ウェブセーフ エンコード文字列を生成します。
computeDigest(algorithm, value)Byte[]指定された Byte[] 値に対して、指定されたアルゴリズムを使用してダイジェストを計算します。
computeDigest(algorithm, value)Byte[]指定された String 値に対して、指定されたアルゴリズムを使用してダイジェストを計算します。
computeDigest(algorithm, value, charset)Byte[]指定された文字セットを使用して、指定された String 値に対して指定されたアルゴリズムを使用してダイジェストを計算します。
computeHmacSha256Signature(value, key)Byte[]指定されたキーを使用して HMAC-SHA256 で指定された値に署名します。
computeHmacSha256Signature(value, key)Byte[]指定されたキーを使用して HMAC-SHA256 で指定された値に署名します。
computeHmacSha256Signature(value, key, charset)Byte[]指定されたキーと文字セットを使用して、HMAC-SHA256 で指定された値に署名します。
computeHmacSignature(algorithm, value, key)Byte[]指定された鍵と値に対して、指定されたアルゴリズムを使用してメッセージ認証コードを計算します。
computeHmacSignature(algorithm, value, key)Byte[]指定された鍵と値に対して、指定されたアルゴリズムを使用してメッセージ認証コードを計算します。
computeHmacSignature(algorithm, value, key, charset)Byte[]指定された鍵と値に対して、指定されたアルゴリズムを使用してメッセージ認証コードを計算します。
computeRsaSha1Signature(value, key)Byte[]指定された鍵を使用して RSA-SHA1 で指定された値に署名します。
computeRsaSha1Signature(value, key, charset)Byte[]指定された鍵と文字セットを使用して、RSA-SHA1 で指定された値に署名します。
computeRsaSha256Signature(value, key)Byte[]指定された鍵を使用して RSA-SHA256 で指定された値に署名します。
computeRsaSha256Signature(value, key, charset)Byte[]指定された鍵を使用して RSA-SHA256 で指定された値に署名します。
computeRsaSignature(algorithm, value, key)Byte[]指定された RSA アルゴリズムと指定された鍵を使用して、指定された値に署名します。
computeRsaSignature(algorithm, value, key, charset)Byte[]指定された RSA アルゴリズムと、指定された鍵と文字セットを使用して、指定された値に署名します。
formatDate(date, timeZone, format)StringJava SE SimpleDateFormat クラスで説明されている仕様に従って日付の形式を設定します。
formatString(template, args)String「%」形式の形式設定文字列を使用して、sprintf のような文字列の形式設定を行います。
getUuid()StringUUID を文字列として取得します(java.util.UUID.randomUUID() メソッドを使用するのと同等)。
gzip(blob)Blobgzip は、指定された Blob データを圧縮し、新しい Blob オブジェクトで返します。
gzip(blob, name)Blobgzip は、指定された Blob データを圧縮し、新しい Blob オブジェクトで返します。
newBlob(data)Blobバイト配列から新しい Blob オブジェクトを作成します。
newBlob(data, contentType)Blobバイト配列とコンテンツ タイプから新しい Blob オブジェクトを作成します。
newBlob(data, contentType, name)Blobバイト配列、コンテンツ タイプ、名前から新しい Blob オブジェクトを作成します。
newBlob(data)Blob文字列から新しい Blob オブジェクトを作成します。
newBlob(data, contentType)Blob文字列とコンテンツ タイプから新しい Blob オブジェクトを作成します。
newBlob(data, contentType, name)Blob文字列、コンテンツ タイプ、名前から新しい Blob オブジェクトを作成します。
parseCsv(csv)String[][]CSV 文字列の表形式の 2 次元配列表現を返します。
parseCsv(csv, delimiter)String[][]カスタム区切り文字を使用して、CSV 文字列の表形式の 2 次元配列表現を返します。
parseDate(date, timeZone, format)DateJava Standard Edition の SimpleDateFormat クラスで説明されている仕様に従って、指定された文字列の日付を解析します。
sleep(milliseconds)void指定されたミリ秒間スリープします。
ungzip(blob)BlobBlob オブジェクトを解凍し、解凍されたデータを含む Blob を返します。
unzip(blob)Blob[]ZIP ファイルを表す Blob を受け取り、その構成ファイルを返します。
zip(blobs)Blob渡された Blob のデータを含む zip ファイルである新しい Blob オブジェクトを作成します。
zip(blobs, name)Blob渡された Blob のデータを含む zip ファイルである新しい Blob オブジェクトを作成します。

詳細なドキュメント

base64Decode(encoded)

base-64 でエンコードされた文字列を UTF-8 バイト配列にデコードします。

// This is the base64 encoded form of "Google グループ"
const base64data = 'R29vZ2xlIOOCsOODq+ODvOODlw==';

// This logs:
//     [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,
//      -29, -125, -85, -29, -125, -68, -29, -125, -105]
const decoded = Utilities.base64Decode(base64data);
Logger.log(decoded);

// If you want a String instead of a byte array:
// This logs the original "Google グループ"
Logger.log(Utilities.newBlob(decoded).getDataAsString());

パラメータ

名前説明
encodedStringデコードするデータのバイト配列。

戻る

Byte[] - Base64 でエンコードされた引数で表される生データをバイト配列として返します。


base64Decode(encoded, charset)

base-64 でエンコードされた文字列を特定の文字セットのバイト配列にデコードします。

// This is the base64 encoded form of "Google グループ"
const base64data = 'R29vZ2xlIOOCsOODq+ODvOODlw==';

const decoded = Utilities.base64Decode(base64data, Utilities.Charset.UTF_8);

// This logs:
//     [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,
//      -29, -125, -85, -29, -125, -68, -29, -125, -105]
Logger.log(decoded);

// If you want a String instead of a byte array:
// This logs the original "Google グループ"
Logger.log(Utilities.newBlob(decoded).getDataAsString());

パラメータ

名前説明
encodedStringデコードするデータ文字列。
charsetCharset入力の文字セットを指定する Charset

戻る

Byte[] - Base64 でエンコードされた引数で表される生データをバイト配列として返します。


base64DecodeWebSafe(encoded)

base-64 ウェブセーフ エンコード文字列を UTF-8 バイト配列にデコードします。

// This is the base64 web-safe encoded form of "Google グループ"
const base64data = 'R29vZ2xlIOOCsOODq-ODvOODlw==';

const decoded = Utilities.base64DecodeWebSafe(base64data);

// This logs:
//     [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,
//      -29, -125, -85, -29, -125, -68, -29, -125, -105]
Logger.log(decoded);

// If you want a String instead of a byte array:
// This logs the original "Google グループ"
Logger.log(Utilities.newBlob(decoded).getDataAsString());

パラメータ

名前説明
encodedStringデコードするウェブセーフ データのバイト配列。

戻る

Byte[] - Base64 のウェブセーフなエンコード引数で表される未加工データをバイト配列として表します。


base64DecodeWebSafe(encoded, charset)

base-64 ウェブセーフ エンコード文字列を特定の文字セットのバイト配列にデコードします。

// This is the base64 web-safe encoded form of "Google グループ"
const base64data = 'R29vZ2xlIOOCsOODq-ODvOODlw==';

const decoded = Utilities.base64DecodeWebSafe(
    base64data,
    Utilities.Charset.UTF_8,
);

// This logs:
//     [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,
//      -29, -125, -85, -29, -125, -68, -29, -125, -105]
Logger.log(decoded);

// If you want a String instead of a byte array:
// This logs the original "Google グループ"
Logger.log(Utilities.newBlob(decoded).getDataAsString());

パラメータ

名前説明
encodedStringデコードするウェブセーフなデータの文字列。
charsetCharset入力の文字セットを指定する Charset

戻る

Byte[] - Base64 のウェブセーフなエンコード引数で表される未加工データをバイト配列として表します。


base64Encode(data)

指定されたバイト配列から Base64 でエンコードされた文字列を生成します。Base64 は、バイナリデータを受け入れられないさまざまなツールで受け入れられる一般的なエンコードです。Base 64 は、メールや HTTP などのインターネット プロトコルや XML ドキュメントでよく使用されます。

// Instantiates a blob here for clarity
const blob = Utilities.newBlob('A string here');

// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.
const encoded = Utilities.base64Encode(blob.getBytes());
Logger.log(encoded);

パラメータ

名前説明
dataByte[]エンコードするデータの byte[]。

戻る

String - 渡されたデータの base64 エンコード表現。


base64Encode(data)

指定された文字列から base-64 でエンコードされた文字列を生成します。Base64 は、バイナリデータを受け入れられないさまざまなツールで受け入れられる一般的なエンコードです。Base 64 は、メールや HTTP などのインターネット プロトコルや XML ドキュメントでよく使用されます。

// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.
const encoded = Utilities.base64Encode('A string here');
Logger.log(encoded);

パラメータ

名前説明
dataStringエンコードする文字列。

戻る

String - 入力文字列の base-64 エンコード表現。


base64Encode(data, charset)

特定の文字セットの指定された文字列から base-64 でエンコードされた文字列を生成します。文字セットは、文字をエンコードできるようにエンコードする方法です。通常、これらはバイナリ形式で行われますが、特定のデータ送信プロトコルと互換性がない場合があります。データを互換性のあるものにするため、通常は base 64 にエンコードされます。これは、バイナリデータを受け入れられないさまざまなツールで受け入れられる一般的なエンコードです。Base 64 は、メールや HTTP などのインターネット プロトコルや XML ドキュメントでよく使用されます。

// "Google Groups" in Katakana (Japanese)
const input = 'Google グループ';

// Writes "R29vZ2xlIOOCsOODq+ODvOODlw==" to the log
const encoded = Utilities.base64Encode(input, Utilities.Charset.UTF_8);
Logger.log(encoded);

パラメータ

名前説明
dataStringエンコードするデータ文字列。
charsetCharset入力の文字セットを指定する Charset

戻る

String - 指定された Charset を使用して入力文字列を base-64 でエンコードした表現。


base64EncodeWebSafe(data)

指定されたバイト配列から base-64 ウェブセーフ エンコード文字列を生成します。Base64 は、バイナリデータを受け入れられないさまざまなツールで受け入れられる一般的なエンコードです。Base 64 ウェブセーフは、メール、HTTP、XML ドキュメントなどのインターネット プロトコルで一般的に使用されます。

// Instantiates a blob here for clarity
const blob = Utilities.newBlob('A string here');

// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.
const encoded = Utilities.base64EncodeWebSafe(blob.getBytes());
Logger.log(encoded);

パラメータ

名前説明
dataByte[]エンコードするデータのバイト配列。

戻る

String - 渡されたデータの Base64 ウェブセーフ エンコード表現。


base64EncodeWebSafe(data)

指定された文字列から base-64 ウェブセーフ エンコード文字列を生成します。Base64 は、バイナリデータを受け入れられないさまざまなツールで受け入れられる一般的なエンコードです。Base 64 ウェブセーフは、メールや HTTP などのインターネット プロトコルや XML ドキュメントで一般的に使用されています。

// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.
const encoded = Utilities.base64EncodeWebSafe('A string here');
Logger.log(encoded);

パラメータ

名前説明
dataStringエンコードする文字列。

戻る

String - 入力文字列の Base64 ウェブセーフ エンコード表現。


base64EncodeWebSafe(data, charset)

特定の文字セットの指定された文字列から、base-64 ウェブセーフ エンコード文字列を生成します。文字セットは、文字をエンコードできるようにエンコードする方法です。通常、これはバイナリ形式で行われますが、特定のデータ送信プロトコルと互換性がない場合があります。データを互換性のあるものにするため、一般的に base 64 にエンコードされます。これは、バイナリデータを受け入れられないさまざまなツールで受け入れられる一般的なエンコードです。Base 64 ウェブセーフは、メール、HTTP、XML ドキュメントなどのインターネット プロトコルで一般的に使用されます。

// "Google Groups" in Katakana (Japanese)
const input = 'Google グループ';

// Writes "R29vZ2xlIOOCsOODq-ODvOODlw==" to the log
const encoded = Utilities.base64EncodeWebSafe(input, Utilities.Charset.UTF_8);
Logger.log(encoded);

パラメータ

名前説明
dataStringエンコードするデータ文字列。
charsetCharset入力の文字セットを指定する Charset

戻る

String - 指定された Charset を使用して入力文字列を base-64 ウェブセーフ エンコードした表現。


computeDigest(algorithm, value)

指定された Byte[] 値に対して、指定されたアルゴリズムを使用してダイジェストを計算します。

const input = Utilities.base64Decode(
    'aW5wdXQgdG8gaGFzaA0K');  // == base64encode("input to hash")
const digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, input);
Logger.log(digest);

パラメータ

名前説明
algorithmDigestAlgorithm使用する DigestAlgorithm
valueByte[]ダイジェストを計算する入力文字列値。

戻る

Byte[] - 出力ダイジェストを表す byte[]。


computeDigest(algorithm, value)

指定された String 値に対して、指定されたアルゴリズムを使用してダイジェストを計算します。

const digest = Utilities.computeDigest(
    Utilities.DigestAlgorithm.MD5,
    'input to hash',
);
Logger.log(digest);

パラメータ

名前説明
algorithmDigestAlgorithm使用する DigestAlgorithm
valueStringダイジェストを計算する入力文字列値。

戻る

Byte[] - 出力ダイジェストを表す byte[]。


computeDigest(algorithm, value, charset)

指定された String 値に対して、指定されたアルゴリズムと指定された文字セットを使用してダイジェストを計算します。

const digest = Utilities.computeDigest(
    Utilities.DigestAlgorithm.MD5,
    'input to hash',
    Utilities.Charset.US_ASCII,
);
Logger.log(digest);

パラメータ

名前説明
algorithmDigestAlgorithm使用する DigestAlgorithm
valueStringダイジェストを計算する入力文字列値。
charsetCharset入力文字セットを表す Charset

戻る

Byte[] - 出力ダイジェストを表す byte[]。


computeHmacSha256Signature(value, key)

指定された鍵を使用して HMAC-SHA256 で指定された値に署名します。

// This writes an array of bytes to the log.
const input = Utilities.base64Decode(
    'aW5wdXQgdG8gaGFzaA0K');                 // == base64encode("input to hash")
const key = Utilities.base64Decode('a2V5');  // == base64encode("key")
const signature = Utilities.computeHmacSha256Signature(input, key);
Logger.log(signature);

パラメータ

名前説明
valueByte[]ハッシュを生成する入力値。
keyByte[]ハッシュの生成に使用するキー。

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeHmacSha256Signature(value, key)

指定された鍵を使用して HMAC-SHA256 で指定された値に署名します。

// This writes an array of bytes to the log.
const signature = Utilities.computeHmacSha256Signature(
    'this is my input',
    'my key - use a stronger one',
);
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyStringハッシュの生成に使用するキー。

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeHmacSha256Signature(value, key, charset)

指定されたキーと文字セットを使用して、HMAC-SHA256 で指定された値に署名します。

// This writes an array of bytes to the log.
const signature = Utilities.computeHmacSha256Signature(
    'this is my input',
    'my key - use a stronger one',
    Utilities.Charset.US_ASCII,
);
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyStringハッシュの生成に使用するキー。
charsetCharset入力文字セットを表す Charset

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeHmacSignature(algorithm, value, key)

指定された鍵と値に対して、指定されたアルゴリズムを使用してメッセージ認証コードを計算します。

// This writes an array of bytes to the log.
const input = Utilities.base64Decode(
    'aW5wdXQgdG8gaGFzaA0K');                 // == base64encode("input to hash")
const key = Utilities.base64Decode('a2V5');  // == base64encode("key")
const signature = Utilities.computeHmacSignature(
    Utilities.MacAlgorithm.HMAC_MD5,
    input,
    key,
);
Logger.log(signature);

パラメータ

名前説明
algorithmMacAlgorithm入力値のハッシュ化に使用する MacAlgorithm アルゴリズム。
valueByte[]ハッシュを生成する入力値。
keyByte[]ハッシュの生成に使用するキー。

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeHmacSignature(algorithm, value, key)

指定された鍵と値に対して、指定されたアルゴリズムを使用してメッセージ認証コードを計算します。

// This writes an array of bytes to the log.
const signature = Utilities.computeHmacSignature(
    Utilities.MacAlgorithm.HMAC_MD5,
    'input to hash',
    'key',
);
Logger.log(signature);

パラメータ

名前説明
algorithmMacAlgorithm入力値のハッシュ化に使用する MacAlgorithm アルゴリズム。
valueStringハッシュを生成する入力値。
keyStringハッシュの生成に使用するキー。

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeHmacSignature(algorithm, value, key, charset)

指定された鍵と値に対して、指定されたアルゴリズムを使用してメッセージ認証コードを計算します。

// This writes an array of bytes to the log.
const signature = Utilities.computeHmacSignature(
    Utilities.MacAlgorithm.HMAC_MD5,
    'input to hash',
    'key',
    Utilities.Charset.US_ASCII,
);
Logger.log(signature);

パラメータ

名前説明
algorithmMacAlgorithm入力値のハッシュ化に使用する MacAlgorithm アルゴリズム。
valueStringハッシュを生成する入力値。
keyStringハッシュの生成に使用するキー。
charsetCharset入力文字セットを表す Charset

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeRsaSha1Signature(value, key)

指定されたキーを使用して RSA-SHA1 で指定された値に署名します。

// This writes an array of bytes to the log.
const signature = Utilities.computeRsaSha1Signature(
    'this is my input',
    PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),
);
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeRsaSha1Signature(value, key, charset)

指定されたキーと文字セットを使用して、RSA-SHA1 で指定された値に署名します。

// This writes an array of bytes to the log.
const signature = Utilities.computeRsaSha1Signature(
    'this is my input',
    PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),
    Utilities.Charset.US_ASCII,
);
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。
charsetCharset入力文字セットを表す Charset

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeRsaSha256Signature(value, key)

指定された鍵を使用して RSA-SHA256 で指定された値に署名します。

// This writes an array of bytes to the log.
const signature = Utilities.computeRsaSha256Signature(
    'this is my input',
    PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),
);
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeRsaSha256Signature(value, key, charset)

指定された鍵を使用して RSA-SHA256 で指定された値に署名します。

// This writes an array of bytes to the log.
const signature = Utilities.computeRsaSha256Signature(
    'this is my input',
    PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),
);
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。
charsetCharset入力文字セットを表す Charset

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeRsaSignature(algorithm, value, key)

指定された RSA アルゴリズムと指定された鍵を使用して、指定された値に署名します。

// This writes an array of bytes to the log.
const signature = Utilities.computeRsaSignature(
    Utilities.RsaAlgorithm.RSA_SHA_256,
    'this is my input',
    PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),
);
Logger.log(signature);

パラメータ

名前説明
algorithmRsaAlgorithm入力値のハッシュ化に使用する RsaAlgorithm アルゴリズム。
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。

戻る

Byte[] - 出力シグネチャを表す byte[]。


computeRsaSignature(algorithm, value, key, charset)

指定された RSA アルゴリズムと、指定された鍵と文字セットを使用して、指定された値に署名します。

// This writes an array of bytes to the log.
const signature = Utilities.computeRsaSignature(
    Utilities.RsaAlgorithm.RSA_SHA_256,
    'this is my input',
    PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),
    Utilities.Charset.US_ASCII,
);
Logger.log(signature);

パラメータ

名前説明
algorithmRsaAlgorithm入力値のハッシュ化に使用する RsaAlgorithm アルゴリズム。
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。
charsetCharset入力文字セットを表す Charset

戻る

Byte[] - 出力シグネチャを表す byte[]。


formatDate(date, timeZone, format)

Java SE SimpleDateFormat クラスで説明されている仕様に従って日付の形式を設定します。仕様については、 http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html をご覧ください。

// This formats the date as Greenwich Mean Time in the format
// year-month-dateThour-minute-second.
const formattedDate = Utilities.formatDate(
    new Date(),
    'GMT',
    'yyyy-MM-dd\'T\'HH:mm:ss\'Z\'',
);
Logger.log(formattedDate);

パラメータ

名前説明
dateDateString としてフォーマットする Date
timeZoneString結果の出力タイムゾーン。
formatStringSimpleDateFormat 仕様に準拠した形式。

戻る

String - 書式設定された文字列としての入力日付。


formatString(template, args)

「%」形式の形式文字列を使用して、sprintf のような文字列の形式設定を行います。

// " 123.456000"
Utilities.formatString('%11.6f', 123.456);

// "   abc"
Utilities.formatString('%6s', 'abc');

パラメータ

名前説明
templateString返される内容を制御する形式文字列。
argsObject...テンプレートの「%」プレースホルダを埋めるために使用するオブジェクト。

戻る

String - フォーマットされた文字列。


getUuid()

UUID を文字列として取得します(java.util.UUID.randomUUID() メソッドを使用するのと同等)。この識別子は、すべての時間と空間で一意であるとは限りません。そのため、一意性が保証されている必要がある状況では使用しないでください。

// This assigns a UUID as a temporary ID for a data object you are creating in
// your script.
const myDataObject = {
  tempId: Utilities.getUuid(),
};

戻る

String - UUID の文字列表現。


gzip(blob)

gzip - 指定された Blob データを圧縮し、新しい Blob オブジェクトで返します。

const textBlob = Utilities.newBlob(
    'Some text to compress using gzip compression',
);

// Create the compressed blob.
const gzipBlob = Utilities.gzip(textBlob);

パラメータ

名前説明
blobBlobSourcegzip を使用して圧縮する Blob オブジェクト。

戻る

Blob - 圧縮データを含む新しい Blob


gzip(blob, name)

gzip-指定された Blob データを圧縮し、新しい Blob オブジェクトで返します。このバージョンのメソッドでは、ファイル名を指定できます。

const textBlob = Utilities.newBlob(
    'Some text to compress using gzip compression',
);

// Create the compressed blob.
const gzipBlob = Utilities.gzip(textBlob, 'text.gz');

パラメータ

名前説明
blobBlobSourcegzip を使用して圧縮する Blob オブジェクト。
nameString作成する gzip ファイルの名前。

戻る

Blob - 圧縮データを含む新しい Blob


newBlob(data)

バイト配列から新しい Blob オブジェクトを作成します。Blob は、バイナリ データを入力として受け取る多くの Apps Script API で使用されます。

// Creates a blob object from a byte array.
const data = [71, 79, 79, 71, 76, 69];
const blob = Utilities.newBlob(data);

// Logs the blob data as a string to the console.
console.log(blob.getDataAsString());

パラメータ

名前説明
dataByte[]Blob のバイト数。

戻る

Blob - 新しく作成された Blob。


newBlob(data, contentType)

バイト配列とコンテンツ タイプから新しい Blob オブジェクトを作成します。Blob は、バイナリ データを入力として受け取る多くの Apps Script API で使用されます。

// Declares a byte array.
const data = [71, 79, 79, 71, 76, 69];

// Declares the content type of the blob.
const contentType = 'application/json';

// Creates a blob object from the byte array and content type.
const blob = Utilities.newBlob(data, contentType);

// Logs the blob data as a string to the console.
console.log(blob.getDataAsString());

// Logs the content type of the blob to the console.
console.log(blob.getContentType());

パラメータ

名前説明
dataByte[]Blob のバイト数。
contentTypeStringblob のコンテンツ タイプ。null を指定できます。

戻る

Blob - 新しく作成された Blob。


newBlob(data, contentType, name)

バイト配列、コンテンツ タイプ、名前から新しい Blob オブジェクトを作成します。Blob は、バイナリ データを入力として受け取る多くの Apps Script API で使用されます。

// Declares a byte array.
const data = [71, 79, 79, 71, 76, 69];

// Declares the content type of the blob.
const contentType = 'application/json';

// Declares the name of the blob.
const name = 'Example blob';

// Creates a blob object from the byte array, content type, and name.
const blob = Utilities.newBlob(data, contentType, name);

// Logs the blob data as a string to the console.
console.log('Blob data:', blob.getDataAsString());

// Logs the content type of the blob to the console.
console.log('Blob content type:', blob.getContentType());

// Logs the name of the blob to the console.
console.log('Blob name:', blob.getName());

パラメータ

名前説明
dataByte[]Blob のバイト数。
contentTypeString- blob のコンテンツ タイプ - null にできます。
nameStringBlob の名前。null にすることもできます。

戻る

Blob - 新しく作成された Blob。


newBlob(data)

文字列から新しい Blob オブジェクトを作成します。Blob は、バイナリ データを入力として受け取る多くの Apps Script API で使用されます。

// Declares a string for the blob.
const data = 'GOOGLE';

// Creates a blob object from a string.
const blob = Utilities.newBlob(data);

// Logs the blob data in byte array to the console.
console.log('Blob Data:', blob.getBytes());

パラメータ

名前説明
dataStringBLOB の文字列(UTF-8 を想定)。

戻る

Blob - 新しく作成された Blob。


newBlob(data, contentType)

文字列とコンテンツ タイプから新しい Blob オブジェクトを作成します。Blob は、バイナリ データを入力として受け取る多くの Apps Script API で使用されます。

// Declares a string for the blob.
const data = 'GOOGLE';

// Declares the content type of blob.
const contentType = 'application/json';

// Creates a blob object from the string and content type.
const blob = Utilities.newBlob(data, contentType);

// Logs the blob data in byte array to the console.
console.log('Blob data:', blob.getBytes());

// Logs the content type of the blob to the console.
console.log(blob.getContentType());

パラメータ

名前説明
dataStringBLOB の文字列(UTF-8 を想定)。
contentTypeStringblob のコンテンツ タイプ。null を指定できます。

戻る

Blob - 新しく作成された Blob。


newBlob(data, contentType, name)

文字列、コンテンツ タイプ、名前から新しい Blob オブジェクトを作成します。Blob は、バイナリ データを入力として受け取る多くの Apps Script API で使用されます。

// Declares a string for the blob.
const data = 'GOOGLE';

// Declares the content type of the blob.
const contentType = 'application/json';

// Declares the name of the blob.
const name = 'Example blob';

// Create a blob object from the string, content type, and name.
const blob = Utilities.newBlob(data, contentType, name);

// Logs the blob data in byte array to the console.
console.log('Blob data:', blob.getBytes());

// Logs the content type of the blob to the console.
console.log('Blob content type:', blob.getContentType());

// Logs the name of the blob to the console.
console.log('Blob name:', blob.getName());

パラメータ

名前説明
dataStringBLOB の文字列(UTF-8 を想定)。
contentTypeStringblob のコンテンツ タイプ。null を指定できます。
nameStringBlob の名前。null にすることもできます。

戻る

Blob - 新しく作成された Blob。


parseCsv(csv)

CSV 文字列の表形式の 2 次元配列表現を返します。

// This creates a two-dimensional array of the format [[a, b, c], [d, e, f]]
const csvString = 'a,b,c\nd,e,f';
const data = Utilities.parseCsv(csvString);

パラメータ

名前説明
csvStringカンマ区切り値(CSV)形式の単一行または複数行のデータを含む文字列。

戻る

String[][] - CSV 文字列の値を含む 2 次元配列。


parseCsv(csv, delimiter)

カスタム区切り文字を使用して、CSV 文字列の表形式の 2 次元配列表現を返します。

// This creates a two-dimensional array of the format [[a, b, c], [d, e, f]]
const csvString = 'a\tb\tc\nd\te\tf';
const data = Utilities.parseCsv(csvString, '\t');

パラメータ

名前説明
csvStringカンマ区切り値(CSV)形式の単一行または複数行のデータを含む文字列。
delimiterChar値の間。

戻る

String[][] - CSV 文字列の値を含む 2 次元配列。


parseDate(date, timeZone, format)

Java Standard Edition SimpleDateFormat クラスで説明されている仕様に従って、指定された文字列の日付を解析します。詳細については、Java の SimpleDateFormat クラスをご覧ください。

// This set of parameters parses the given string as a date in Greenwich Mean
// Time, formatted as year-month-dateThour-minute-second.
const date = Utilities.parseDate(
    '1970-01-01 00:00:00',
    'GMT',
    'yyyy-MM-dd\' \'HH:mm:ss',
);
Logger.log(date);

パラメータ

名前説明
dateString日付として解析する文字列値。
timeZoneString出力タイムゾーン。
formatStringSimpleDateFormat 仕様に準拠した日付形式。

戻る

Date - 入力文字列を日付として指定します。


sleep(milliseconds)

指定したミリ秒間スリープします。指定されたミリ秒数の間、スクリプトをすぐにスリープ状態にします。最大許容値は 300,000(5 分)です。

// Creates a blob object from a string.
const data = 'GOOGLE';
const blob = Utilities.newBlob(data);

// Puts the script to sleep for 10,000 milliseconds (10 seconds).
Utilities.sleep(10000);

// Logs the blob data in byte array to the console.
console.log(blob.getBytes());

パラメータ

名前説明
millisecondsIntegerスリープするミリ秒数。

ungzip(blob)

Blob オブジェクトを解凍し、解凍されたデータを含む Blob を返します。

const textBlob = Utilities.newBlob(
    'Some text to compress using gzip compression',
);

// Create the compressed blob.
const gzipBlob = Utilities.gzip(textBlob, 'text.gz');

// Uncompress the data.
const uncompressedBlob = Utilities.ungzip(gzipBlob);

パラメータ

名前説明
blobBlobSource圧縮データの Blob

戻る

Blob - 圧縮解除されたデータを表す Blob


unzip(blob)

ZIP ファイルを表す Blob を受け取り、その構成ファイルを取得します。

const googleFavIconUrl = 'https://www.google.com/favicon.ico';
const googleLogoUrl = 'https://www.google.com/images/srpr/logo3w.png';

// Fetch the Google favicon.ico file and get the Blob data
const faviconBlob = UrlFetchApp.fetch(googleFavIconUrl).getBlob();
const logoBlob = UrlFetchApp.fetch(googleLogoUrl).getBlob();

// zip now references a blob containing an archive of both faviconBlob and
// logoBlob
const zip = Utilities.zip([faviconBlob, logoBlob], 'google_images.zip');

// This now unzips the blobs
const files = Utilities.unzip(zip);

パラメータ

名前説明
blobBlobSourceZIP ファイルの BLOB。

戻る

Blob[] - コンポーネント blob を表す Blob[]。各 blob には zip 内のフルパスが名前として付けられています。


zip(blobs)

渡された Blob のデータを含む zip ファイルである新しい Blob オブジェクトを作成します。

const googleFavIconUrl = 'https://www.google.com/favicon.ico';
const googleLogoUrl = 'https://www.google.com/images/srpr/logo3w.png';

// Fetch the Google favicon.ico file and get the Blob data
const faviconBlob = UrlFetchApp.fetch(googleFavIconUrl).getBlob();
const logoBlob = UrlFetchApp.fetch(googleLogoUrl).getBlob();

// zip now references a blob containing an archive of both faviconBlob and
// logoBlob
const zip = Utilities.zip([faviconBlob, logoBlob]);

パラメータ

名前説明
blobsBlobSource[]zip 圧縮する Blob の配列。

戻る

Blob - 入力をアーカイブとして含む新しい BLOB。


zip(blobs, name)

渡された Blob のデータを含む zip ファイルである新しい Blob オブジェクトを作成します。このバージョンのメソッドでは、ファイル名を指定できます。

const googleFavIconUrl = 'https://www.google.com/favicon.ico';
const googleLogoUrl = 'https://www.google.com/images/srpr/logo3w.png';

// Fetch the Google favicon.ico file and get the Blob data
const faviconBlob = UrlFetchApp.fetch(googleFavIconUrl).getBlob();
const logoBlob = UrlFetchApp.fetch(googleLogoUrl).getBlob();

// zip now references a blob containing an archive of both faviconBlob and
// logoBlob
const zip = Utilities.zip([faviconBlob, logoBlob], 'google_images.zip');

パラメータ

名前説明
blobsBlobSource[]zip 圧縮する Blob の配列。
nameString作成する zip ファイルの名前。

戻る

Blob - 入力をアーカイブとして含む新しい BLOB。

サポート終了のメソッド