@k.sukumar You can use code like this to change tab stop position in the Toc1 style:
Document doc = new Document(@"C:\Temp\in.docx");
Style toc1 = doc.Styles[StyleIdentifier.Toc1];
TabStop stop = toc1.ParagraphFormat.TabStops[0];
toc1.ParagraphFormat.TabStops.Clear();
toc1.ParagraphFormat.TabStops.Add(ConvertUtil.MillimeterToPoint(7.6), stop.Alignment, stop.Leader);
doc.Save(@"C:\Temp\out.docx");
Thank you so much @alexey.noskov.
i have one more doubt what if have more paragraphs with toc1 here you have mentioned toc[0] it means we are take only first one what iam about remaining paragraphs thats the major issue iam facing
@k.sukumar In the code example style is modified so the changes will affect all the paragraphs the modified style is applied to. Also, as you might note all tab stops are cleared and one tab stop is added. So in the resulting modified style there will be only one tab stop.
Thank you @alexey.noskov i understand now
1 Like
Hi @alexey.noskov,
iam facing issue regarding heading 1 , heading 2, heading 3, heading 4, etc so on styles …iam trying to access numbering property in that we have 8 styles … will you help me how to use that 8 styles . what code i need to write to use this styles and need to this styles to this document which i have attached… And moreover i have attached screenshot of what style am searching for … plz help meCapture.aspose.JPG (114.4 KB)
O-3.2.P.8.1-Stability-Summary-and-Conclusion.docx (41.5 KB)
@k.sukumar You can access the heading styles using the appropriate style identifier. For example see the following code:
Style heading1 = doc.Styles[StyleIdentifier.Heading1];
If you need to get paragraphs the heading style is applied to, you can use code like this:
List<Paragraph> heading1Paragraphs = doc.GetChildNodes(NodeType.Paragraph, true)
.Cast<Paragraph>().Where(p => p.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1).ToList();
Hi @alexey.noskov, thank you alexey but i want to change that numbering styles also which is there in screenshot . can you please him
@k.sukumar You can remove numbering in heading paragraph using code like this:
Document doc = new Document(@"C:\Temp\in.docx");
List<Paragraph> heading1Paragraphs = doc.GetChildNodes(NodeType.Paragraph, true)
.Cast<Paragraph>().Where(p => p.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1).ToList();
foreach (Paragraph heading in heading1Paragraphs)
heading.ListFormat.RemoveNumbers();
doc.Save(@"C:\Temp\out.docx");
Please see our documentation to learn more how to work with lists.
Hi @alexey.noskov,
iam facing issue with left tab postion as well as right tab postion … this is the code i have used
if (chLst[k].Check_Name == "Left Tab Position")
{
List<int> lst = new List<int>();
string lefttabposition = string.Empty;
for (int i = 0; i < doc.PageCount; i++)
{
TabStopCollection kk = toc1.ParagraphFormat.TabStops;
if (kk.Count > 0)
{
for (int j = 0; j < kk.Count; j++)
{
if (kk[j].Alignment == TabAlignment.Left)
{
flag = true;
if (kk[j].Position != Convert.ToDouble(chLst[k].Check_Parameter) * 12)
{
lst.Add(j);
flag = true;
}
}
}
please check the document i have attached . in this doc there is toc1 style text is there for that toc1 text i want o apply left tab position … above code i have used but iam unable to change that left tSource_3.2.P.3.1 Manufacturer(s)-blank rows after section break.docx (42.1 KB)
ab or right tab …help me regarding this issuetocstyleeeeedoc.JPG (48.2 KB)
@k.sukumar If you need to change tabstop position, you can use code like this:
private void UpdateTocStyles(Document doc)
{
// List of all TOC styles.
StyleIdentifier[] tocStyles = new StyleIdentifier[]
{
StyleIdentifier.Toc1,
StyleIdentifier.Toc2,
StyleIdentifier.Toc3,
StyleIdentifier.Toc4,
StyleIdentifier.Toc5,
StyleIdentifier.Toc6,
StyleIdentifier.Toc7,
StyleIdentifier.Toc8,
StyleIdentifier.Toc9
};
// Calculate width of the page without left and right margins.
double pageWidth = doc.FirstSection.PageSetup.PageWidth - doc.FirstSection.PageSetup.RightMargin - doc.FirstSection.PageSetup.LeftMargin;
// Reset tab stops in TOC styles.
foreach (StyleIdentifier tocStyleIdentifier in tocStyles)
{
Style tocStyle = doc.Styles[tocStyleIdentifier];
tocStyle.ParagraphFormat.TabStops.Clear();
tocStyle.ParagraphFormat.TabStops.Add(new TabStop(pageWidth, TabAlignment.Right, TabLeader.Dots));
}
}