开发者

C# OpenXml Selective Font Bolding

开发者 https://www.devze.com 2023-04-11 06:11 出处:网络
I have a function that takes a couple of font parameters, and produces the required font in a RunProperties class. How can I turn on/off the Bold class? MSDN was pretty useless on this issue.

I have a function that takes a couple of font parameters, and produces the required font in a RunProperties class. How can I turn on/off the Bold class? MSDN was pretty useless on this issue.

public RunProperties getRCFont(int size, string color = "000000", string font = "Futura Bk BT", bool bld = false, bool und = false) {

    return new RunProperties(new Bold() { Val = bld ? OnOffOnlyValues.On : OnOffOnlyValues.Off });

}

This doesn't work, produces this error:

Error 1 Cannot implicitly convert type 'DocumentFormat.OpenXml.Wordprocessing.OnOffOnlyValues' to 'DocumentFormat.OpenXml.OnOffValue'

But OnOffValue class has no properties!!

P.S. : Underline class has UnderlineValues class, but not for the Bold class (such as BoldValues), bah.

E开发者_如何学Pythondit - I'm sorry I got it. For anyone interested in the solution:

return new RunProperties(new Bold() { Val = bld ? new OnOffValue { Value = true } : new OnOffValue { Value = false } });


RunProperties(new Bold() { Val = bld ? new OnOffValue { Value = true } : new OnOffValue { Value = false } });


You can resume the line using bld instead of use the operator "?:"

RunProperties(new Bold() { Val = new OnOffValue { Value = bld } });

0

精彩评论

暂无评论...
验证码 换一张
取 消