Providing custom number

Hi,
creating a document with no.of paragraphs and applying different styles, but i need to provide Custom number to the paragraph like,
3. Paragraph1
3.1 Paragraph1.1

Is there any method to to provide custom number…like above i provided 3
Regards,
Srinu Dhulipalla

Hi

Thanks for your inquiry. List numbers are calculated on fly. You can specify format of numbers of each level and start number of each level. Please see the following links for more information:
https://reference.aspose.com/words/net/aspose.words.lists/listlevel/numberformat/
https://reference.aspose.com/words/net/aspose.words.lists/listlevel/startat/
Hope this helps.
Best regards.

Hi Alexey,
Thank you for providing needful information. I tried in different ways to providing the custom number to the paragraph having heading style, i am able to providing the number to normal paragraphs but not heading style paragraphs.
pls see my attached document containing only one paragraph with Heading1 style and Intend number starts at 1, i changed that intend number to 3 with the code like,

Aspose.Words.Lists.List list = mainSec.Lists.Add(Aspose.Words.Lists.ListTemplate.NumberDefault);
Aspose.Words.Lists.ListLevel level1 = list.ListLevels[0];
level1.StartAt = 3;

but it’s remains 1, let me know how to provide the custom number to the Heading style paragraphs,
If suppose the paragraph of the attached document containing Heading2 style, then how should i provide number to 3.5
This could be need to us, to provide limited and perticular info to our clients. pls provide me the sample code to give custom number to Heading style paragraphs.
Regards,
Srinu Dhulipalla

Hi Srinu,

Thank you for additional information. In your case you do not need to create new list. You should just change formatting of Heading1 list level as shown in the code below.

// Open document
Document doc = new Document(@"Test077\Aspose.doc");
// Specify startign number of Heading 1
if (doc.Styles[StyleIdentifier.Heading1].ListFormat != null)
    doc.Styles[StyleIdentifier.Heading1].ListFormat.ListLevel.StartAt = 3;
// Save output document
doc.Save(@"Test077\out.doc");

Hope this helps.
Best regards.

Hi Alexey,
Thank you for providing extra needful information. That’s great! what you are providing above is reaching to my requirement.
but i may not always provide Heading1 information to our clients, some times it should be Heading2 or Heading3. If i am providing code like,

// Specify startign number of Heading 2
if (doc.Styles[StyleIdentifier.Heading2].ListFormat != null)
    doc.Styles[StyleIdentifier.Heading2].ListFormat.ListLevel.StartAt = 3.5;

It will throw an error, bcoz StartAt property will take only Integers, Is there any other way to provide float numbers like 3.1 or 3.5, …
See my attached document it contains only one paragraph with Heading2 style and intend number is 1.1
How should i change intend number to 3.5 insted of 1.1?
Regards,
Srinu Dhulipalla

Hi

In this case, you just should do the following:

// Specify starting number of Heading 1
if (doc.Styles[StyleIdentifier.Heading1].ListFormat != null)
    doc.Styles[StyleIdentifier.Heading1].ListFormat.ListLevel.StartAt = 3;
// Specify starting number of Heading 2
if (doc.Styles[StyleIdentifier.Heading2].ListFormat != null)
    doc.Styles[StyleIdentifier.Heading2].ListFormat.ListLevel.StartAt = 5;

Best regards.

Hi Alexey,
We are facing some problems while providing custom numbers to Heading style paragraphs if we are follwing above things,
It is fine when i am proving custiom number, if the document is having only one Heading1 style paragraph, but if document having morethan one Heading1 style paragraphs, it is failing order of numbering at 2nd level… I used the code like this,

// strStartNos (first time it is 3, second time it is 9)
if (docSecItem.Styles[StyleIdentifier.Heading1].ListFormat != null)
    docSecItem.Styles[StyleIdentifier.Heading1].ListFormat.ListLevel.StartAt = Convert.ToInt32(strStartNos[0]);
if (docSecItem.Styles[StyleIdentifier.Heading2].ListFormat != null)
    docSecItem.Styles[StyleIdentifier.Heading2].ListFormat.ListLevel.StartAt = Convert.ToInt32(strStartNos[1]);
AppendDoc(mainSec, docSecItem, true, "noAttachments");
// Append Document 
void AppendDoc(Document dstDoc, Document srcDoc, bool remove, string attach)
{
    try
    {
        foreach(Section srcSection in srcDoc)
        {
            Node dstSection;
            if (isSectionOnly)
                dstSection = dstDoc.ImportNode(srcSection, true, ImportFormatMode.KeepSourceFormatting);
            else
                dstSection = dstDoc.ImportNode(srcSection, true, ImportFormatMode.UseDestinationStyles);
            dstDoc.Sections.Add(dstSection);
        }
        if (attach == "")
        {
            DocumentBuilder bdoc = new DocumentBuilder(dstDoc);
            bdoc.MoveToSection(-1);
            bdoc.MoveToParagraph(-1, 0);
            bdoc.CurrentParagraph.Remove();
        }
    }
    builderMainSec.MoveToSection(-1);
    builderMainSec.MoveToParagraph(0, 0);
    SetLevel(level); // here im providing level of heading like

( case 0: builderMainSec.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;, …)
pls see the attached document, the order of the numbering is fails, It is showing 3.3, but it should be 9.1 let me know is there any other way to provide proper order of numbering…

Hi

Thanks for your request. If you need custom numbers, you can try to insert them as simple text at the beginning of the paragraph, instead of using list numbers.
Best regards.

Hi Alexey,
I tried that one also, but they are not appearing in the table of contents…
So please help me out to resolve that one…
Regards,
Srinu dhulipalla

Hi

Thanks for your inquiry. I think that you can use TC fields (TOC entry). Please see the following link:
https://forum.aspose.com/t/113410
Best regards.

Hi Alexey,

Thank you for your help,

my word template having TOC fileds, but when i am providing custom number before the paragraph, it is not appearing in the paragraph… bcoz they are not the heading styles.

So im using Heading list to provide the custom number to Heading style paragraph… but at 2nd level it is showing false info (order of serial no is wrong),

pls look at the my attached documet ( in my previos reply i atached)… It is not following order at TOC…
pls help me out to provide better document report to our clients.

Regards,
Srinu Dhulipalla

Hi

Thanks for your request. There is few ways to resolve your issue.

  1. You can use simple text instead list labels to insert custom numbers. Here is simple code you can use:
// Open document
Document doc = new Document(@"Test077\Aspose.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// insert headign1 text
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
if (builder.ListFormat != null)
{
    // remove numbering
    builder.ListFormat.RemoveNumbers();
}
// insert necessary number at the beggining of the paragraph
builder.Writeln("4. This is my heading item");
// Save output document
doc.Save(@"Test077\out.doc");
  1. You can use list labels, but if you need to specify custom numbers to each item, then each item should be belong to different lists, because numbering within list is continuous. This approach is much harder. Here is snippet of code:
// Open document
Document doc = new Document(@"Test077\Aspose.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// insert headign1 text
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
if (builder.ListFormat != null)
{
    // clone list
    List newList = doc.Lists.AddCopy(builder.ListFormat.List);
    builder.ListFormat.List = newList;
    // Specify numbers
    newList.ListLevels[0].StartAt = 4;
    newList.ListLevels[1].StartAt = 8;
}
// insert necessary number at the beggining of the paragraph
builder.Writeln("This is my heading 2 item");
// Save output document
doc.Save(@"Test077\out.doc");

Hope this helps.
Best regards.