TabStopCollection class
TabStopCollection class
A collection of TabStop objects that represent custom tabs for a paragraph or a style. To learn more, visit the Aspose.Words Document Object Model (DOM) documentation article.
Remarks
In Microsoft Word documents, a tab stop can be defined in the properties of a paragraph style or directly in the properties of a paragraph. A style can be based on another style. Therefore, the complete set of tab stops for a given object is a combination of tab stops defined directly on this object and tab stops inherited from the parent styles.
In Aspose.Words, when you obtain a TabStopCollection for a paragraph or a style, it contains only the custom tab stops defined directly for this paragraph or style. The collection does not include tab stops defined in the parent styles or default tab stops.
Inheritance: TabStopCollection → InternableComplexAttr
Indexers
Name | Description |
---|---|
__getitem__(index) | Gets a tab stop at the given index. |
Properties
Name | Description |
---|---|
count | Gets the number of tab stops in the collection. |
Methods
Name | Description |
---|---|
add(tab_stop) | Adds or replaces a tab stop in the collection. |
add(position, alignment, leader) | Adds or replaces a tab stop in the collection. |
after(position) | Gets a first tab stop to the right of the specified position. |
before(position) | Gets a first tab stop to the left of the specified position. |
clear() | Deletes all tab stop positions. |
equals(rhs) | Determines whether the specified TabStopCollection is equal in value to the current TabStopCollection. |
get_index_by_position(position) | Gets the index of a tab stop with the specified position in points. |
get_position_by_index(index) | Gets the position (in points) of the tab stop at the specified index. |
remove_by_index(index) | Removes a tab stop at the specified index from the collection. |
remove_by_position(position) | Removes a tab stop at the specified position from the collection. |
Examples
Shows how to work with a document’s collection of tab stops.
doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
tab_stops = builder.paragraph_format.tab_stops
# 72 points is one "inch" on the Microsoft Word tab stop ruler.
tab_stops.add(tab_stop=aw.TabStop(position=72))
tab_stops.add(tab_stop=aw.TabStop(position=432, alignment=aw.TabAlignment.RIGHT, leader=aw.TabLeader.DASHES))
self.assertEqual(2, tab_stops.count)
self.assertFalse(tab_stops[0].is_clear)
self.assertFalse(tab_stops[0].equals(tab_stops[1]))
# Every "tab" character takes the builder's cursor to the location of the next tab stop.
builder.writeln('Start\tTab 1\tTab 2')
paragraphs = doc.first_section.body.paragraphs
self.assertEqual(2, paragraphs.count)
# Each paragraph gets its tab stop collection, which clones its values from the document builder's tab stop collection.
self.assertEqual(paragraphs[0].paragraph_format.tab_stops, paragraphs[1].paragraph_format.tab_stops)
# A tab stop collection can point us to TabStops before and after certain positions.
self.assertEqual(72, tab_stops.before(100).position)
self.assertEqual(432, tab_stops.after(100).position)
# We can clear a paragraph's tab stop collection to revert to the default tabbing behavior.
paragraphs[1].paragraph_format.tab_stops.clear()
self.assertEqual(0, paragraphs[1].paragraph_format.tab_stops.count)
doc.save(file_name=ARTIFACTS_DIR + 'TabStopCollection.TabStopCollection.docx')
See Also
- module aspose.words
- class InternableComplexAttr
- class ParagraphFormat
- class TabStop
- property Document.default_tab_stop