本文整理汇总了C#中RunProperties.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# RunProperties.AppendChild方法的具体用法?C# RunProperties.AppendChild怎么用?C# RunProperties.AppendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RunProperties
的用法示例。
在下文中一共展示了RunProperties.AppendChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendParagraphToDocument
public static WmlDocument AppendParagraphToDocument(
WmlDocument wmlDoc,
string strParagraph,
bool isBold,
bool isItalic,
bool isUnderline,
string foreColor,
string backColor,
string styleName)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(wmlDoc))
{
using (WordprocessingDocument wDoc = streamDoc.GetWordprocessingDocument())
{
StyleDefinitionsPart part = wDoc.MainDocumentPart.StyleDefinitionsPart;
Body body = wDoc.MainDocumentPart.Document.Body;
SectionProperties sectionProperties = body.Elements<SectionProperties>().FirstOrDefault();
Paragraph paragraph = new Paragraph();
Run run = paragraph.AppendChild(new Run());
RunProperties runProperties = new RunProperties();
if (isBold)
runProperties.AppendChild(new Bold());
if (isItalic)
runProperties.AppendChild(new Italic());
if (!string.IsNullOrEmpty(foreColor))
{
int colorValue = System.Drawing.Color.FromName(foreColor).ToArgb();
if (colorValue == 0)
throw new OpenXmlPowerToolsException(String.Format("Add-DocxText: The specified color {0} is unsupported, Please specify the valid color. Ex, Red, Green", foreColor));
string ColorHex = string.Format("{0:x6}", colorValue);
runProperties.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Color() { Val = ColorHex.Substring(2) });
}
if (isUnderline)
runProperties.AppendChild(new Underline() { Val = UnderlineValues.Single });
if (!string.IsNullOrEmpty(backColor))
{
int colorShade = System.Drawing.Color.FromName(backColor).ToArgb();
if (colorShade == 0)
throw new OpenXmlPowerToolsException(String.Format("Add-DocxText: The specified color {0} is unsupported, Please specify the valid color. Ex, Red, Green", foreColor));
string ColorShadeHex = string.Format("{0:x6}", colorShade);
runProperties.AppendChild(new Shading() { Fill = ColorShadeHex.Substring(2), Val = ShadingPatternValues.Clear });
}
if (!string.IsNullOrEmpty(styleName))
{
Style style = part.Styles.Elements<Style>().Where(s => s.StyleId == styleName).FirstOrDefault();
//if the specified style is not present in word document add it
if (style == null)
{
using (MemoryStream memoryStream = new MemoryStream())
{
#region Default.dotx Template has been used to get all the paragraph styles
string base64 =
@"UEsDBBQABgAIAAAAIQDTMB8uXgEAACAFAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbLSUy27CMBBF
95X6D5G3VWLooqoqAos+li1S6QcYewJW/ZI9vP6+EwKoqiCRCmwiJTP33jNWxoPR2ppsCTFp70rW
L3osAye90m5Wsq/JW/7IsoTCKWG8g5JtILHR8PZmMNkESBmpXSrZHDE8cZ7kHKxIhQ/gqFL5aAXS
a5zxIOS3mAG/7/UeuPQOwWGOtQcbDl6gEguD2euaPjckEUxi2XPTWGeVTIRgtBRIdb506k9Kvkso
SLntSXMd0h01MH40oa6cDtjpPuhoolaQjUXEd2Gpi698VFx5ubCkLNptjnD6qtISDvraLUQvISU6
c2sKBBtoAiis0G7Pf5Ij4cZAujxF49sdD4gkuAbAzrkTYQXTz6tR/DLvBKkodyKmBi6PcbDuhEDa
QGie/bM5tjZtkdQ5jj4k2uj4j7H3K1urcxo4QETd/tcdEsn67Pmgvg0UqCPZfHu/DX8AAAD//wMA
UEsDBBQABgAIAAAAIQAekRq37wAAAE4CAAALAAAAX3JlbHMvLnJlbHOsksFqwzAMQO+D/YPRvVHa
wRijTi9j0NsY2QcIW0lME9vYatf+/TzY2AJd6WFHy9LTk9B6c5xGdeCUXfAallUNir0J1vlew1v7
vHgAlYW8pTF41nDiDJvm9mb9yiNJKcqDi1kVis8aBpH4iJjNwBPlKkT25acLaSIpz9RjJLOjnnFV
1/eYfjOgmTHV1mpIW3sHqj1FvoYdus4ZfgpmP7GXMy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FaNo+mq88+mrft6tHd
u810ni+yZkwtlvTleVUvspb+rC/urrLp2+wiv7u3s/Pp3UXeZrOsze4C4PbKQvxIQc6mFuRqXZcM
YDa9m5f5Il+2zd3d8e5d17bN60UTfYG/8VouivZ6lUebmi9t63dNYRteXV2Nr+5xU8J/9+7v/cXz
1zzU7WIJUk3zj44ez6aPpnWetVV9dJIVbVks0+NmXubX26+qslxky8d3vSYgZ5k17RdE+PMinz25
vsuf1fllgZk52n181//zsY5TAOSzlPB7JKMx33z33snTN88+Otrb2d3b3nmwvXf/ze6DR3v3H+3s
/BT6Dt53ABeKwW0g3nuzt/tovwPRADhijEMeOfp/AFBLAwQUAAYACAAAACEA1mSzUfQAAAAxAwAA
HAAAAHdvcmQvX3JlbHMvZG9jdW1lbnQueG1sLnJlbHOskstqwzAQRfeF/oOYfS07fVBC5GxKIdvW
/QBFHj+oLAnN9OG/r0hJ69BguvByrphzz4A228/BineM1HunoMhyEOiMr3vXKnipHq/uQRBrV2vr
HSoYkWBbXl5sntBqTkvU9YFEojhS0DGHtZRkOhw0ZT6gSy+Nj4PmNMZWBm1edYtyled3Mk4ZUJ4w
xa5WEHf1NYhqDPgftm+a3uCDN28DOj5TIT9w/4zM6ThKWB1bZAWTMEtEkOdFVkuK0B+LYzKnUCyq
wKPFqcBhnqu/XbKe0y7+th/G77CYc7hZ0qHxjiu9txOPn+goIU8+evkFAAD//wMAUEsDBBQABgAI
ANFqBkF65TN3MwIAAJAFAAARAAAAd29yZC9kb2N1bWVudC54bWztvQdgHEmWJSYvbcp7f0r1Stfg
//.........这里部分代码省略.........