Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Jul 11, 2019 8:56 am

Itry to use the Multi-level List with custom counter and am having the indent issue problem.
my goal is to create the following structure multi-levle list

二、 Titie
(一) sub_titile
<tab space>1. sub_sub_title
<tab space><tab space>(1)sub_sub_subtitle
<tab space><tab space><tab space>a. sub_sub_sub_sub_title
but my code prodoce the following result
二、 Titie
(一) sub_titile
1. sub_sub_title
(1) sub_sub_subtitle
<tab space><tab space><tab space> a. sub_sub_sub_sub_title
i creat the custom liststyle with the following code
Code: Select all
 ListStyle listStyle = new ListStyle(document, ListType.Numbered);
            listStyle.Name = "levelstyle";
            listStyle.Levels[0].PatternType = ListPatternType.ChineseCounting;     
            listStyle.Levels[0].NumberPrefix = "第";
            listStyle.Levels[0].NumberSufix = "章";
            listStyle.Levels[0].ParagraphFormat.SetLeftIndent(0);
            listStyle.Levels[0].ParagraphFormat.SetFirstLineIndent(0);
            listStyle.Levels[1].PatternType = ListPatternType.ChineseCounting;
            listStyle.Levels[1].NumberSufix = "、";
            listStyle.Levels[1].NumberPosition = -25;
            listStyle.Levels[1].ParagraphFormat.SetLeftIndent(25);
            listStyle.Levels[1].ParagraphFormat.SetFirstLineIndent(0);

            listStyle.Levels[2].PatternType = ListPatternType.Arabic;
            listStyle.Levels[2].NumberPrefix = "(";
            listStyle.Levels[2].NumberSufix = ")";
            listStyle.Levels[2].CharacterFormat.FontSize = contentformat.FontSize;
            listStyle.Levels[2].CharacterFormat.FontName = "DFKai-SB";
            listStyle.Levels[2].ParagraphFormat.SetLeftIndent(30);
            listStyle.Levels[2].ParagraphFormat.SetFirstLineIndent(0);
            listStyle.Levels[2].NumberPosition = -30;
            listStyle.Levels[2].NumberAlignment = ListNumberAlignment.Left;
            listStyle.Levels[3].PatternType = ListPatternType.Arabic; 
            listStyle.Levels[3].ParagraphFormat.SetLeftIndent(40);
            listStyle.Levels[3].ParagraphFormat.SetFirstLineIndent(0);
            listStyle.Levels[3].NumberPosition = -40;
            listStyle.Levels[4].PatternType = ListPatternType.LowLetter;
            listStyle.Levels[4].NumberPosition = -60;
            listStyle.Levels[4].ParagraphFormat.SetLeftIndent(60);
            listStyle.Levels[4].ParagraphFormat.SetFirstLineIndent(0);
            document.ListStyles.Add(listStyle);


any suggestion of solving the indent and header misalign issue?
Last edited by dczephy on Fri Jul 12, 2019 1:50 am, edited 1 time in total.

dczephy
 
Posts: 6
Joined: Thu Jul 11, 2019 8:46 am
Location: Taiwan

Thu Jul 11, 2019 11:23 am

Hello,

Thanks for your inquiry.
There are some issues when looking into the issue, we need to do more investigations and then reply you ASAP.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Fri Jul 12, 2019 5:44 am

Hello,

