Class Utilities

ยูทิลิตี

บริการนี้มีเครื่องมือสำหรับการเข้ารหัส/ถอดรหัสสตริง การจัดรูปแบบวันที่ การจัดการ JSON และงานอื่นๆ

พร็อพเพอร์ตี้

พร็อพเพอร์ตี้ประเภทคำอธิบาย
CharsetCharset
DigestAlgorithmDigestAlgorithm
MacAlgorithmMacAlgorithm
RsaAlgorithmRsaAlgorithm

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
base64Decode(encoded)Byte[]ถอดรหัสสตริงที่เข้ารหัส Base64 เป็นอาร์เรย์ไบต์ UTF-8
base64Decode(encoded, charset)Byte[]ถอดรหัสสตริงที่เข้ารหัส Base64 เป็นอาร์เรย์ไบต์ในชุดอักขระที่เฉพาะเจาะจง
base64DecodeWebSafe(encoded)Byte[]ถอดรหัสสตริงที่เข้ารหัส Web-safe base64 เป็นอาร์เรย์ไบต์ UTF-8
base64DecodeWebSafe(encoded, charset)Byte[]ถอดรหัสสตริงที่เข้ารหัส base-64 แบบ Web-safe เป็นอาร์เรย์ไบต์ในชุดอักขระที่เฉพาะเจาะจง
base64Encode(data)Stringสร้างสตริงที่เข้ารหัส Base64 จากอาร์เรย์ไบต์ที่ระบุ
base64Encode(data)Stringสร้างสตริงที่เข้ารหัส Base64 จากสตริงที่ระบุ
base64Encode(data, charset)Stringสร้างสตริงที่เข้ารหัส Base64 จากสตริงที่กำหนดในชุดอักขระที่เฉพาะเจาะจง
base64EncodeWebSafe(data)Stringสร้างสตริงที่เข้ารหัส Web-safe base64 จากอาร์เรย์ไบต์ที่ระบุ
base64EncodeWebSafe(data)Stringสร้างสตริงที่เข้ารหัส Web-safe base64 จากสตริงที่ระบุ
base64EncodeWebSafe(data, charset)Stringสร้างสตริงที่เข้ารหัสแบบ Web-safe 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)Stringจัดรูปแบบวันที่ตามข้อกำหนดที่อธิบายไว้ในคลาส SimpleDateFormat ของ Java SE
formatString(template, args)Stringดำเนินการจัดรูปแบบสตริงคล้าย sprintf โดยใช้สตริงรูปแบบสไตล์ "%"
getUuid()Stringรับ UUID เป็นสตริง (เทียบเท่ากับการใช้วิธี 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[][]แสดงผลการแสดงอาร์เรย์ 2 มิติแบบตารางของสตริง CSV
parseCsv(csv, delimiter)String[][]แสดงการแทนอาร์เรย์ 2 มิติแบบตารางของสตริง CSV โดยใช้ตัวคั่นที่กำหนดเอง
parseDate(date, timeZone, format)Dateแยกวิเคราะห์วันที่สตริงที่ระบุตามข้อกำหนดที่อธิบายไว้ในคลาส Java Standard Edition SimpleDateFormat
sleep(milliseconds)voidพักเป็นจำนวนมิลลิวินาทีที่ระบุ
ungzip(blob)Blobคลายการบีบอัดออบเจ็กต์ Blob และแสดงผล Blob ที่มีข้อมูลที่ไม่ได้บีบอัด
unzip(blob)Blob[]รับ Blob ที่แสดงไฟล์ ZIP และแสดงผลไฟล์คอมโพเนนต์
zip(blobs)Blobสร้างออบเจ็กต์ Blob ใหม่ซึ่งเป็นไฟล์ ZIP ที่มีข้อมูลจาก Blob ที่ส่งเข้ามา
zip(blobs, name)Blobสร้างออบเจ็กต์ Blob ใหม่ซึ่งเป็นไฟล์ ZIP ที่มีข้อมูลจาก Blob ที่ส่งเข้ามา

เอกสารโดยละเอียด

base64Decode(encoded)

ถอดรหัสสตริงที่เข้ารหัส Base64 เป็นอาร์เรย์ไบต์ 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)

