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

How To get the correct style for custom list ? #256

Open
khofesh opened this issue Sep 27, 2024 · 3 comments
Open

How To get the correct style for custom list ? #256

khofesh opened this issue Sep 27, 2024 · 3 comments

Comments

@khofesh
Copy link

khofesh commented Sep 27, 2024

OfficeIMO version: 0.18.0

Hi, I'm trying to change the color of the bullet point

here's my code

using WordDocument document = WordDocument.Create();

NumberingDefinitionsPart numberingPart = document._document.MainDocumentPart
    .AddNewPart<NumberingDefinitionsPart>("OSgBuNd6wIbboubIU5c0");
numberingPart.Numbering = new Numbering(
    new AbstractNum(
        new Level(
            new NumberingFormat() { Val = NumberFormatValues.Bullet },
            new LevelText() { Val = "•" },
            new RunProperties(
                new Color { Val = fontColorStr }
            ),
            new ParagraphProperties(
                new Indentation() { Left = "700", Hanging = "360" }
            )
        )
        { LevelIndex = 0 }
    )
    { AbstractNumberId = 1 },
    new NumberingInstance(
        new AbstractNumId() { Val = 1 }
    )
    { NumberID = 420 }
);

a function to generate list

    public static WordParagraph CreateCustomBulletListItem(WordDocument document, string text, string textColor, int fontSize)
    {
        var paragraph = new Paragraph();

        var numberingProperties = new NumberingProperties(
            new NumberingLevelReference() { Val = 0 },
            new NumberingId() { Val = 420 }
        );


        var textRunProperties = new RunProperties(
            new Color() { Val = textColor },
            new RunFonts() { Ascii = "Calibri", HighAnsi = "Calibri" },
            new FontSize() { Val = (fontSize * 2).ToString() }  // OpenXML uses half-points
        );

        var paragraphProperties = new ParagraphProperties(
            numberingProperties,
            new SpacingBetweenLines() { After = "0", Line = "240", LineRule = LineSpacingRuleValues.Auto }
        );

        // spacing properties
        SpacingBetweenLines spacingBetweenLines = new SpacingBetweenLines()
        {
            Before = "0", // Spacing before (in twips, 1/20 pt)
            After = "0",  // Spacing after (in twips, 1/20 pt)
            Line = "240", // Line spacing (240 twips = 12 points = single spacing)
            LineRule = LineSpacingRuleValues.Auto // Automatically adjust line spacing
        };

        paragraphProperties.Append(spacingBetweenLines);

        var textRun = new Run(
            textRunProperties,
            new Text(text)
        );

        paragraph.Append(paragraphProperties, textRun);


        return document.AddParagraph(
            new WordParagraph(document, paragraph)
        );
    }

creating the custom list

                CustomHorizontalLine(document);
                document.AddParagraph(RegulerStyle(""));

                CreateCustomBulletListItem(
                    document, "this is a test", fontColorStr, defaultFontSize
                );
                CreateCustomBulletListItem(
                    document, "this is a test2", fontColorStr, defaultFontSize
                );

                CustomHorizontalLine(document);
                document.AddParagraph(RegulerStyle(""));

the result is not quite satistying

image (2)

How to get the default style like this ?
image

var softwareList = document.AddList(WordListStyle.Bulleted);
foreach (var skill in someData)
{
    var item = pccList.AddItem($"{skill.Name}", 0)
        .SetColor(fontColor);
    item.FontSize = defaultFontSize;
    item.LineSpacing = 240;
    item.LineSpacingAfter = 0;
    item.LineSpacingBefore = 0;
    item.LineSpacingRule = LineSpacingRuleValues.Auto;
}

thanks in advance

@PrzemyslawKlys
Copy link
Member

To be honest - I don't know :-)

Try looking at this PR:

I started building something that would allow creating custom lists or loading ones, but I am not sure at the moment what is the state of it and whether it actually works

@PrzemyslawKlys
Copy link
Member

It could also be related to work in here:

@khofesh
Copy link
Author

khofesh commented Sep 27, 2024

@PrzemyslawKlys Hi, thank you.

I'll look into the URLs you shared

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