ทํางานกับคําแนะนํา

Google เอกสารช่วยให้ผู้ทำงานร่วมกันสามารถ ให้คำแนะนำ ซึ่งมีประสิทธิภาพเลื่อนเวลาการแก้ไขเพื่อรอการอนุมัติอยู่

เมื่อคุณใช้วิธีการ documents.get เพื่อดึงเนื้อหาเอกสาร เนื้อหาอาจมีคําแนะนําที่ยังไม่ได้แก้ไข หากต้องการควบคุมวิธีที่ documents.get แสดงคำแนะนำ ให้ใช้พารามิเตอร์ SuggestionsViewMode ที่ไม่บังคับ เงื่อนไขตัวกรองต่อไปนี้ใช้ได้กับพารามิเตอร์นี้

  • รับเนื้อหาด้วย SUGGESTIONS_INLINE เพื่อให้ข้อความที่รอการลบหรือการแทรกปรากฏในเอกสาร
  • รับเนื้อหาเป็นตัวอย่างพร้อมยอมรับคำแนะนำทั้งหมด
  • รับเนื้อหาเป็นตัวอย่าง โดยไม่มีคำแนะนำ โดยปฏิเสธคำแนะนำทั้งหมด

ถ้าคุณไม่ระบุ SuggestionsViewMode Google เอกสาร API จะใช้การตั้งค่าเริ่มต้นที่เหมาะสมกับสิทธิ์ของผู้ใช้ปัจจุบัน

คำแนะนำและดัชนี

เหตุผลหนึ่งที่ SuggestionsViewMode สำคัญคือดัชนีในการตอบสนองอาจแตกต่างกันไปโดยขึ้นอยู่กับว่ามีคำแนะนำดังที่แสดงด้านล่าง

เนื้อหาที่มีคำแนะนำ เนื้อหาที่ไม่มีคำแนะนำ
{
 "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"
  }
 }
},

{
 "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

สตริงสุดท้าย SUGGEST_MODE = "PREVIEW_WITHOUT_SUGGESTIONS"; เอกสารเอกสาร = service.documents().get(DOCUMENT_ID).setSuggestionsViewMode(SUGGEST_MODE).execute();

Python

SUGGEST_MODE="PREVIEW_WITHOUT_SUGGESTIONS" ผลลัพธ์ = service.documents().get(documentId=DOCUMENT_ID, 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 เท่านั้น