ถอดรหัสสตริงที่เข้ารหัส Base64 เป็นอาร์เรย์ไบต์ในชุดอักขระที่เฉพาะเจาะจง

// 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สตริงของข้อมูลที่จะถอดรหัส
charsetCharsetCharset ที่ระบุชุดอักขระของอินพุต

รีเทิร์น

Byte[] - ข้อมูลดิบที่แสดงโดยอาร์กิวเมนต์ที่เข้ารหัส Base64 เป็นอาร์เรย์ไบต์


base64DecodeWebSafe(encoded)

ถอดรหัสสตริงที่เข้ารหัส Web-safe base64 เป็นอาร์เรย์ไบต์ 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 แบบ Web-safe เป็นอาร์เรย์ไบต์ในชุดอักขระที่เฉพาะเจาะจง

// 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สตริงของข้อมูลที่ปลอดภัยบนเว็บที่จะถอดรหัส
charsetCharsetCharset ที่ระบุชุดอักขระของอินพุต

รีเทิร์น

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[]อาร์เรย์ไบต์ของข้อมูลที่จะเข้ารหัส

รีเทิร์น

String - การแสดงข้อมูลที่ส่งผ่านซึ่งเข้ารหัสแบบ Base64


base64Encode(data)

สร้างสตริงที่เข้ารหัส Base64 จากสตริงที่ระบุ Base64 เป็นการเข้ารหัสที่ใช้กันทั่วไปซึ่งเครื่องมือต่างๆ ที่รับข้อมูลไบนารีไม่ได้ยอมรับ Base 64 มักใช้ในโปรโตคอลอินเทอร์เน็ต เช่น อีเมล, HTTP หรือในเอกสาร XML

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

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dataStringสตริงที่จะเข้ารหัส

รีเทิร์น

String — การแสดงสตริงอินพุตที่เข้ารหัส Base64


base64Encode(data, charset)

สร้างสตริงที่เข้ารหัส Base64 จากสตริงที่กำหนดในชุดอักขระที่เฉพาะเจาะจง Charset คือวิธีการเข้ารหัสอักขระเพื่อให้เข้ารหัสได้ โดยปกติแล้วจะดำเนินการใน รูปแบบไบนารี ซึ่งอาจไม่เข้ากันกับโปรโตคอลการส่งข้อมูลบางอย่าง โดยทั่วไปแล้ว ระบบจะเข้ารหัสข้อมูลเป็น Base64 ซึ่งเป็นการเข้ารหัสที่ใช้กันทั่วไป และเครื่องมือต่างๆ ที่รับข้อมูลไบนารีไม่ได้ยอมรับ เพื่อให้ข้อมูลเข้ากันได้ โดยทั่วไปจะใช้ 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สตริงของข้อมูลที่จะเข้ารหัส
charsetCharsetCharset ที่ระบุชุดอักขระของอินพุต

รีเทิร์น

String - การแสดงสตริงอินพุตที่เข้ารหัส Base64 พร้อมด้วย Charset ที่ระบุ


base64EncodeWebSafe(data)

สร้างสตริงที่เข้ารหัส Web-safe 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.base64EncodeWebSafe(blob.getBytes());
Logger.log(encoded);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dataByte[]อาร์เรย์ของไบต์ของข้อมูลที่จะเข้ารหัส

รีเทิร์น

String — การแสดงข้อมูลที่ส่งผ่านซึ่งเข้ารหัส Web-safe base64


base64EncodeWebSafe(data)

สร้างสตริงที่เข้ารหัส Web-safe base64 จากสตริงที่ระบุ Base64 เป็นการเข้ารหัสที่ใช้กันทั่วไป ซึ่งเครื่องมือต่างๆ ที่รับข้อมูลไบนารีไม่ได้ยอมรับ โดยทั่วไปจะใช้ Base 64 ที่ปลอดภัยบนเว็บ ในโปรโตคอลอินเทอร์เน็ต เช่น อีเมล, HTTP หรือในเอกสาร XML

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

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dataStringสตริงที่จะเข้ารหัส

รีเทิร์น

String — การแสดงสตริงอินพุตที่เข้ารหัส Web-safe base64


base64EncodeWebSafe(data, charset)

สร้างสตริงที่เข้ารหัสแบบ Web-safe base-64 จากสตริงที่กำหนดในชุดอักขระที่เฉพาะเจาะจง Charset คือวิธีการเข้ารหัสอักขระเพื่อให้เข้ารหัสได้ โดยปกติแล้วจะดำเนินการในรูปแบบไบนารี ซึ่งอาจไม่สามารถใช้ร่วมกับโปรโตคอลการส่งข้อมูลบางอย่างได้ โดยทั่วไปแล้ว ระบบจะเข้ารหัสข้อมูลเป็น Base64 เพื่อให้ข้อมูลเข้ากันได้ ซึ่งเป็น การเข้ารหัสทั่วไปที่เครื่องมือต่างๆ ยอมรับซึ่งไม่สามารถยอมรับข้อมูลไบนารีได้ 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สตริงของข้อมูลที่จะเข้ารหัส
charsetCharsetCharset ที่ระบุชุดอักขระของอินพุต

รีเทิร์น

String — การแสดงสตริงอินพุตที่เข้ารหัส Web-safe base64 พร้อมด้วย Charset ที่ระบุ


computeDigest(algorithm, value)

คำนวณแฮชโดยใช้อัลกอริทึมที่ระบุในค่า Byte[] ที่ระบุ

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

พารามิเตอร์

ชื่อประเภทคำอธิบาย
algorithmDigestAlgorithmA DigestAlgorithm เพื่อใช้
valueByte[]ค่าสตริงอินพุตที่จะใช้คำนวณแฮช

รีเทิร์น

Byte[] — อาร์เรย์ไบต์ที่แสดงค่าแฮชเอาต์พุต


computeDigest(algorithm, value)

คำนวณแฮชโดยใช้อัลกอริทึมที่ระบุในค่า String ที่ระบุ

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

พารามิเตอร์

ชื่อประเภทคำอธิบาย
algorithmDigestAlgorithmA DigestAlgorithm เพื่อใช้
valueStringค่าสตริงอินพุตที่จะใช้คำนวณแฮช

รีเทิร์น

Byte[] — อาร์เรย์ไบต์ที่แสดงค่าแฮชเอาต์พุต


computeDigest(algorithm, value, charset)

คำนวณค่าแฮชโดยใช้อัลกอริทึมที่ระบุในStringค่าที่ระบุด้วย ชุดอักขระที่กำหนด

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

พารามิเตอร์

ชื่อประเภทคำอธิบาย
algorithmDigestAlgorithmA DigestAlgorithm เพื่อใช้
valueStringค่าสตริงอินพุตที่จะใช้คำนวณแฮช
charsetCharsetCharset ที่แสดงชุดอักขระอินพุต

รีเทิร์น

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[] — อาร์เรย์ไบต์ที่แสดงลายเซ็นเอาต์พุต


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[] — อาร์เรย์ไบต์ที่แสดงลายเซ็นเอาต์พุต


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คีย์ที่ใช้สร้างแฮช
charsetCharsetCharset ที่แสดงชุดอักขระอินพุต

รีเทิร์น

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[] — อาร์เรย์ไบต์ที่แสดงลายเซ็นเอาต์พุต


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[] — อาร์เรย์ไบต์ที่แสดงลายเซ็นเอาต์พุต


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คีย์ที่ใช้สร้างแฮช
charsetCharsetCharset ที่แสดงชุดอักขระอินพุต

รีเทิร์น

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[] — อาร์เรย์ไบต์ที่แสดงลายเซ็นเอาต์พุต


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 ที่ใช้สร้างลายเซ็น
charsetCharsetCharset ที่แสดงชุดอักขระอินพุต

รีเทิร์น

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[] — อาร์เรย์ไบต์ที่แสดงลายเซ็นเอาต์พุต


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 ที่ใช้สร้างลายเซ็น
charsetCharsetCharset ที่แสดงชุดอักขระอินพุต

รีเทิร์น

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[] — อาร์เรย์ไบต์ที่แสดงลายเซ็นเอาต์พุต


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 ที่ใช้สร้างลายเซ็น
charsetCharsetCharset ที่แสดงชุดอักขระอินพุต

