@alexey.noskov hi sir , in word document how to check the position of tab stops of left alignment and right alignment tab stops can you please give me a clarity , i want to check left tab with 0" and right alignment with 6.5".( by clicking header we are getting tab key symbols of L and reverse T and revrese L am talking about these tab keys) how to check these tab key positions ? please provide some info about this.
@srinu12 You can use ParagraphFormat.TabStops property to get tab stops of the concrete paragraph.
Also document has a default tab stop, which cab be accessed using Document.DefaultTabStop property.
@alexey.noskov I want to know the position of tab key stops exact is it int or string how to get the position can you please provide code for one tab stop position .
@srinu12 Unfortunately, your question is not clear enough. Could you please elaborate it and provide sample document and screen shot that will show what value you would like to get.
The examples provided in the documentation shows how to work with TabStops in the document:
expected.docx (20.0 KB)
Hai sir, am attaching source and expected output for table insert captions, I want to insert table sequnce by using related heading 1 style section.am using below code but am getting bookmark not found error.insert-caption.PNG (16.9 KB)
source.docx (19.2 KB)
foreach (Field field in doc.Range.Fields)
{
if (field.Type == FieldType.FieldSequence && field.Start.ParentParagraph.GetText().ToUpper().StartsWith("TABLE") && field.GetFieldCode().Trim() != "SEQ Table \\* alphabetic")
{
Run r = ((Run)field.Start.NextSibling);
while (r.NextSibling.NodeType == NodeType.Run)
r.NextSibling.Remove();
r.Text = " STYLEREF 1 \\s " + "." + " SEQ Table \\* alphabetic \\s 1 ";
}
}
doc.UpdateFields();
doc.Save("D:\\expected_out.docx");
@srinu12 In your case you should use DocumentBuilder.InsertField method to insert STYLEREF and SEQ fields to builder the required table captions. For example see the following code:
Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get SEQ fields with Table identifier.
List<FieldSeq> seqFields = doc.Range.Fields.Where(f => f.Type == FieldType.FieldSequence).Cast<FieldSeq>()
.Where(f => f.SequenceIdentifier == "Table").ToList();
foreach (FieldSeq f in seqFields)
{
// Check whether containing paragraph starts with TABLE.
Paragraph p = f.Start.ParentParagraph;
if (p.ToString(SaveFormat.Text).ToUpper().StartsWith("TABLE"))
{
// Insert STYLEREF and SEQ fields.
builder.MoveToField(f, true);
builder.InsertField(@"STYLEREF 1 \s");
builder.Write(".");
builder.InsertField(@"SEQ Table \* alphabetic \s 1");
// Remove the original SEQ field.
f.Remove();
}
}
doc.UpdateFields();
doc.Save(@"C:\Temp\out.docx");
Hi sir, Thank you so much for your response ,sir one more doubt in above code if i have para like “Table 3.2.P-1. table para” 1 is the sequence number i need to remove 3.2.P-(before sequence number ,Table and one tab key i want (Table tab key and above mentioned heading and alphabet)) mainly i want replace with 3.2.P- is Tab key(not only 3.2.P- if any text there i should replace with tab key) please help for this
@srinu12 The code fully depends on your document. So please attach your input and expected output documents. We will check them and provide you a solution.
The text you need to remove can be represented by simple text or by fields or by combination of both. So without your input document it is difficult to provide you a solution.
On your side you can use DocumentExplorer demo project to explore document’s node structure. You can get this demo from our GitHub.