TabStopCollection
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.
public class TabStopCollection : InternableComplexAttr
Properties
Name | Description |
---|---|
Count { get; } | Gets the number of tab stops in the collection. |
Item { get; } | Gets a tab stop at the given index. (2 indexers) |
Methods
Name | Description |
---|---|
Add(TabStop) | Adds or replaces a tab stop in the collection. |
Add(double, TabAlignment, TabLeader) | Adds or replaces a tab stop in the collection. |
After(double) | Gets a first tab stop to the right of the specified position. |
Before(double) | Gets a first tab stop to the left of the specified position. |
Clear() | Deletes all tab stop positions. |
override Equals(object) | Determines whether the specified object is equal in value to the current object. |
Equals(TabStopCollection) | Determines whether the specified TabStopCollection is equal in value to the current TabStopCollection . |
override GetHashCode() | Serves as a hash function for this type. |
GetIndexByPosition(double) | Gets the index of a tab stop with the specified position in points. |
GetPositionByIndex(int) | Gets the position (in points) of the tab stop at the specified index. |
RemoveByIndex(int) | Removes a tab stop at the specified index from the collection. |
RemoveByPosition(double) | Removes a tab stop at the specified position from the collection. |
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.
Examples
Shows how to work with a document’s collection of tab stops.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
TabStopCollection tabStops = builder.ParagraphFormat.TabStops;
// 72 points is one "inch" on the Microsoft Word tab stop ruler.
tabStops.Add(new TabStop(72.0));
tabStops.Add(new TabStop(432.0, TabAlignment.Right, TabLeader.Dashes));
Assert.AreEqual(2, tabStops.Count);
Assert.IsFalse(tabStops[0].IsClear);
Assert.IsFalse(tabStops[0].Equals(tabStops[1]));
// Every "tab" character takes the builder's cursor to the location of the next tab stop.
builder.Writeln("Start\tTab 1\tTab 2");
ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs;
Assert.AreEqual(2, paragraphs.Count);
// Each paragraph gets its tab stop collection, which clones its values from the document builder's tab stop collection.
Assert.AreEqual(paragraphs[0].ParagraphFormat.TabStops, paragraphs[1].ParagraphFormat.TabStops);
Assert.AreNotSame(paragraphs[0].ParagraphFormat.TabStops, paragraphs[1].ParagraphFormat.TabStops);
// A tab stop collection can point us to TabStops before and after certain positions.
Assert.AreEqual(72.0, tabStops.Before(100.0).Position);
Assert.AreEqual(432.0, tabStops.After(100.0).Position);
// We can clear a paragraph's tab stop collection to revert to the default tabbing behavior.
paragraphs[1].ParagraphFormat.TabStops.Clear();
Assert.AreEqual(0, paragraphs[1].ParagraphFormat.TabStops.Count);
doc.Save(ArtifactsDir + "TabStopCollection.TabStopCollection.docx");
See Also
- class InternableComplexAttr
- namespace Aspose.Words
- assembly Aspose.Words