Free Support Forum - aspose.com

How According to the second-level heading Automatic numbering of table is 1 ro 2 or 3 and so on x.x-1

I have document is:

1 title1

1.1 title1.1

there is table

1.2 title1.2

there is table

2 title

2.1title 2.1

there is table

2.2 title 2.2

there is table

2.2.1 title 2.2.1

there is table

how According to the second-level heading Automatic numbering of table is 1 ro 2 or 3 and so on x.x-1how According to the second-level heading Automatic numbering of table is 1 ro 2 or 3 and so on x.x-1

I want get this document ,number of table is x.x-1,x.x-2 type

1 title1

1.1 title1.1

there is table(1.1-1)

1.2 title1.2

there is table(1.1-2)

2 title

2.1title 2.1

there is table(2.1-1)

2.2 title 2.2

there is table(2.2-1)

2.2.1 title 2.2.1

there is table(2.2-2)

Hi,


Thanks for your inquiry. Unfortunately, I have not completely understood your query. Could you please create a MS Word document with your shared scenario and attach here? I will check the scenario and will share the code accordingly.

I already updata test file,I wanted to AutoNumber a table caption(Such forms x.x-1,x.x-2), in accordance with head 2

Sorry for the confussion!

To be clear, my document is formated like this:

1 title1
1.1 title 1.1
“original table 1”
"original talbe 2"
1.2 title 1.2
"original table 3"
2 title2
2.1 title 2.1
"original table 4"
2.2 title 2.2
"original table 5"
2.2.1 title 2.2.1
"original table 6"

What I really want to do is to associate these table captions with their sub-level(limit to 2 sub levels) numbers and the table numbers, such as:

1 title1
1.1 title 1.1
“table 1.1-1
"table 1.1-2"
1.2 title 1.2
"table 1.2-1"
2 title2
2.1 title 2.1
"table 2.1-1"
2.2 title 2.2
"table 2.2-1"
2.2.1 title 2.2.1
"table 2.2-2"

The highlighted numbers are table numbers.

Please help!
Thank you!

Hi,


Thanks for the additional information. We are checking with this scenario and will get back to you soon.

help me,thanks.

Hi,


Please accept my apologies for late response.

I have worked with your source document and have written the following code snippet. This code snippet add caption of each table according to list format. You may modify this code according to your requirements. Please check the highlighted section of code. I have attached the output document with this post. Hope this helps you. Please let us know if you have any more queries.


<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:
0pt;mso-no-proof:yes”>Document<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> doc = new Document(MyDir

  • “TableTestSource.docx”);<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

doc.UpdateListLabels();

Node[] tables = doc.GetChildNodes(NodeType.Table, true).ToArray();

for (int i = 0; i < tables.Length; i++)

{

Node currentNode = tables[i];

Paragraph para = null;

//Get Previous paragraph of table which is without list format

if (currentNode.PreviousPreOrder(doc).NodeType == NodeType.Paragraph)

para = (Paragraph)currentNode.PreviousPreOrder(doc);

currentNode = currentNode.PreviousPreOrder(doc);

if (currentNode.NodeType == NodeType.Paragraph)

{

//Get list format paragraph like 1.1. etc

while (true)

{

if (currentNode.NodeType == NodeType.Paragraph && ((Paragraph)currentNode).IsListItem == true)

break;

currentNode = currentNode.PreviousPreOrder(doc);

}

ListLabel label = ((Paragraph)currentNode).ListLabel;

String strCaption = label.LabelString;

strCaption += " Text Added";

Run run = new Run(doc, strCaption);

run.Font.Bold = true;

para.AppendChild(run);

}

}

doc.Save(MyDir + "AsposeOut.docx");

that work not good.
1、currentNode.PreviousPreOrder(doc).NodeType can not return paragraph ,return is run type
2、I use currentNode.PreviousSibling,this can return paragraph
3、how can insert paragraph after original paragraph?I want this style
2.1 test2.1
test document.
2.1-1 table-1
"this table"

Hi,


Thanks for your inquiry. Yes, the PreviousSibling property works correctly in your scenario. Please use the following code snippet to insert paragraph after specific paragraph with same font of previous paragraph.
http://www.aspose.com/docs/display/wordsnet/MoveToParagraph+Method

<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:
0pt;mso-no-proof:yes”>Document<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> doc = new Document(MyDir

  • “TableTestSource.docx”);<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

doc.UpdateListLabels();

builder.MoveToParagraph(2, 0);

Aspose.Words.Font font = ((Paragraph)builder.CurrentParagraph.PreviousSibling).Runs[0].Font;

Paragraph para = builder.InsertParagraph();

Run run = new Run(doc, "some text");

run.Font.Name = font.Name;

run.Font.Size = font.Size;

para.AppendChild(run);



Following example shows how to insert a paragraph into the document.


Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// Specify font formatting

Aspose.Words.Font font = builder.Font;

font.Size = 16;

font.Bold = true;

font.Color = System.Drawing.Color.Blue;

font.Name = "Arial";

font.Underline = Underline.Dash;

// Specify paragraph formatting

ParagraphFormat paragraphFormat = builder.ParagraphFormat;

paragraphFormat.FirstLineIndent = 8;

paragraphFormat.Alignment = ParagraphAlignment.Justify;

paragraphFormat.KeepTogether = true;

builder.Writeln("A whole paragraph.");


I suggest you to read following documentation links for your kind reference.
http://www.aspose.com/docs/display/wordsnet/ParagraphFormat+Class
http://www.aspose.com/docs/display/wordsnet/Style+Class
http://www.aspose.com/docs/display/wordsnet/Accessing+Styles