Free Support Forum - aspose.com

How to set the tab postion of Table os contents

Hi,

How can we set the Tab postion of table of contents TOC1 and TOC2 and TOC 3 from coding.

testdoc.Styles[StyleIdentifier.Toc2].ParagraphFormat.TabStops.Before =doc.Styles[StyleIdentifier.Toc2].ParagraphFormat.TabStops.Before;

Here I am attaching the image for reference.

Please give me response as early as possible .

Thanks,

Sailaja.

Hi,

Please help me to fix this tabposition of Table of contents.I need to submit my application to client.If you send the respone as early as possible then it will be very helpful to me.

Thanks,Sailaja.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Sorry for delay. Please try using the following code snippet.

public void Test026()

{

Document srcDoc = new Document(@"Test026\MS PROP_Part (1).doc");

Document doc = new Document();

ImportStyle(doc.Styles[StyleIdentifier.Toc1], srcDoc.Styles[StyleIdentifier.Toc1]);

ImportStyle(doc.Styles[StyleIdentifier.Toc2], srcDoc.Styles[StyleIdentifier.Toc2]);

ImportStyle(doc.Styles[StyleIdentifier.Toc3], srcDoc.Styles[StyleIdentifier.Toc3]);

DocumentBuilder builder = new DocumentBuilder(doc);

// Insrt a table of contents at the beginning of the document.

builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");

// Build a document with complex structure by applying different heading styles thus creating TOC entries.

// ……………………………………………………………….

doc.Save(@"Test026\out.doc");

}

private void ImportStyle(Style dstStyle, Style srcStyle)

{

dstStyle.Font.Name = srcStyle.Font.Name;

dstStyle.Font.Bold = srcStyle.Font.Bold;

dstStyle.Font.Size = srcStyle.Font.Size;

dstStyle.Font.AllCaps = srcStyle.Font.AllCaps;

dstStyle.ParagraphFormat.Alignment = srcStyle.ParagraphFormat.Alignment;

dstStyle.ParagraphFormat.LineSpacing = srcStyle.ParagraphFormat.LineSpacing;

dstStyle.ParagraphFormat.SpaceAfter = srcStyle.ParagraphFormat.SpaceAfter;

dstStyle.ParagraphFormat.SpaceBefore = srcStyle.ParagraphFormat.SpaceBefore;

dstStyle.ParagraphFormat.LeftIndent = srcStyle.ParagraphFormat.LeftIndent;

dstStyle.ParagraphFormat.RightIndent = srcStyle.ParagraphFormat.RightIndent;

dstStyle.ParagraphFormat.FirstLineIndent = srcStyle.ParagraphFormat.FirstLineIndent;

dstStyle.ParagraphFormat.LineSpacingRule = srcStyle.ParagraphFormat.LineSpacingRule;

dstStyle.ParagraphFormat.OutlineLevel = srcStyle.ParagraphFormat.OutlineLevel;

dstStyle.ParagraphFormat.SpaceAfterAuto = srcStyle.ParagraphFormat.SpaceAfterAuto;

dstStyle.ParagraphFormat.SpaceBeforeAuto = srcStyle.ParagraphFormat.SpaceBeforeAuto;

dstStyle.ParagraphFormat.TabStops.Clear();

for (int i = 0; i < srcStyle.ParagraphFormat.TabStops.Count; i++)

{

dstStyle.ParagraphFormat.TabStops.Add(srcStyle.ParagraphFormat.TabStops[i]);

}

}

I hope this could help you.

Best regards.