علامة تبويب في المستند تحتوي على نص منسَّق وعناصر مثل الجداول والقوائم
استرداد علامة تبويب في المستند باستخدام Document.getTabs()[tabIndex].asDocumentTab()
// Get a specific document tab based on the tab ID. // TODO(developer): Replace the IDs with your own. const documentTab = DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();
الطُرق
| الطريقة | نوع القيمة التي تم إرجاعها | وصف قصير |
|---|---|---|
add | Bookmark | تضيف هذه الطريقة Bookmark في Position المحدّد. |
add | Footer | تضيف هذه السمة قسم تذييل علامة التبويب، إذا لم يكن هناك قسم. |
add | Header | تضيف هذه السمة قسمًا لعنوان علامة التبويب، إذا لم يكن هناك قسم. |
add | Named | تضيف هذه السمة Named، وهي Range لها اسم ورقم تعريف يمكن استخدامهما في
عمليات الاسترداد اللاحقة. |
get | Body | تعرض هذه السمة Body لعلامة التبويب. |
get | Bookmark|null | تعرض هذه الطريقة Bookmark بالمعرّف المحدّد. |
get | Bookmark[] | تعرض هذه السمة جميع عناصر Bookmark في علامة التبويب. |
get | Footer | تعرض هذه السمة قسم التذييل لعلامة التبويب، إذا كان متوفّرًا. |
get | Footnote[]|null | يستردّ هذا الإجراء جميع عناصر Footnote في نص علامة التبويب. |
get | Header | تعرض هذه الطريقة قسم عنوان علامة التبويب، إذا كان متوفّرًا. |
get | Named | تعرض هذه الطريقة Named بالمعرّف المحدّد. |
get | Named | تعرض هذه السمة جميع عناصر Named في علامة التبويب. |
get | Named | تعرض جميع عناصر Named في علامة التبويب التي تحمل الاسم المحدّد. |
new | Position | ينشئ هذا الإجراء Position جديدًا، وهو مرجع إلى موقع جغرافي في علامة التبويب، بالنسبة إلى عنصر معيّن. |
new | Range | تنشئ هذه الدالة أداة إنشاء تُستخدَم لإنشاء عناصر Range من عناصر علامات التبويب. |
مستندات تفصيلية
addBookmark(position)
تضيف هذه الطريقة Bookmark في Position المحدّد.
// Opens the Docs file and retrieves the tab by its IDs. If you created your // script from within a Google Docs file, you can use // DocumentApp.getActiveDocument().getActiveTab() instead. // TODO(developer): Replace the IDs with your own. const documentTab = DocumentApp.openById('123abc').getTab('123abc').asDocumentTab(); // Gets the tab body and adds a paragraph. const paragraph = documentTab.getBody().appendParagraph('My new paragraph.'); // Creates a position at the first character of the paragraph text. const position = documentTab.newPosition(paragraph.getChild(0), 0); // Adds a bookmark at the first character of the paragraph text. const bookmark = documentTab.addBookmark(position); // Logs the bookmark ID to the console. console.log(bookmark.getId());
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
position | Position | موضع الإشارة المرجعية الجديدة |
الإرجاع
Bookmark: الإشارة المرجعية الجديدة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
addHeader()
تضيف هذه السمة قسمًا لعنوان علامة التبويب، إذا لم يكن هناك قسم.
// Opens the Docs file and retrieves the tab by its IDs. If you created your // script from within a Google Docs file, you can use // DocumentApp.getActiveDocument().getActiveTab() instead. // TODO(developer): Replace the IDs with your own. const documentTab = DocumentApp.openById('123abc').getTab('123abc').asDocumentTab(); // Adds a header to the tab. const header = documentTab.addHeader(); // Sets the header text to 'This is a header.' header.setText('This is a header');
الإرجاع
HeaderSection: عنوان علامة التبويب
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
addNamedRange(name, range)
تضيف هذه السمة NamedRange، وهي Range لها اسم ورقم تعريف يمكن استخدامهما في
عمليات الاسترداد اللاحقة. لا تكون الأسماء فريدة بالضرورة، حتى في علامات التبويب المختلفة، إذ يمكن أن تتشارك عدة نطاقات مختلفة في المستند نفسه الاسم نفسه، تمامًا مثل فئة في HTML. في المقابل، تكون المعرّفات فريدة ضمن المستند، مثل المعرّف في HTML. بعد إضافة NamedRange، لا يمكنك تعديله، بل يمكنك فقط إزالته.
يمكن لأي نص برمجي يصل إلى علامة التبويب الوصول إلى NamedRange. لتجنُّب حدوث تعارضات غير مقصودة بين النصوص البرمجية، ننصحك بإضافة بادئة فريدة إلى أسماء النطاقات.
// Creates a named range that includes every table in a tab by its ID. // TODO(developer): Replace the IDs with your own. const documentTab = DocumentApp.openById('123abc').getTab('123abc').asDocumentTab(); const rangeBuilder = documentTab.newRange(); const tables = documentTab.getBody().getTables(); for (let i = 0; i < tables.length; i++) { rangeBuilder.addElement(tables[i]); } documentTab.addNamedRange('Tab t.0 tables', rangeBuilder.build());
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
name | String | اسم النطاق، ولا يشترط أن يكون فريدًا، ويجب أن يتراوح طوله بين حرف واحد و256 حرفًا. |
range | Range | نطاق العناصر المطلوب ربطها بالاسم، ويمكن أن يكون النطاق نتيجة بحث أو يتم إنشاؤه يدويًا باستخدام new. |
الإرجاع
NamedRange — NamedRange
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getBody()
تعرض هذه السمة Body لعلامة التبويب.
قد تحتوي علامات التبويب على أنواع مختلفة من الأقسام (مثل HeaderSection وFooterSection). القسم النشط لعلامة التبويب هو Body.
تتم تفويض طرق العناصر في DocumentTab إلى Body.
// Opens the Docs file and retrieves the tab by its IDs. If you created your // script from within a Google Docs file, you can use // DocumentApp.getActiveDocument().getActiveTab() instead. // TODO(developer): Replace the IDs with your own. const documentTab = DocumentApp.openById('123abc').getTab('123abc').asDocumentTab(); // Gets the tab body. const body = documentTab.getBody(); // Gets the body text and logs it to the console. console.log(body.getText());
الإرجاع
Body: قسم نص علامة التبويب
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getBookmark(id)
تعرض هذه الطريقة Bookmark بالمعرّف المحدّد. تعرض هذه الطريقة null إذا لم يكن هناك Bookmark من هذا النوع في علامة التبويب هذه.
// Opens the Docs file and retrieves the tab by its IDs. If you created your // script from within a Google Docs file, you can use // DocumentApp.getActiveDocument().getActiveTab() instead. // TODO(developer): Replace the IDs with your own. const documentTab = DocumentApp.openById('123abc').getTab('123abc').asDocumentTab(); // Gets the bookmark by its ID. const bookmark = documentTab.getBookmark('id.xyz654321'); // If the bookmark exists within the tab, logs the character offset of its // position to the console. Otherwise, logs 'No bookmark exists with the given // ID.' to the console. if (bookmark) { console.log(bookmark.getPosition().getOffset()); } else { console.log('No bookmark exists with the given ID.'); }
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
id | String | تمثّل هذه السمة المعرّف الخاص بـ Bookmark. |
الإرجاع
Bookmark|null: Bookmark الذي يحمل رقم التعريف المحدّد، أو null إذا لم يكن هناك Bookmark بهذا الرقم ضمن علامة التبويب
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getBookmarks()
تعرض هذه السمة جميع عناصر Bookmark في علامة التبويب.
// Opens the Docs file and retrieves the tab by its IDs. If you created your // script from within a Google Docs file, you can use // DocumentApp.getActiveDocument().getActiveTab() instead. // TODO(developer): Replace the IDs with your own. const documentTab = DocumentApp.openById('123abc').getTab('123abc').asDocumentTab(); // Gets all of the bookmarks in the tab. const bookmarks = documentTab.getBookmarks(); // Logs the number of bookmarks in the tab to the console. console.log(bookmarks.length);
الإرجاع
Bookmark[]: مصفوفة من عناصر Bookmark في علامة التبويب
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getFootnotes()
يستردّ هذا الإجراء جميع عناصر Footnote في نص علامة التبويب.
تؤدي طلبات البحث إلى getFootnotes إلى تكرار عناصر علامة التبويب. بالنسبة إلى علامات التبويب الكبيرة،
تجنَّب إجراء مكالمات غير ضرورية لهذه الطريقة.
// Opens the Docs file and retrieves the tab by its IDs. If you created your // script from within a Google Docs file, you can use // DocumentApp.getActiveDocument().getActiveTab() instead. // TODO(developer): Replace the IDs with your own. const documentTab = DocumentApp.openById('123abc').getTab('123abc').asDocumentTab(); // Gets the first footnote. const footnote = documentTab.getFootnotes()[0]; // Logs footnote contents to the console. console.log(footnote.getFootnoteContents().getText());
الإرجاع
Footnote[]|null: الحواشي السفلية للأغنية
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getHeader()
تعرض هذه الطريقة قسم عنوان علامة التبويب، إذا كان متوفّرًا.
// Opens the Docs file and retrieves the tab by its IDs. If you created your // script from within a Google Docs file, you can use // DocumentApp.getActiveDocument().getActiveTab() instead. // TODO(developer): Replace the IDs with your own. const documentTab = DocumentApp.openById('123abc').getTab('123abc').asDocumentTab(); // Gets the text of the tab's header and logs it to the console. console.log(documentTab.getHeader().getText());
الإرجاع
HeaderSection|null: عنوان علامة التبويب
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNamedRangeById(id)
تعرض هذه الطريقة NamedRange بالمعرّف المحدّد. تعرض هذه الطريقة null إذا لم يكن هناك
NamedRange في علامة التبويب. ليست الأسماء فريدة بالضرورة، حتى في علامات التبويب المختلفة، فقد تتشارك عدة نطاقات مختلفة في المستند نفسه الاسم نفسه، تمامًا مثل فئة في HTML. في المقابل، تكون المعرّفات فريدة داخل علامة التبويب، مثل المعرّف في HTML.
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
id | String | معرّف النطاق، وهو معرّف فريد ضمن علامة التبويب. |
الإرجاع
NamedRange|null: NamedRange الذي يتضمّن رقم التعريف المحدّد، أو null إذا لم يكن هناك نطاق بهذا الرقم في علامة التبويب
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNamedRanges()
تعرض هذه السمة جميع عناصر NamedRange في علامة التبويب.
يمكن لأي نص برمجي يصل إلى علامة التبويب الوصول إلى NamedRange. لتجنُّب حدوث تعارضات غير مقصودة بين النصوص البرمجية، ننصحك بإضافة بادئة فريدة إلى أسماء النطاقات.
الإرجاع
NamedRange[]: مصفوفة من عناصر NamedRange في علامة التبويب، وقد تتضمّن نطاقات متعددة بالاسم نفسه.
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNamedRanges(name)
تعرض جميع عناصر NamedRange في علامة التبويب التي تحمل الاسم المحدّد. ليست الأسماء فريدة بالضرورة، حتى في علامات التبويب المختلفة، فقد تتشارك عدة نطاقات مختلفة في المستند نفسه الاسم نفسه، تمامًا مثل الفئة في HTML. في المقابل، تكون المعرّفات فريدة ضمن علامة التبويب، مثل المعرّف في HTML.
يمكن لأي نص برمجي يصل إلى علامة التبويب الوصول إلى NamedRange. لتجنُّب حدوث تعارضات غير مقصودة بين النصوص البرمجية، ننصحك بإضافة بادئة فريدة إلى أسماء النطاقات.
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
name | String | اسم النطاق، وهو ليس فريدًا بالضرورة. |
الإرجاع
NamedRange[]: مصفوفة من عناصر NamedRange في علامة التبويب التي تحمل الاسم المحدّد
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
newPosition(element, offset)
ينشئ هذا الإجراء Position جديدًا، وهو مرجع إلى موقع جغرافي في علامة التبويب، بالنسبة إلى عنصر معيّن. يتم تمثيل مؤشر المستخدم على شكل Position، من بين استخدامات أخرى.
// Append a paragraph, then place the user's cursor after the first word of the // new paragraph. // TODO(developer): Replace the IDs with your own. const doc = DocumentApp.openById('123abc'); const documentTab = doc.getTab('123abc').asDocumentTab(); const paragraph = documentTab.getBody().appendParagraph('My new paragraph.'); const position = documentTab.newPosition(paragraph.getChild(0), 2); doc.setCursor(position);
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
element | Element | العنصر الذي يحتوي على Position الذي تم إنشاؤه حديثًا، ويجب أن يكون إما عنصر Text أو عنصر حاوية مثل Paragraph. |
offset | Integer | بالنسبة إلى عناصر Text، يمثّل هذا الرقم عدد الأحرف التي تسبق Position، أما بالنسبة إلى العناصر الأخرى، فيمثّل عدد العناصر الثانوية التي تسبق Position ضمن عنصر الحاوية نفسه. |
الإرجاع
Position: Position الجديد
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
newRange()
تنشئ هذه الدالة أداة إنشاء تُستخدَم لإنشاء عناصر Range من عناصر علامات التبويب.
// Change the user's selection to a range that includes every table in the tab. // TODO(developer): Replace the IDs with your own. const doc = DocumentApp.openById('123abc'); const documentTab = doc.getTab('123abc').asDocumentTab(); const rangeBuilder = documentTab.newRange(); const tables = documentTab.getBody().getTables(); for (let i = 0; i < tables.length; i++) { rangeBuilder.addElement(tables[i]); } doc.setSelection(rangeBuilder.build());
الإرجاع
RangeBuilder: أداة الإنشاء الجديدة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents