Free Support Forum - aspose.com

How can get number in list item

how can get number in list item?like function doc.Sections[0].Range.ListFormat.ConvertNumbersToText(); in word. I have a text:1 and 1.1 is list,I use paragraph.listlabel,can not get number in list,and 11.7 can not find ListLabelsExtractor

1
Test1<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>

1.1
Test1.1<o:p></o:p>

I want convert 1 and 1.1 from the list to a character of paragraph,like function doc.Sections[0].Range.ListFormat.ConvertNumbersToText(); I want get 1 and 1.1,can you give a code?

Emergency help

Hi,


Thanks for your request. First of all, you can use ListLevel.NumberFormat property to get format of the list number:
http://www.aspose.com/docs/display/wordsnet/NumberFormat+Property

Also, if you need to simply get the list number, you can achieve this using ListLabel as described here:
http://www.aspose.com/docs/display/wordsnet/ListLabel+Class

Please let me know if I can be of any further assistance.

Best Regadrs,
I open the document with this code:
doca= new Aspose.Words.Document(@"c:\1.docx");
Aspose.Words.Lists.List list1 = doca.Lists.Add(Aspose.Words.Lists.ListTemplate.OutlineLegal);
// Modify the formatting of the list.
list1.ListLevels[0].NumberFormat = "%1 ";
list1.ListLevels[1].NumberFormat = "%1.%2 ";
list1.ListLevels[2].NumberFormat = "%1.%2.%3 ";
list1.ListLevels[3].NumberFormat = "%1.%2.%3.%4 ";

foreach (Aspose.Words.Paragraph p in doca.Sections[0].Body.Paragraphs)
{

p.ListFormat.List = list1;
p.ListFormat.ListLevelNumber = 0;

}
then get this document:
1 test1
2 test2
p.ListFormat.ListLevel.NumberFormat return "%1",p.ListLabel return "",but I want get "1" and convert list number 1 to text 1,?like function doc.Sections[0].Range.ListFormat.ConvertNumbersToText() in word.
Hi,

Thanks for your inquiry.

Please attach your input Word document (1.docx) and target Word document here for our reference. I will investigate as to how you are expecting your final document to be generated like. You can use Microsoft Word to create your target Word document. I will then provide you code to achieve the same by using Aspose.Words. Moreover, you may want to take a look at the List class below:
http://www.aspose.com/docs/display/wordsnet/List+Class

Best Regards,

help me,thanks

Hi,


Thanks for your inquiry and sorry for the delayed response. In your case, you can turn your list numbering into static list labels by using the following code snippet:

Document doc = new
Document(@“C:\Temp\sourcefile.docx”);

doc.UpdateListLabels();

foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true))

{

if (paragraph.ListFormat.IsListItem)

{

string label = paragraph.ListLabel.LabelString;

Run run = new Run(doc);

run.Text = label;

run.Font.Name = "Calibri";

double leftIndent = paragraph.ParagraphFormat.LeftIndent;

double hangingIndent = paragraph.ParagraphFormat.FirstLineIndent;

paragraph.ListFormat.RemoveNumbers();

paragraph.Runs.Insert(0, run);

paragraph.ParagraphFormat.LeftIndent = leftIndent;

paragraph.ParagraphFormat.FirstLineIndent = hangingIndent;

}

}

doc.Save(@“C:\Temp\out.docx”);


I hope, this helps.

Best Regards,

thanks,at first that worked good,but at secend time to call , the return value is not good, paragraph.ListLabel.LabelString return “1%” or “%1.%2”,Does not return the correct value “1” or “1.1”;but reopen file and re call,then paragraph.ListLabel.LabelString return is correct value “1” or “1.1”

Hi,


Thanks for the additional information. Please create a simple console application that demonstrates your problem and attach it here for testing. I will run your application to reproduce the same issue on my side and provide you a fix.

Best Regards,