Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figuring out the list type #258

Open
ChrisBellBO opened this issue Sep 30, 2024 · 3 comments
Open

Figuring out the list type #258

ChrisBellBO opened this issue Sep 30, 2024 · 3 comments

Comments

@ChrisBellBO
Copy link
Contributor

Hi
I am trying to convert Word lists into HTML ul/ol lists. I've found IsListItem and ListItemLevel which gives me enough to figure out the structure of the list but I'm not sure how to find out if it is a numbered or bulleted list. I see AddList takes a WordListStyle parameter which looks like it might give me what I want, but that doesn't seem to be exposed anywhere. I can't find it on the underlying object either, any ideas?

@PrzemyslawKlys
Copy link
Member

I am probably not exposing anything.

Document has Lists property, which is WordList List, which is where it should be exposed. The "type" of the list is not stored on paragraphs, but at completely different place which is a nightmare to track

Looking at this test:

[Fact]
public void Test_SavingWordDocumentWithListsToStream() {
var filePath = Path.Combine(_directoryWithFiles, "CreatedDocumentWithListsToStream.docx");
var wordListStyles = (WordListStyle[])Enum.GetValues(typeof(WordListStyle));
using (var document = WordDocument.Create()) {
foreach (var listStyle in wordListStyles) {
var paragraph = document.AddParagraph(listStyle.ToString());
paragraph.SetColor(Color.Red).SetBold();
paragraph.ParagraphAlignment = JustificationValues.Center;
var wordList1 = document.AddList(listStyle);
wordList1.AddItem("Text 1");
}
using var outputStream = new MemoryStream();
document.Save(outputStream);
File.WriteAllBytes(filePath, outputStream.ToArray());
Assert.True(HasUnexpectedElements(document) == false, "Document has unexpected elements. Order of elements matters!");
}
using (var document = WordDocument.Load(filePath)) {
Assert.Equal(wordListStyles.Length, document.Lists.Count);
var abstractNums = document._wordprocessingDocument.MainDocumentPart!.NumberingDefinitionsPart!
.Numbering.ChildElements.OfType<AbstractNum>().ToArray();
for (var idx = 0; idx < abstractNums.Length; idx++) {
var style = WordListStyles.GetStyle(wordListStyles[idx]);
Assert.Equal(style, abstractNums[idx]);
}
}
}

You could probably figure it out. I started exposing some things in:

But it's not yet ready

@ChrisBellBO
Copy link
Contributor Author

Thanks
WordParagraph has a private listNumberId and WordList has a private _numberId so I think that's how I get the list for the list item
WordList has a private _abstractId which I guess is how I then get hold of the AbstractNum that holds the actual style
Then things get complicated. AbstractNum can have different styles at each level so I think it probably makes sense to have the style on the list item rather than on the list?

@PrzemyslawKlys
Copy link
Member

The list style is applied on the list level => as in the general ones, however each list item, depending on level may have it's own config, if the list is custom, which you can see in the linked PR.

So I guess exposing both makes sense => as in list has it's own type or custom, and then each list item would need to expose what it has

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants