Class DocumentTab

علامة التبويبالمستند

علامة تبويب مستند تحتوي على نص منسَّق وعناصر مثل الجداول والقوائم

استرداد علامة تبويب مستند باستخدام 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();

الطُرق

الطريقةنوع القيمة التي يتم إرجاعهاوصف قصير
addBookmark(position)Bookmarkتضيف هذه الطريقة Bookmark في Position المحدّد.
addFooter()FooterSectionتضيف هذه السمة قسم تذييل علامة التبويب، إذا لم يكن هناك قسم تذييل.
addHeader()HeaderSectionتضيف هذه السمة قسمًا لعنوان علامة التبويب، إذا لم يكن هناك قسم.
addNamedRange(name, range)NamedRangeتضيف هذه السمة NamedRange، وهي Range تتضمّن اسمًا ورقم تعريف يمكن استخدامهما لاسترداد البيانات لاحقًا.
getBody()Bodyتعرض هذه السمة Body لعلامة التبويب.
getBookmark(id)Bookmark|nullتعرض هذه الطريقة Bookmark بالمعرّف المحدّد.
getBookmarks()Bookmark[]تعرض هذه السمة جميع عناصر Bookmark في علامة التبويب.
getFooter()FooterSection|nullتعرض هذه الطريقة قسم التذييل لعلامة التبويب، إذا كان متوفّرًا.
getFootnotes()Footnote[]|nullيستردّ هذا الإجراء جميع عناصر Footnote في نص علامة التبويب.
getHeader()HeaderSection|nullتعرض هذه الطريقة قسم العنوان الخاص بعلامة التبويب، إذا كان متوفّرًا.
getNamedRangeById(id)NamedRange|nullتعرض هذه الطريقة NamedRange بالمعرّف المحدّد.
getNamedRanges()NamedRange[]تعرض هذه السمة جميع عناصر NamedRange في علامة التبويب.
getNamedRanges(name)NamedRange[]تعرض هذه الدالة جميع عناصر NamedRange في علامة التبويب التي تحمل الاسم المحدّد.
newPosition(element, offset)Positionينشئ هذا الإجراء Position جديدًا، وهو مرجع إلى موقع جغرافي في علامة التبويب، بالنسبة إلى عنصر معيّن.
newRange()RangeBuilderتنشئ هذه الفئة أداة إنشاء تُستخدَم لإنشاء عناصر 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());

المعلمات

الاسمالنوعالوصف
positionPositionموضع الإشارة المرجعية الجديدة

الإرجاع

Bookmark: الإشارة المرجعية الجديدة

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

addFooter()

تضيف هذه السمة قسم تذييل علامة التبويب، إذا لم يكن هناك قسم تذييل.

// 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 footer to the tab.
const footer = documentTab.addFooter();

// Sets the footer text to 'This is a footer.'
footer.setText('This is a footer');

الإرجاع

FooterSection: تذييل علامة التبويب

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

المعلمات

الاسمالنوعالوصف
nameStringاسم النطاق، ولا يشترط أن يكون فريدًا، ويجب أن يتراوح طوله بين حرف واحد و256 حرفًا.
rangeRangeنطاق العناصر المطلوب ربطها بالاسم، ويمكن أن يكون النطاق نتيجة بحث أو يتم إنشاؤه يدويًا باستخدام newRange().

الإرجاع

NamedRangeNamedRange

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

  • 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.');
}

المعلمات

الاسمالنوعالوصف
idStringتمثّل هذه السمة المعرّف الخاص بـ 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

getFooter()

تعرض هذه الطريقة قسم التذييل لعلامة التبويب، إذا كان متوفّرًا.

// 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 footer and logs it to the console.
console.log(documentTab.getFooter().getText());

الإرجاع

FooterSection|null: تذييل علامة التبويب

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

  • 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.

المعلمات

الاسمالنوعالوصف
idStringمعرّف النطاق، وهو معرّف فريد ضمن علامة التبويب.

الإرجاع

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. لتجنُّب حدوث تعارضات غير مقصودة بين النصوص البرمجية، ننصحك بإضافة بادئة فريدة إلى أسماء النطاقات.

المعلمات

الاسمالنوعالوصف
nameStringاسم النطاق، وهو ليس فريدًا بالضرورة.

الإرجاع

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

المعلمات

الاسمالنوعالوصف
elementElementالعنصر الذي يحتوي على Position الذي تم إنشاؤه حديثًا، ويجب أن يكون إما عنصر Text أو عنصر حاوية مثل Paragraph
offsetIntegerبالنسبة إلى عناصر Text، يمثّل هذا الرقم عدد الأحرف التي تسبق Position، أما بالنسبة إلى العناصر الأخرى، فيمثّل عدد العناصر الثانوية التي تسبق Position ضمن عنصر الحاوية نفسه.

الإرجاع

PositionPosition الجديد

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

  • 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