Class RichTextValueBuilder
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
RichTextValueBuilder
ตัวสร้างค่า Rich Text
เอกสารประกอบโดยละเอียด
build()
สร้างค่า Rich Text จากเครื่องมือสร้างนี้
รีเทิร์น
RichTextValue
— ค่าข้อความที่มีรูปแบบที่สร้างจากเครื่องมือสร้างนี้
setLinkUrl(startOffset, endOffset, linkUrl)
ตั้งค่า URL ของลิงก์สำหรับสตริงย่อยที่ระบุของค่านี้ หรือล้างค่าหาก linkUrl
เป็น null
// Creates a Rich Text value for the text "foo no baz" with "foo" pointing to
// "https://bar.foo" and "baz" to "https://abc.xyz".
// "foo" is underlined with the default link color, whereas "baz" has its text
// style overridden by a call to `setTextStyle`, and is therefore black and bold
// with no underlining.
const boldStyle = SpreadsheetApp.newTextStyle()
.setUnderline(false)
.setBold(true)
.setForegroundColor('#000000')
.build();
const value = SpreadsheetApp.newRichTextValue()
.setText('foo no baz')
.setLinkUrl(0, 3, 'https://bar.foo')
.setLinkUrl(7, 10, 'https://abc.xyz')
.setTextStyle(7, 10, boldStyle)
.build();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
startOffset | Integer | ออฟเซ็ตเริ่มต้นของสตริงย่อย โดยรวม |
endOffset | Integer | ช่วงเวลาสิ้นสุดของสตริงย่อย ไม่รวมช่วงเวลาสิ้นสุดนี้ด้วย |
linkUrl | String | URL ของลิงก์ที่ตั้งค่า |
รีเทิร์น
RichTextValueBuilder
— ตัวสร้างนี้สําหรับการต่อเชื่อม
setLinkUrl(linkUrl)
ตั้งค่า URL ของลิงก์สำหรับค่าทั้งหมด หรือล้างค่าหาก linkUrl
เป็น null
// Creates a Rich Text value for the text "Foo" which points to
// "https://bar.foo".
const value = SpreadsheetApp.newRichTextValue()
.setText('Foo')
.setLinkUrl('https://bar.foo')
.build();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
linkUrl | String | URL ของลิงก์ที่ตั้งค่า |
รีเทิร์น
RichTextValueBuilder
— ตัวสร้างนี้สําหรับการต่อเชื่อม
setTextStyle(startOffset, endOffset, textStyle)
ใช้รูปแบบข้อความกับสตริงย่อยที่ระบุของค่านี้ การออฟเซตจะอิงตาม 0 และสัมพันธ์กับค่าข้อความของเซลล์ ไม่ดําเนินการใดๆ หาก textStyle
เป็น null
// Creates a Rich Text value for the text "HelloWorld", with "Hello" bolded, and
// "World" italicized.
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
const value = SpreadsheetApp.newRichTextValue()
.setText('HelloWorld')
.setTextStyle(0, 5, bold)
.setTextStyle(5, 10, italic)
.build();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
startOffset | Integer | ออฟเซ็ตเริ่มต้นของสตริงย่อย โดยรวม |
endOffset | Integer | ช่วงเวลาสิ้นสุดของสตริงย่อย ไม่รวมช่วงเวลาสิ้นสุดนี้ด้วย |
textStyle | TextStyle | รูปแบบข้อความที่กำลังตั้งค่า |
รีเทิร์น
RichTextValueBuilder
— ตัวสร้างนี้สําหรับการต่อเชื่อม
setTextStyle(textStyle)
ใช้รูปแบบข้อความกับทั้งค่า รูปแบบข้อความที่ตั้งไว้ก่อนหน้านี้จะได้รับผลกระทบก็ต่อเมื่อมีค่าภายใน textStyle
เขียนทับโดยตรงเท่านั้น ไม่ดําเนินการใดๆ หาก textStyle
เป็น null
// Creates a Rich Text value for the text "HelloWorld" with "Hello" bolded and
// italicized, and "World" only italicized.
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
const value = SpreadsheetApp.newRichTextValue()
.setText('HelloWorld')
.setTextStyle(0, 5, bold)
.setTextStyle(italic)
.build();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
textStyle | TextStyle | รูปแบบข้อความที่กำลังตั้งค่า |
รีเทิร์น
RichTextValueBuilder
— ตัวสร้างนี้สําหรับการต่อเชื่อม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eThe \u003ccode\u003eRichTextValueBuilder\u003c/code\u003e enables the creation and customization of rich text values within a spreadsheet.\u003c/p\u003e\n"],["\u003cp\u003eYou can set text styles, like bold or italic, for specific portions or the entire text value using the builder.\u003c/p\u003e\n"],["\u003cp\u003eHyperlinks can be added to substrings or the whole text value via the \u003ccode\u003esetLinkUrl\u003c/code\u003e methods of the builder.\u003c/p\u003e\n"],["\u003cp\u003eThe builder provides a fluent interface using a chaining pattern, allowing for sequential method calls to construct the desired rich text.\u003c/p\u003e\n"],["\u003cp\u003eFinally, call the \u003ccode\u003ebuild()\u003c/code\u003e method to generate the \u003ccode\u003eRichTextValue\u003c/code\u003e object based on the configurations set in the builder.\u003c/p\u003e\n"]]],[],null,["# Class RichTextValueBuilder\n\nRichTextValueBuilder\n\nA builder for Rich Text values. \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------------------------------------------------------|---------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|\n| [build()](#build()) | [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value) | Creates a Rich Text value from this builder. |\n| [setLinkUrl(startOffset, endOffset, linkUrl)](#setLinkUrl(Integer,Integer,String)) | [RichTextValueBuilder](#) | Sets the link URL for the given substring of this value, or clears it if `link``Url` is `null`. |\n| [setLinkUrl(linkUrl)](#setLinkUrl(String)) | [RichTextValueBuilder](#) | Sets the link URL for the entire value, or clears it if `link``Url` is `null`. |\n| [setText(text)](#setText(String)) | [RichTextValueBuilder](#) | Sets the text for this value and clears any existing text style. |\n| [setTextStyle(startOffset, endOffset, textStyle)](#setTextStyle(Integer,Integer,TextStyle)) | [RichTextValueBuilder](#) | Applies a text style to the given substring of this value. |\n| [setTextStyle(textStyle)](#setTextStyle(TextStyle)) | [RichTextValueBuilder](#) | Applies a text style to the entire value. |\n\nDetailed documentation\n----------------------\n\n### `build()`\n\nCreates a Rich Text value from this builder.\n\n#### Return\n\n\n[RichTextValue](/apps-script/reference/spreadsheet/rich-text-value) --- A Rich Text value created from this builder.\n\n*** ** * ** ***\n\n### `set``Link``Url(startOffset, endOffset, linkUrl)`\n\nSets the link URL for the given substring of this value, or clears it if `link``Url` is\n`null`.\n\n```javascript\n// Creates a Rich Text value for the text \"foo no baz\" with \"foo\" pointing to\n// \"https://bar.foo\" and \"baz\" to \"https://abc.xyz\".\n// \"foo\" is underlined with the default link color, whereas \"baz\" has its text\n// style overridden by a call to `setTextStyle`, and is therefore black and bold\n// with no underlining.\nconst boldStyle = SpreadsheetApp.newTextStyle()\n .setUnderline(false)\n .setBold(true)\n .setForegroundColor('#000000')\n .build();\nconst value = SpreadsheetApp.newRichTextValue()\n .setText('foo no baz')\n .setLinkUrl(0, 3, 'https://bar.foo')\n .setLinkUrl(7, 10, 'https://abc.xyz')\n .setTextStyle(7, 10, boldStyle)\n .build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------|-----------|------------------------------------------------|\n| `start``Offset` | `Integer` | The start offset for the substring, inclusive. |\n| `end``Offset` | `Integer` | The end offset for the substring, exclusive. |\n| `link``Url` | `String` | The link URL being set. |\n\n#### Return\n\n\n[RichTextValueBuilder](#) --- This builder, for chaining.\n\n*** ** * ** ***\n\n### `set``Link``Url(linkUrl)`\n\nSets the link URL for the entire value, or clears it if `link``Url` is `null`.\n\n```javascript\n// Creates a Rich Text value for the text \"Foo\" which points to\n// \"https://bar.foo\".\nconst value = SpreadsheetApp.newRichTextValue()\n .setText('Foo')\n .setLinkUrl('https://bar.foo')\n .build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-------------|----------|-------------------------|\n| `link``Url` | `String` | The link URL being set. |\n\n#### Return\n\n\n[RichTextValueBuilder](#) --- This builder, for chaining.\n\n*** ** * ** ***\n\n### `set``Text(text)`\n\nSets the text for this value and clears any existing text style. When creating a new Rich Text\nvalue, this should be called before [setTextStyle(startOffset, endOffset, textStyle)](#setTextStyle(Integer,Integer,TextStyle)).\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|--------------------------|\n| `text` | `String` | The text for this value. |\n\n#### Return\n\n\n[RichTextValueBuilder](#) --- This builder, for chaining.\n\n*** ** * ** ***\n\n### `set``Text``Style(startOffset, endOffset, textStyle)`\n\nApplies a text style to the given substring of this value. Offsets are 0 based and are relative\nto the cell's text value. Does nothing if `text``Style` is `null`.\n\n```javascript\n// Creates a Rich Text value for the text \"HelloWorld\", with \"Hello\" bolded, and\n// \"World\" italicized.\nconst bold = SpreadsheetApp.newTextStyle().setBold(true).build();\nconst italic = SpreadsheetApp.newTextStyle().setItalic(true).build();\nconst value = SpreadsheetApp.newRichTextValue()\n .setText('HelloWorld')\n .setTextStyle(0, 5, bold)\n .setTextStyle(5, 10, italic)\n .build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------|------------------------------------------------------------|------------------------------------------------|\n| `start``Offset` | `Integer` | The start offset for the substring, inclusive. |\n| `end``Offset` | `Integer` | The end offset for the substring, exclusive. |\n| `text``Style` | [TextStyle](/apps-script/reference/spreadsheet/text-style) | The text style being set. |\n\n#### Return\n\n\n[RichTextValueBuilder](#) --- This builder, for chaining.\n\n*** ** * ** ***\n\n### `set``Text``Style(textStyle)`\n\nApplies a text style to the entire value. Previously set text styles are only affected if they\nare directly overwritten by values within `text``Style`. Does nothing if `text``Style`\nis `null`.\n\n```javascript\n// Creates a Rich Text value for the text \"HelloWorld\" with \"Hello\" bolded and\n// italicized, and \"World\" only italicized.\nconst bold = SpreadsheetApp.newTextStyle().setBold(true).build();\nconst italic = SpreadsheetApp.newTextStyle().setItalic(true).build();\nconst value = SpreadsheetApp.newRichTextValue()\n .setText('HelloWorld')\n .setTextStyle(0, 5, bold)\n .setTextStyle(italic)\n .build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------------|------------------------------------------------------------|---------------------------|\n| `text``Style` | [TextStyle](/apps-script/reference/spreadsheet/text-style) | The text style being set. |\n\n#### Return\n\n\n[RichTextValueBuilder](#) --- This builder, for chaining."]]