Thanks for your patient waiting.
I noticed that you have modified your post. Please refer to the following sample code to achieve your desired effect. If there is any question, welcome to write back.
Code: Select all
 Document doc = new Document();
 Section section = doc.AddSection();
 ListStyle listStyle = new ListStyle(doc, ListType.Numbered);
 listStyle.Name = "levelstyle";
 //level 1
 listStyle.Levels[0].PatternType = ListPatternType.ChineseCounting;     
 listStyle.Levels[0].NumberPrefix = "第";
 listStyle.Levels[0].NumberSufix = "章";
 listStyle.Levels[0].ParagraphFormat.SetLeftIndent(0);
 listStyle.Levels[0].ParagraphFormat.SetFirstLineIndent(0);
 //level 2
 listStyle.Levels[1].PatternType = ListPatternType.ChineseCounting;
 listStyle.Levels[1].NumberSufix = "、";
 listStyle.Levels[1].NumberAlignment = ListNumberAlignment.Left;
 listStyle.Levels[1].ParagraphFormat.SetLeftIndent(0);
 listStyle.Levels[1].NumberPosition = 0;
 //level 3
 listStyle.Levels[2].PatternType = ListPatternType.ChineseCounting;
 listStyle.Levels[2].NumberPrefix = "(";
 listStyle.Levels[2].NumberSufix = ")";
 listStyle.Levels[2].NumberAlignment = ListNumberAlignment.Left;
 listStyle.Levels[2].ParagraphFormat.SetLeftIndent(0);
 listStyle.Levels[2].NumberPosition = 0;
 //level 4
 listStyle.Levels[3].PatternType = ListPatternType.Arabic;
 listStyle.Levels[3].ParagraphFormat.ClearFormatting();
 listStyle.Levels[3].NumberPosition = 20;
 //level 5
 listStyle.Levels[4].PatternType = ListPatternType.Arabic;
 listStyle.Levels[4].NumberPrefix = "(";
 listStyle.Levels[4].NumberSufix = ")";
 listStyle.Levels[4].CharacterFormat.FontSize = 12;
 listStyle.Levels[4].CharacterFormat.FontName = "DFKai-SB";
 listStyle.Levels[4].ParagraphFormat.ClearFormatting();
 listStyle.Levels[4].NumberAlignment = ListNumberAlignment.Left;
 listStyle.Levels[4].NumberPosition = 40;
 //level 6
 listStyle.Levels[5].PatternType = ListPatternType.LowLetter;
 listStyle.Levels[5].ParagraphFormat.ClearFormatting();
 listStyle.Levels[5].NumberPosition = 60;
 doc.ListStyles.Add(listStyle);
 Spire.Doc.Formatting.CharacterFormat format = new Spire.Doc.Formatting.CharacterFormat(doc);
 format.FontName = "Arial";
 //para1
 Paragraph paragraph = section.AddParagraph();
 TextRange tr = paragraph.AppendText("");
 tr.ApplyCharacterFormat(format);
 paragraph.ListFormat.ListLevelNumber = 0;
 paragraph.ListFormat.ApplyStyle("levelstyle");
 //para2
 paragraph = section.AddParagraph();
 tr = paragraph.AppendText("Title");
 tr.ApplyCharacterFormat(format);
 paragraph.ListFormat.ListLevelNumber = 1;
 paragraph.ListFormat.ApplyStyle("levelstyle");
 //para3
 paragraph = section.AddParagraph();
 tr = paragraph.AppendText("sub_titile");
 tr.ApplyCharacterFormat(format);
 paragraph.ListFormat.ListLevelNumber = 2;
 paragraph.ListFormat.ApplyStyle("levelstyle");
 //para4
 paragraph = section.AddParagraph();
 tr = paragraph.AppendText("sub_sub_title");
 tr.ApplyCharacterFormat(format);
 paragraph.ListFormat.ListLevelNumber = 3;
 paragraph.ListFormat.ApplyStyle("levelstyle");
 //para5
 paragraph = section.AddParagraph();
 tr = paragraph.AppendText("sub_sub_subtitle");
 tr.ApplyCharacterFormat(format);
 paragraph.ListFormat.ListLevelNumber = 4;
 paragraph.ListFormat.ApplyStyle("levelstyle");
 //para6
 paragraph = section.AddParagraph();
 tr = paragraph.AppendText("sub_sub_sub_sub_title");
 tr.ApplyCharacterFormat(format);
 paragraph.ListFormat.ListLevelNumber = 5;
 paragraph.ListFormat.ApplyStyle("levelstyle");
 doc.SaveToFile("result.docx", Spire.Doc.FileFormat.Docx);

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Fri Jul 12, 2019 6:19 am

Thanks for the help now the title with subtitle indent is what I hope to create for my doc.
now I am facing another issue is that when the title is too long that need more than 2 lines to display the 2nd line will not indent as the first line.
Please see attachment for graphic

I try to use the listStyle.Levels[4].ParagraphFormat.SetLeftIndent(20); but to no avil.

dczephy
 
Posts: 6
Joined: Thu Jul 11, 2019 8:46 am
Location: Taiwan

Fri Jul 12, 2019 7:04 am

Hello,

Thanks for your quick response.
When setting SetLeftIndent(20), please comment out the setting of NumberPosition like the following code snippet to achieve. If there is any question, just feel free to write back.
Code: Select all
listStyle.Levels[4].PatternType = ListPatternType.Arabic;
listStyle.Levels[4].ParagraphFormat.ClearFormatting();
listStyle.Levels[4].ParagraphFormat.SetLeftIndent(20);
//listStyle.Levels[4].NumberPosition = 20;

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Fri Jul 12, 2019 8:49 am

Thanks for the help but the indent part still need some help.
the following graph is what I create and what I hope will be
thanks for your help in advance

dczephy
 
Posts: 6
Joined: Thu Jul 11, 2019 8:46 am
Location: Taiwan

Fri Jul 12, 2019 9:08 am

Hello,

Please do settings like the below way to achieve your target format. Just feel free to write back if there is any other question.
Code: Select all
 listStyle.Levels[3].PatternType = ListPatternType.Arabic;
 listStyle.Levels[3].ParagraphFormat.ClearFormatting();
 listStyle.Levels[3].ParagraphFormat.SetFirstLineIndent(-20);
 listStyle.Levels[3].ParagraphFormat.SetLeftIndent(40);

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Wed Jul 17, 2019 9:59 am

Hello,

Greetings from E-iceblue.
Did my code work for you? Thanks in advance for your feedback and time.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Thu Jul 18, 2019 1:40 am

Thanks for the help
most of the indent issues are solved.
I also discover that it will automatically insert white space behind the counter and the length of space will be affected by sub-level. (chinese counter)
I solved this part by tweaking the sub-level indent length and somehow fix the structure.

dczephy
 
Posts: 6
Joined: Thu Jul 11, 2019 8:46 am
Location: Taiwan

Thu Jul 18, 2019 2:42 am

Hello,

Glad to hear that! If you encounter any issue related to our products in the future, just feel free to contact us.
Wish you all the best!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc