Free Support Forum - aspose.com

How to set font size when created custom list style

Hi there,


I’ve created new list style by following code:
private List DefineNewListNumbering(Document doc)
{
        <span style="color:blue;">var</span> list = doc.Lists.Add(<span style="color:#2b91af;">ListTemplate</span>.OutlineHeadingsLegal);
        <span style="color:green;">// Level 1 labels will be "1".</span>
        list.ListLevels[0].NumberFormat = <span style="color:#a31515;">"\x0000."</span>;
        list.ListLevels[0].NumberStyle = <span style="color:#2b91af;">NumberStyle</span>.Arabic;
        list.ListLevels[0].Font.Size = 20;
        <span style="color:green;">// Level 2 labels will be "1.1."</span>
        list.ListLevels[1].NumberFormat = <span style="color:#a31515;">"\x0000.\x0001."</span>;
        list.ListLevels[1].NumberStyle = <span style="color:#2b91af;">NumberStyle</span>.Arabic;
        list.ListLevels[1].Font.Size = 14;
        list.ListLevels[1].Font.Italic = <span style="color:blue;">false</span>;
        <span style="color:green;">// Level 3 labels will be "1.1.1.".</span>
        list.ListLevels[2].NumberFormat = <span style="color:#a31515;">"\x0000.\x0001.\x0002."</span>;
        list.ListLevels[2].NumberStyle = <span style="color:#2b91af;">NumberStyle</span>.Arabic;
        list.ListLevels[2].Font.Size = 11;
        <span style="color:green;">// Level 4 labels will be "a.1.".</span>
        list.ListLevels[3].NumberFormat = <span style="color:#a31515;">"\x0003.\x0000."</span>;
        list.ListLevels[3].NumberStyle = <span style="color:#2b91af;">NumberStyle</span>.LowercaseLetter;

        <span style="color:green;">// Make labels of all list levels bold.</span>
        <span style="color:blue;">foreach</span> (<span style="color:#2b91af;">ListLevel</span> level <span style="color:blue;">in</span> list.ListLevels)
        {
            level.Font.Bold = <span style="color:blue;">true</span>;
        }
            
        <span style="color:blue;">return</span> list;
    }</pre><pre style="font-family: Consolas; font-size: 13px; background: white;">This code run very fun but font size of list level cannot match with my style.</pre><pre style="font-family: Consolas; font-size: 13px; background: white;">This font style keeps default font. Heading 1 has font size 16 and heading 2 has font size 14.</pre><pre style="font-family: Consolas; font-size: 13px; background: white;">Please help me to fix this issue.</pre><pre style="font-family: Consolas; font-size: 13px; background: white;">Thanks,</pre><pre style="font-family: Consolas; font-size: 13px; background: white;">Hanh</pre></div>

Hi Hanh,

Can you please share a couple of documents to show what you get after running your code and what is your expected output?

Best Regards,

Hi guys,


I just posted my expect out.
Please help me to view it and give me advances

Thanks,
Hanh

Hi Hanh,

Your document has many pages and lists. Can you please highlight which part of the document you are referring to? It would be great if you can copy your desired list in a new document and post that document with a single list only.

If you are trying to work with Table of Contents field, you can follow this example http://www.aspose.com/docs/display/wordsnet/How-to+Insert+and+Work+with+the+Table+of+Contents+Field to work with table of contents.

Best Regards,

Hi you guys,


Thanks for your feedback. Please see my expert list style bellow:
1. Heading 1
1.1. Heading 2
1.1.2 Heading 3
2. Heading 2.1
2.1. Heading 2.1.2
2.1.1. Heading 2.1.2

Right now, My above code is correctly with output. But now, Heading 2(eg: 1.1. Heading 2) is having font-italic default is true and Heading 3(eg: 1.1.2 Heading 3) is having font-size default is 10. I’m trying to change font-size and font-italic default to font-italic = false and fonts-size = 11. But It can’t be changed .
Please help me to fix it.

Many thanks,

Hi Hanh,

Your code generates attached list at my end. Can you please elaborate what problems you see in this output?

Best Regards,

Hi you guys,


Please see my attach file which contains output generated by my above code and my expert output.

Thanks,

Hi Hanh,

Thanks for the detailed description. We are working on updating your code according to your requirement and will update you soon.

Best Regards,

Hi Hanh,

You are using paragraph level styles for different levels of your desired list so you need to update these styles before adding text to your list. You can use following code to set styles and formatting for different levels of your required list.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

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

List list = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);

list.ListLevels[0].NumberFormat = "\x0000.";

list.ListLevels[0].NumberStyle = NumberStyle.Arabic;

Style styleLevel0 = doc.Styles["Heading 1"];

styleLevel0.Font.Size = 24;

styleLevel0.ListFormat.List = list;

styleLevel0.ListFormat.ListLevelNumber = 0;

Style styleLevel1 = doc.Styles["Heading 2"];

styleLevel1.Font.Italic = false;

styleLevel1.ListFormat.List = list;

styleLevel1.ListFormat.ListLevelNumber = 1;

builder.ParagraphFormat.Style = styleLevel0;

builder.Writeln("Level0 Text 1.");

builder.ParagraphFormat.Style = styleLevel1;

builder.Writeln("Level1 Text 1.");

builder.ParagraphFormat.Style = styleLevel0;

builder.Writeln("Level0 Text 2.");

builder.ParagraphFormat.Style = styleLevel1;

builder.Writeln("Level1 Text 2.");

builder.ParagraphFormat.Style = styleLevel1;

builder.Writeln("Level1 Text 3.");

builder.ListFormat.RemoveNumbers();

builder.ParagraphFormat.ClearFormatting();

builder.Document.Save("Lists Out.doc");

Best Regards,

Many thanks for your answer. This code is correct. :slight_smile: