Example #1
0
        public void ParseStyle()
        {
            var elements = converter.Parse(@"<b style=""
font-style:italic;
font-size:12px;
color:red;
text-decoration:underline;
"">bold with italic style</b>");

            Assert.That(elements.Count, Is.EqualTo(1));

            Run run = elements[0].GetFirstChild <Run>();

            Assert.IsNotNull(run);

            RunProperties runProperties = run.GetFirstChild <RunProperties>();

            Assert.IsNotNull(runProperties);
            Assert.Multiple(() => {
                Assert.IsTrue(runProperties.HasChild <Bold>());
                Assert.IsTrue(runProperties.HasChild <Italic>());
                Assert.IsTrue(runProperties.HasChild <FontSize>());
                Assert.IsTrue(runProperties.HasChild <Underline>());
                Assert.IsTrue(runProperties.HasChild <Color>());
            });
        }
Example #2
0
        Run GenerateTextRun(string Content, WordTable.ColumnStyle Style = WordTable.ColumnStyle.NONE)
        {
            RunProperties Props = CurrentRun.Copy() ?? new RunProperties();

            if (Style.HasFlag(WordTable.ColumnStyle.BOLD))
            {
                if (!Props.HasChild <Bold>())
                {
                    Props.AppendChild(new Bold());
                }
                else
                {
                    Props.GetFirstChild <Bold>().Val.Value = true;
                }
            }

            if (Style.HasFlag(WordTable.ColumnStyle.ITALIC))
            {
                if (!Props.HasChild <Italic>())
                {
                    Props.AppendChild(new Italic());
                }
                else
                {
                    Props.GetFirstChild <Italic>().Val.Value = true;
                }
            }

            if (Style.HasFlag(WordTable.ColumnStyle.UNDERLINE) && !Props.HasChild <Underline>())
            {
                if (!Props.HasChild <Underline>())
                {
                    Props.AppendChild(new Underline());
                }
                else
                {
                    Props.GetFirstChild <Underline>().Val.Value = UnderlineValues.Single;
                }
            }

            Run NewRun = new Run();

            NewRun.AppendChild(Props);

            string[] Lines = Content.Replace("\r", "").Split(new[] { '\n' });
            for (int i = 0; i < Lines.Length; i++)
            {
                NewRun.AppendChild(new Text(Lines[i])
                {
                    Space = SpaceProcessingModeValues.Preserve
                });

                if (i < Lines.Length - 1)
                {
                    NewRun.AppendChild(new Break());
                }
            }

            return(NewRun);
        }