java.lang.ObjectInternableComplexAttr
com.aspose.words.TabStopCollection
public class TabStopCollection
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 TabStops collection 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. Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Access the collection of tab stops and add some tab stops to it
TabStopCollection tabStops = builder.getParagraphFormat().getTabStops();
// 72 points is one "inch" on the Microsoft Word tab stop ruler
tabStops.add(new TabStop(72.0));
tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES));
Assert.assertEquals(2, tabStops.getCount());
Assert.assertFalse(tabStops.get(0).isClear());
Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1)));
// Every "tab" character takes the builder's cursor to the next tab stop
builder.writeln("Start\tTab 1\tTab 2");
// Get the collection of paragraphs that we've created
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
Assert.assertEquals(2, paragraphs.getCount());
// Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection
Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
// A TabStopCollection can point us to TabStops before and after certain positions
Assert.assertEquals(72.0, tabStops.before(100.0).getPosition());
Assert.assertEquals(432.0, tabStops.after(100.0).getPosition());
// We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour
paragraphs.get(1).getParagraphFormat().getTabStops().clear();
Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount());
doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
Property Getters/Setters Summary | ||
---|---|---|
int | getCount() | |
Gets the number of tab stops in the collection. | ||
TabStop | get(double position) | |
Gets a tab stop at the specified position. | ||
TabStop | get(int index) | |
Gets a tab stop at the given index. |
Method Summary | ||
---|---|---|
void | add(TabStop tabStop) | |
Adds or replaces a tab stop in the collection. | ||
void | add(double position, int alignment, int leader) | |
Adds or replaces a tab stop in the collection. | ||
TabStop | after(double position) | |
Gets a first tab stop to the right of the specified position. | ||
TabStop | before(double position) | |
Gets a first tab stop to the left of the specified position. | ||
void | clear() | |
Deletes all tab stop positions. | ||
boolean | equals(TabStopCollection rhs) | |
Determines whether the specified TabStopCollection is equal in value to the current TabStopCollection. | ||
boolean | equals(java.lang.Object obj) | |
Determines whether the specified object is equal in value to the current object. | ||
int | getIndexByPosition(double position) | |
Gets the index of a tab stop with the specified position in points. | ||
double | getPositionByIndex(int index) | |
Gets the position (in points) of the tab stop at the specified index. | ||
int | hashCode() | |
Serves as a hash function for this type. | ||
void | removeByIndex(int index) | |
Removes a tab stop at the specified index from the collection. | ||
void | removeByPosition(double position) | |
Removes a tab stop at the specified position from the collection. |
Property Getters/Setters Detail |
---|
getCount | |
public int getCount() |
Example:
Shows how to work with a document's collection of tab stops.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.getParagraphFormat().getTabStops(); // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.add(new TabStop(72.0)); tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES)); Assert.assertEquals(2, tabStops.getCount()); Assert.assertFalse(tabStops.get(0).isClear()); Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1))); // Every "tab" character takes the builder's cursor to the next tab stop builder.writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs(); Assert.assertEquals(2, paragraphs.getCount()); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.assertEquals(72.0, tabStops.before(100.0).getPosition()); Assert.assertEquals(432.0, tabStops.after(100.0).getPosition()); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs.get(1).getParagraphFormat().getTabStops().clear(); Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount()); doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
get | |
public TabStop get(double position) |
position
- The position (in points) of the tab stop.Example:
Shows how to work with a document's collection of tab stops.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.getParagraphFormat().getTabStops(); // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.add(new TabStop(72.0)); tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES)); Assert.assertEquals(2, tabStops.getCount()); Assert.assertFalse(tabStops.get(0).isClear()); Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1))); // Every "tab" character takes the builder's cursor to the next tab stop builder.writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs(); Assert.assertEquals(2, paragraphs.getCount()); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.assertEquals(72.0, tabStops.before(100.0).getPosition()); Assert.assertEquals(432.0, tabStops.after(100.0).getPosition()); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs.get(1).getParagraphFormat().getTabStops().clear(); Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount()); doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
get | |
public TabStop get(int index) |
index
- An index into the collection of tab stops.Example:
Shows how to work with a document's collection of tab stops.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.getParagraphFormat().getTabStops(); // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.add(new TabStop(72.0)); tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES)); Assert.assertEquals(2, tabStops.getCount()); Assert.assertFalse(tabStops.get(0).isClear()); Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1))); // Every "tab" character takes the builder's cursor to the next tab stop builder.writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs(); Assert.assertEquals(2, paragraphs.getCount()); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.assertEquals(72.0, tabStops.before(100.0).getPosition()); Assert.assertEquals(432.0, tabStops.after(100.0).getPosition()); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs.get(1).getParagraphFormat().getTabStops().clear(); Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount()); doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
Method Detail |
---|
add | |
public void add(TabStop tabStop) |
If a tab stop already exists at the specified position, it is replaced.
tabStop
- A tab stop object to add.Example:
Shows how to add tab stops to a document and set their positions.Document doc = new Document(); Paragraph paragraph = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true); // Create a TabStop object and add it to the document TabStop tabStop = new TabStop(ConvertUtil.inchToPoint(3.0), TabAlignment.LEFT, TabLeader.DASHES); paragraph.getParagraphFormat().getTabStops().add(tabStop); // Add a tab stop without explicitly creating new TabStop objects paragraph.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(100.0), TabAlignment.LEFT, TabLeader.DASHES); // Add tab stops at 5 cm to all paragraphs for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) { para.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(50.0), TabAlignment.LEFT, TabLeader.DASHES); } // Insert text with tabs that demonstrate the tab stops DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Start\tTab 1\tTab 2\tTab 3\tTab 4"); doc.save(getArtifactsDir() + "TabStopCollection.AddTabStops.docx");
add | |
public void add(double position, int alignment, int leader) |
If a tab stop already exists at the specified position, it is replaced.
position
- A position (in points) where to add the tab stop.alignment
- A leader
- A Example:
Shows how to add tab stops to a document and set their positions.Document doc = new Document(); Paragraph paragraph = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true); // Create a TabStop object and add it to the document TabStop tabStop = new TabStop(ConvertUtil.inchToPoint(3.0), TabAlignment.LEFT, TabLeader.DASHES); paragraph.getParagraphFormat().getTabStops().add(tabStop); // Add a tab stop without explicitly creating new TabStop objects paragraph.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(100.0), TabAlignment.LEFT, TabLeader.DASHES); // Add tab stops at 5 cm to all paragraphs for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) { para.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(50.0), TabAlignment.LEFT, TabLeader.DASHES); } // Insert text with tabs that demonstrate the tab stops DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Start\tTab 1\tTab 2\tTab 3\tTab 4"); doc.save(getArtifactsDir() + "TabStopCollection.AddTabStops.docx");
after | |
public TabStop after(double position) |
Skips tab stops with Alignment set to TabAlignment.Bar
.
position
- The reference position (in points).Example:
Shows how to work with a document's collection of tab stops.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.getParagraphFormat().getTabStops(); // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.add(new TabStop(72.0)); tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES)); Assert.assertEquals(2, tabStops.getCount()); Assert.assertFalse(tabStops.get(0).isClear()); Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1))); // Every "tab" character takes the builder's cursor to the next tab stop builder.writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs(); Assert.assertEquals(2, paragraphs.getCount()); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.assertEquals(72.0, tabStops.before(100.0).getPosition()); Assert.assertEquals(432.0, tabStops.after(100.0).getPosition()); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs.get(1).getParagraphFormat().getTabStops().clear(); Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount()); doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
before | |
public TabStop before(double position) |
Skips tab stops with Alignment set to TabAlignment.Bar
.
position
- The reference position (in points).Example:
Shows how to work with a document's collection of tab stops.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.getParagraphFormat().getTabStops(); // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.add(new TabStop(72.0)); tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES)); Assert.assertEquals(2, tabStops.getCount()); Assert.assertFalse(tabStops.get(0).isClear()); Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1))); // Every "tab" character takes the builder's cursor to the next tab stop builder.writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs(); Assert.assertEquals(2, paragraphs.getCount()); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.assertEquals(72.0, tabStops.before(100.0).getPosition()); Assert.assertEquals(432.0, tabStops.after(100.0).getPosition()); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs.get(1).getParagraphFormat().getTabStops().clear(); Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount()); doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
clear | |
public void clear() |
Example:
Shows how to work with a document's collection of tab stops.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.getParagraphFormat().getTabStops(); // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.add(new TabStop(72.0)); tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES)); Assert.assertEquals(2, tabStops.getCount()); Assert.assertFalse(tabStops.get(0).isClear()); Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1))); // Every "tab" character takes the builder's cursor to the next tab stop builder.writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs(); Assert.assertEquals(2, paragraphs.getCount()); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.assertEquals(72.0, tabStops.before(100.0).getPosition()); Assert.assertEquals(432.0, tabStops.after(100.0).getPosition()); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs.get(1).getParagraphFormat().getTabStops().clear(); Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount()); doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
equals | |
public boolean equals(TabStopCollection rhs) |
Example:
Shows how to work with a document's collection of tab stops.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.getParagraphFormat().getTabStops(); // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.add(new TabStop(72.0)); tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES)); Assert.assertEquals(2, tabStops.getCount()); Assert.assertFalse(tabStops.get(0).isClear()); Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1))); // Every "tab" character takes the builder's cursor to the next tab stop builder.writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs(); Assert.assertEquals(2, paragraphs.getCount()); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.assertEquals(72.0, tabStops.before(100.0).getPosition()); Assert.assertEquals(432.0, tabStops.after(100.0).getPosition()); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs.get(1).getParagraphFormat().getTabStops().clear(); Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount()); doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
equals | |
public boolean equals(java.lang.Object obj) |
Example:
Shows how to work with a document's collection of tab stops.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.getParagraphFormat().getTabStops(); // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.add(new TabStop(72.0)); tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES)); Assert.assertEquals(2, tabStops.getCount()); Assert.assertFalse(tabStops.get(0).isClear()); Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1))); // Every "tab" character takes the builder's cursor to the next tab stop builder.writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs(); Assert.assertEquals(2, paragraphs.getCount()); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.assertEquals(72.0, tabStops.before(100.0).getPosition()); Assert.assertEquals(432.0, tabStops.after(100.0).getPosition()); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs.get(1).getParagraphFormat().getTabStops().clear(); Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount()); doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
getIndexByPosition | |
public int getIndexByPosition(double position) |
Example:
Shows how to look up a position to see if a tab stop exists there, and if so, obtain its index.Document doc = new Document(); TabStopCollection tabStops = doc.getFirstSection().getBody().getParagraphs().get(0).getParagraphFormat().getTabStops(); // Add a tab stop at a position of 30mm tabStops.add(ConvertUtil.millimeterToPoint(30.0), TabAlignment.LEFT, TabLeader.DASHES); // "0" confirms that a tab stop at 30mm exists in this collection, and it is at index 0 Assert.assertEquals(0, tabStops.getIndexByPosition(ConvertUtil.millimeterToPoint(30.0))); // "-1" means that there is no tab stop in this collection with a position of 60mm Assert.assertEquals(-1, tabStops.getIndexByPosition(ConvertUtil.millimeterToPoint(60.0)));
getPositionByIndex | |
public double getPositionByIndex(int index) |
index
- An index into the collection of tab stops.Example:
Shows how to find a tab stop by it's index and get its position.Document doc = new Document(); TabStopCollection tabStops = doc.getFirstSection().getBody().getParagraphs().get(0).getParagraphFormat().getTabStops(); tabStops.add(ConvertUtil.millimeterToPoint(30.0), TabAlignment.LEFT, TabLeader.DASHES); tabStops.add(ConvertUtil.millimeterToPoint(60.0), TabAlignment.LEFT, TabLeader.DASHES); // Get the position of the second tab stop in the collection Assert.assertEquals(ConvertUtil.millimeterToPoint(60.0), tabStops.getPositionByIndex(1), 0.1d);
hashCode | |
public int hashCode() |
Example:
Shows how to work with a document's collection of tab stops.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.getParagraphFormat().getTabStops(); // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.add(new TabStop(72.0)); tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES)); Assert.assertEquals(2, tabStops.getCount()); Assert.assertFalse(tabStops.get(0).isClear()); Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1))); // Every "tab" character takes the builder's cursor to the next tab stop builder.writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs(); Assert.assertEquals(2, paragraphs.getCount()); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.assertEquals(72.0, tabStops.before(100.0).getPosition()); Assert.assertEquals(432.0, tabStops.after(100.0).getPosition()); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs.get(1).getParagraphFormat().getTabStops().clear(); Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount()); doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
removeByIndex | |
public void removeByIndex(int index) |
index
- An index into the collection of tab stops.Example:
Shows how to select a tab stop in a document by its index and remove it.Document doc = new Document(); TabStopCollection tabStops = doc.getFirstSection().getBody().getParagraphs().get(0).getParagraphFormat().getTabStops(); tabStops.add(ConvertUtil.millimeterToPoint(30.0), TabAlignment.LEFT, TabLeader.DASHES); tabStops.add(ConvertUtil.millimeterToPoint(60.0), TabAlignment.LEFT, TabLeader.DASHES); Assert.assertEquals(2, tabStops.getCount()); // Tab stop placed at 30 mm is removed tabStops.removeByIndex(0); Assert.assertEquals(1, tabStops.getCount()); doc.save(getArtifactsDir() + "TabStopCollection.RemoveByIndex.docx");
removeByPosition | |
public void removeByPosition(double position) |
position
- The position (in points) of the tab stop to remove.Example:
Shows how to modify the position of the right tab stop in TOC related paragraphs.Document doc = new Document(getMyDir() + "Table of contents.docx"); // Iterate through all paragraphs formatted using the TOC result based styles; this is any style between TOC and TOC9 for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) { if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1 && para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) { // Get the first tab used in this paragraph, this should be the tab used to align the page numbers TabStop tab = para.getParagraphFormat().getTabStops().get(0); // Remove the old tab from the collection para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition()); // Insert a new tab using the same properties but at a modified position // We could also change the separators used (dots) by passing a different Leader type para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50, tab.getAlignment(), tab.getLeader()); } } doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");