DocX
DocX copied to clipboard
How to get custom style form Template. Using custom styles to List
Hi!
I have my document with custom styles. Haw can i get them? How can i use my custom styles to List? There is no property StyleName, like at Paragraph.
Example:
File.Copy("Template.docx", "TestDocument.docx", true); var document = DocX.Load("TestDocument.docx"); var list = document.AddList(listType: ListItemType.Bulleted); document.AddListItem(list, "Text", item.Level); document.InsertList(list);
In document Template.docx i have my custom style for List, but i cant find how to get that style, and how to use it after.
May be i should create paragraph and use my style to it, but i dont know how to get my style.
Wating for answer, thanks :)
Find a solution. Just created every ListItem as paragrpah and used id of my common style in StyleName.
Found another problem... Cant reset numbering of numbered lists, created using my style, so if the first list ends on "4", the second list will start with "5".
Is there any way to reset numbering?
Thanks! :)
Hi, Can you submit a sample so we can validate how you created your lists and test the same code as you ? Thank you
Hi, in my template i have styles for lists.
Example:
Code:
File.Copy("Template.docx", "TestDocument.docx", true); var document = DocX.Load("TestDocument.docx");
var listItem = document.InsertParagraph("Text"); listItem.StyleName = "id" - here i'm using style, depending on the list level
And if I insert some text and then create a list, it looks like this:
Вut I don't need the next list to continue numbering, i need to start it form "a)"
Posted code in the comment above.
Wating for answer. Thanks.
Hi,
I don't have your template (and not much details on how the listItems are created), but if I use the following code to add 2 different lists in a docx, the second list restart at 1.
` var document = DocX.Create( "AddList.docx" );
// Add a numbered list where the first ListItem is starting with number 1.
var numberedList = document.AddList( "Berries", 0, ListItemType.Numbered, 1 );
// Add Sub-items(level 1) to the preceding ListItem.
document.AddListItem( numberedList, "Strawberries", 1 );
document.AddListItem( numberedList, "Blueberries", 1 );
document.AddListItem( numberedList, "Raspberries", 1 );
// Add an item (level 0)
document.AddListItem( numberedList, "Banana" );
// Add an item (level 0)
document.AddListItem( numberedList, "Apple" );
// Add Sub-items(level 1) to the preceding ListItem.
document.AddListItem( numberedList, "Red", 1 );
document.AddListItem( numberedList, "Green", 1 );
document.AddListItem( numberedList, "Yellow", 1 );
document.InsertList( numberedList );
document.InsertParagraph("Some text").SpacingAfter( 40d );
// Add a 2nd list
var numberedList2 = document.AddList( "Second List", 0, ListItemType.Numbered );
// Add Sub-items(level 1) to the preceding ListItem.
document.AddListItem( numberedList2, "Second List Content", 1 );
document.InsertList( numberedList2 );
document.Save();`