public void Substring_From_ThreeStrings_Start2()
        {
            IXLWorksheet ws         = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLRichText  richString = ws.Cell(1, 1).RichText;

            richString.AddText("Good Morning");
            richString.AddText(" my ");
            richString.AddText("neighbors!");

            IXLFormattedText <IXLRichText> actual = richString.Substring(0, 15);

            Assert.AreEqual(2, actual.Count);

            Assert.AreEqual(4, richString.Count); // The text was split because of the substring

            Assert.AreEqual("Good Morning", actual.ElementAt(0).Text);
            Assert.AreEqual(" my", actual.ElementAt(1).Text);

            Assert.AreEqual("Good Morning", richString.ElementAt(0).Text);
            Assert.AreEqual(" my", richString.ElementAt(1).Text);
            Assert.AreEqual(" ", richString.ElementAt(2).Text);
            Assert.AreEqual("neighbors!", richString.ElementAt(3).Text);

            actual.ElementAt(1).SetBold();

            Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(0).Bold);
            Assert.AreEqual(true, ws.Cell(1, 1).RichText.ElementAt(1).Bold);
            Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(2).Bold);
            Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(3).Bold);

            richString.First().SetItalic();

            Assert.AreEqual(true, ws.Cell(1, 1).RichText.ElementAt(0).Italic);
            Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(1).Italic);
            Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(2).Italic);
            Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(3).Italic);

            Assert.AreEqual(true, actual.ElementAt(0).Italic);
            Assert.AreEqual(false, actual.ElementAt(1).Italic);

            richString.SetFontSize(20);

            Assert.AreEqual(20, ws.Cell(1, 1).RichText.ElementAt(0).FontSize);
            Assert.AreEqual(20, ws.Cell(1, 1).RichText.ElementAt(1).FontSize);
            Assert.AreEqual(20, ws.Cell(1, 1).RichText.ElementAt(2).FontSize);
            Assert.AreEqual(20, ws.Cell(1, 1).RichText.ElementAt(3).FontSize);

            Assert.AreEqual(20, actual.ElementAt(0).FontSize);
            Assert.AreEqual(20, actual.ElementAt(1).FontSize);
        }
示例#2
0
        public void Substring_All_From_OneString()
        {
            IXLWorksheet ws         = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLRichText  richString = ws.Cell(1, 1).RichText;

            richString.AddText("Hello");

            IXLFormattedText <IXLRichText> actual = richString.Substring(0);

            Assert.AreEqual(richString.First(), actual.First());

            Assert.AreEqual(1, actual.Count);

            actual.First().SetBold();

            Assert.AreEqual(true, ws.Cell(1, 1).RichText.First().Bold);
        }
示例#3
0
        public void AddTextTest1()
        {
            IXLWorksheet ws         = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLCell      cell       = ws.Cell(1, 1);
            IXLRichText  richString = cell.RichText;

            string text = "Hello";

            richString.AddText(text).SetBold().SetFontColor(XLColor.Red);

            Assert.AreEqual(cell.GetString(), text);
            Assert.AreEqual(cell.RichText.First().Bold, true);
            Assert.AreEqual(cell.RichText.First().FontColor, XLColor.Red);

            Assert.AreEqual(1, richString.Count);

            richString.AddText("World");
            Assert.AreEqual(richString.First().Text, text, "Item in collection is not the same as the one returned");
        }
示例#4
0
        public void Substring_From_OneString_Middle()
        {
            IXLWorksheet ws         = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLRichText  richString = ws.Cell(1, 1).RichText;

            richString.AddText("Hello");

            IXLFormattedText <IXLRichText> actual = richString.Substring(2, 2);

            Assert.AreEqual(1, actual.Count);     // substring was in one piece

            Assert.AreEqual(3, richString.Count); // The text was split because of the substring

            Assert.AreEqual("ll", actual.First().Text);

            Assert.AreEqual("He", richString.First().Text);
            Assert.AreEqual("ll", richString.ElementAt(1).Text);
            Assert.AreEqual("o", richString.Last().Text);

            actual.First().SetBold();

            Assert.AreEqual(false, ws.Cell(1, 1).RichText.First().Bold);
            Assert.AreEqual(true, ws.Cell(1, 1).RichText.ElementAt(1).Bold);
            Assert.AreEqual(false, ws.Cell(1, 1).RichText.Last().Bold);

            richString.Last().SetItalic();

            Assert.AreEqual(false, ws.Cell(1, 1).RichText.First().Italic);
            Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(1).Italic);
            Assert.AreEqual(true, ws.Cell(1, 1).RichText.Last().Italic);

            Assert.AreEqual(false, actual.First().Italic);

            richString.SetFontSize(20);

            Assert.AreEqual(20, ws.Cell(1, 1).RichText.First().FontSize);
            Assert.AreEqual(20, ws.Cell(1, 1).RichText.ElementAt(1).FontSize);
            Assert.AreEqual(20, ws.Cell(1, 1).RichText.Last().FontSize);

            Assert.AreEqual(20, actual.First().FontSize);
        }