Google เอกสารช่วยให้ผู้ทำงานร่วมกันสามารถเสนอแนะซึ่งเป็น การแก้ไขที่เลื่อนออกไปรอการอนุมัติได้อย่างมีประสิทธิภาพ
เมื่อใช้วิธี
documents.get
เพื่อ
ดึงเนื้อหาเอกสาร เนื้อหาอาจมีคำแนะนำที่ยังไม่ได้รับการแก้ไข หากต้องการควบคุมวิธีที่ documents.get
แสดงคำแนะนำ ให้ใช้พารามิเตอร์SuggestionsViewMode
ที่ไม่บังคับ เงื่อนไขตัวกรองต่อไปนี้ใช้ได้กับพารามิเตอร์นี้
- รับเนื้อหาด้วย
SUGGESTIONS_INLINE
เพื่อให้ข้อความที่รอการลบหรือ การแทรกปรากฏในเอกสาร - รับเนื้อหาเป็นตัวอย่างโดยยอมรับคำแนะนำทั้งหมด
- รับเนื้อหาเป็นตัวอย่างโดยไม่มีคำแนะนำและปฏิเสธคำแนะนำทั้งหมด
หากคุณไม่ระบุ SuggestionsViewMode
Google Docs API จะใช้การตั้งค่าเริ่มต้น
ที่เหมาะสมกับสิทธิ์ของผู้ใช้ปัจจุบัน
คำแนะนำและดัชนี
เหตุผลหนึ่งที่ SuggestionsViewMode
มีความสำคัญคือดัชนีในคำตอบอาจแตกต่างกันไปตามว่ามีคำแนะนำหรือไม่ ดังที่แสดงด้านล่าง
เนื้อหาพร้อมคำแนะนำ | เนื้อหาที่ไม่มีคำแนะนำ |
---|---|
{ "tabs": [ { "documentTab": { "body": { "content": [ { "startIndex": 1, "endIndex": 31, "paragraph": { "elements": [ { "startIndex": 1, "endIndex": 31, "textRun": { "content": "Text preceding the suggestion\n", "textStyle": {} } } ], "paragraphStyle": { "namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT" } } }, { "startIndex": 31, "endIndex": 51, "paragraph": { "elements": [ { "startIndex": 31, "endIndex": 50, "textRun": { "content": "Suggested insertion", "suggestedInsertionIds": [ "suggest.vcti8ewm4mww" ], "textStyle": {} } }, { "startIndex": 50, "endIndex": 51, "textRun": { "content": "\n", "textStyle": {} } } ], "paragraphStyle": { "namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT" } } }, { "startIndex": 51, "endIndex": 81, "paragraph": { "elements": [ { "startIndex": 51, "endIndex": 81, "textRun": { "content": "Text following the suggestion\n", "textStyle": {} } } ], "paragraphStyle": { "namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT" } } } ] } } } ] }, |
{ "tabs": [ { "documentTab": { "body": { "content": [ { "startIndex": 1, "endIndex": 31, "paragraph": { "elements": [ { "startIndex": 1, "endIndex": 31, "textRun": { "content": "Text preceding the suggestion\n", "textStyle": {} } } ], "paragraphStyle": { "namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT" } } }, { "startIndex": 31, "endIndex": 32, "paragraph": { "elements": [ { "startIndex": 31, "endIndex": 32, "textRun": { "content": "\n", "textStyle": {} } } ], "paragraphStyle": { "namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT" } } }, { "startIndex": 32, "endIndex": 62, "paragraph": { "elements": [ { "startIndex": 32, "endIndex": 62, "textRun": { "content": "Text following the suggestion\n", "textStyle": {} } } ], "paragraphStyle": { "namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT" } } } ] } } } ] }, |
ในคำตอบด้านบน ย่อหน้าที่มีบรรทัด "ข้อความหลังคำแนะนำ" จะแสดงความแตกต่างเมื่อใช้ SuggestionsViewMode
เมื่อตั้งค่าเป็น SUGGESTIONS_INLINE
startIndex
ของ
ParagraphElement
จะเริ่มต้นที่ 51 และ endIndex
จะหยุดที่ 81 หากไม่มีคำแนะนำ startIndex
และ endIndex
จะอยู่ในช่วง 32-62
รับเนื้อหาโดยไม่มีคำแนะนำ
ตัวอย่างโค้ดบางส่วนต่อไปนี้แสดงวิธีรับเอกสารเป็นตัวอย่างโดยปฏิเสธคำแนะนำทั้งหมด (หากมี) โดยการตั้งค่าพารามิเตอร์ SuggestionsViewMode
เป็น PREVIEW_WITHOUT_SUGGESTIONS
Java
final string SUGGEST_MODE = "PREVIEW_WITHOUT_SUGGESTIONS"; Document doc = service .documents() .get(DOCUMENT_ID) .setIncludeTabsContent(true) .setSuggestionsViewMode(SUGGEST_MODE) .execute();
Python
SUGGEST_MODE = "PREVIEW_WITHOUT_SUGGESTIONS" result = ( service.documents() .get( documentId=DOCUMENT_ID, includeTabsContent=True, suggestionsViewMode=SUGGEST_MODE, ) .execute() )
การละเว้นพารามิเตอร์ SuggestionsViewMode
จะเทียบเท่ากับการระบุ
DEFAULT_FOR_CURRENT_ACCESS
เป็นค่าพารามิเตอร์
รูปแบบที่แนะนำ
เอกสารยังมีคำแนะนำด้านสไตล์ได้ด้วย การเปลี่ยนแปลงเหล่านี้เป็นคำแนะนำในการจัดรูปแบบและการนำเสนอ ไม่ใช่การเปลี่ยนแปลงเนื้อหา
การแทรกหรือลบข้อความจะไม่ชดเชยดัชนี แต่จะแบ่งTextRun
ออกเป็นส่วนเล็กๆ และเพิ่มคำอธิบายประกอบเกี่ยวกับการเปลี่ยนแปลงรูปแบบที่แนะนำ
คำอธิบายประกอบดังกล่าวคือ
SuggestedTextStyle
ซึ่งประกอบด้วย 2 ส่วน ได้แก่
textStyle
ซึ่งอธิบายวิธีจัดรูปแบบข้อความหลังจากมีการเปลี่ยนแปลงที่แนะนำ แต่ไม่ได้ระบุว่ามีการเปลี่ยนแปลงอะไรtextStyleSuggestionState
ซึ่งระบุว่าคำแนะนำจะเปลี่ยนแปลงฟิลด์ของtextStyle
อย่างไร
คุณจะเห็นสิ่งนี้ในข้อความที่ดึงมาจากแท็บเอกสารต่อไปนี้ ซึ่งรวมถึง การเปลี่ยนแปลงรูปแบบที่แนะนำ
[01] "paragraph": {
[02] "elements": [
[03] {
[04] "endIndex": 106,
[05] "startIndex": 82,
[06] "textRun": {
[07] "content": "Some text that does not ",
[08] "textStyle": {}
[09] }
[10] },
[11] {
[12] "endIndex": 115,
[13] "startIndex": 106,
[14] "textRun": {
[15] "content": "initially",
[16] "suggestedTextStyleChanges": {
[17] "suggest.xymysbs9zldp": {
[18] "textStyle": {
[19] "backgroundColor": {},
[20] "baselineOffset": "NONE",
[21] "bold": true,
[22] "fontSize": {
[23] "magnitude": 11,
[24] "unit": "PT"
[25] },
[26] "foregroundColor": {
[27] "color": {
[28] "rgbColor": {}
[29] }
[30] },
[31] "italic": false,
[32] "smallCaps": false,
[33] "strikethrough": false,
[34] "underline": false
[35] },
[36] "textStyleSuggestionState": {
[37] "boldSuggested": true,
[38] "weightedFontFamilySuggested": true
[39] }
[40] }
[41] },
[42] "textStyle": {
[43] "italic": true
[44] }
[45] }
[46] },
[47] {
[48] "endIndex": 143,
[49] "startIndex": 115,
[50] "textRun": {
[51] "content": " contain any boldface text.\n",
[52] "textStyle": {}
[53] }
[54] }
[55] ],
[56] "paragraphStyle": {
[57] "direction": "LEFT_TO_RIGHT",
[58] "namedStyleType": "NORMAL_TEXT"
[59] }
[60] }
ในตัวอย่างด้านบน ย่อหน้าประกอบด้วยข้อความ 3 รายการ โดยเริ่มที่บรรทัด 6, 14 และ 50 ตรวจสอบการเรียกใช้ข้อความตรงกลาง
- บรรทัดที่ 16: มีออบเจ็กต์
suggestedTextStyleChanges
- บรรทัดที่ 18:
textStyle
ระบุการจัดรูปแบบต่างๆ - บรรทัดที่ 36:
textStyleSuggestionState
บอกว่าเฉพาะส่วนที่เป็นตัวหนาของ ข้อกำหนดนี้เท่านั้นที่เป็นคำแนะนำ - บรรทัดที่ 42: การจัดรูปแบบตัวเอียงของข้อความนี้เป็นส่วนหนึ่งของเอกสารปัจจุบัน (และไม่ได้รับผลกระทบจากคำแนะนำ)
เฉพาะฟีเจอร์สไตล์ที่ตั้งค่าเป็น true
ใน textStyleSuggestionState
เท่านั้นที่จะเป็นส่วนหนึ่ง
ของคำแนะนำ