รีเทิร์น

Byte[] — อาร์เรย์ไบต์ที่แสดงลายเซ็นเอาต์พุต


formatDate(date, timeZone, format)

จัดรูปแบบวันที่ตามข้อกำหนดที่อธิบายไว้ในคลาส SimpleDateFormat ของ Java SE โปรดดูข้อกำหนดที่ 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dateDateDate เพื่อจัดรูปแบบเป็นสตริง
timeZoneStringเขตเวลาเอาต์พุตของผลลัพธ์
formatStringรูปแบบตามSimpleDateFormatข้อกำหนด

รีเทิร์น

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
blobBlobSourceออบเจ็กต์ Blob ที่จะบีบอัดโดยใช้ gzip

รีเทิร์น

BlobBlobใหม่ที่มีข้อมูลที่บีบอัด


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');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
blobBlobSourceออบเจ็กต์ Blob ที่จะบีบอัดโดยใช้ gzip
nameStringชื่อของgzipไฟล์ที่จะสร้าง

รีเทิร์น

BlobBlobใหม่ที่มีข้อมูลที่บีบอัด


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
contentTypeStringประเภทเนื้อหาของ Blob ซึ่งอาจเป็น 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 ได้
nameStringชื่อของ Blob - สามารถเป็น 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dataStringสตริงสำหรับ Blob ซึ่งถือว่าเป็น 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dataStringสตริงสำหรับ Blob ซึ่งถือว่าเป็น UTF-8
contentTypeStringประเภทเนื้อหาของ Blob ซึ่งอาจเป็น 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dataStringสตริงสำหรับ Blob ซึ่งถือว่าเป็น UTF-8
contentTypeStringประเภทเนื้อหาของ Blob ซึ่งอาจเป็น null
nameStringชื่อของ Blob - สามารถเป็น null

รีเทิร์น

Blob - BLOB ที่สร้างขึ้นใหม่


parseCsv(csv)

แสดงผลการแสดงอาร์เรย์ 2 มิติแบบตารางของสตริง CSV

// 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[][] — อาร์เรย์ 2 มิติที่มีค่าในสตริง CSV


parseCsv(csv, delimiter)

แสดงการแทนอาร์เรย์ 2 มิติแบบตารางของสตริง CSV โดยใช้ตัวคั่นที่กำหนดเอง

// 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[][] — อาร์เรย์ 2 มิติที่มีค่าในสตริง CSV


parseDate(date, timeZone, format)

แยกวิเคราะห์วันที่สตริงที่ระบุตามข้อกำหนดที่อธิบายไว้ในคลาส Java Standard Edition SimpleDateFormat ดูข้อมูลเพิ่มเติมได้ที่คลาส SimpleDateFormat ของ Java

// 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เขตเวลาเอาต์พุต
formatStringรูปแบบวันที่ตามSimpleDateFormatข้อกำหนด

รีเทิร์น

Date - สตริงอินพุตเป็นวันที่


sleep(milliseconds)

พักเป็นจำนวนมิลลิวินาทีที่ระบุ ทำให้สคริปต์เข้าสู่โหมดพักทันทีเป็นเวลา จำนวนมิลลิวินาทีที่ระบุ ค่าสูงสุดที่อนุญาตคือ 300000 (หรือ 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
blobBlobSourceBlob ของข้อมูลที่บีบอัด

รีเทิร์น

Blob — อาร์เรย์ไบต์Blobที่แสดงข้อมูลที่คลายการบีบอัดแล้ว


unzip(blob)

รับ Blob ที่แสดงไฟล์ ZIP และแสดงผลไฟล์คอมโพเนนต์

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
blobBlobSourceBlob ของไฟล์ ZIP

รีเทิร์น

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[]อาร์เรย์ของ 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[]อาร์เรย์ของ Blob ที่จะบีบอัด
nameStringชื่อของไฟล์ ZIP ที่จะสร้าง

รีเทิร์น

Blob — Blob ใหม่ที่มีอินพุตเป็นที่เก็บถาวร

วิธีการที่เลิกใช้งานแล้ว