示例#1
0
        public void Substring_From_ThreeStrings_Mid2()
        {
            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(5, 15);

            Assert.AreEqual(3, actual.Count);

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

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

            Assert.AreEqual("Good ", richString.ElementAt(0).Text);
            Assert.AreEqual("Morning", richString.ElementAt(1).Text);
            Assert.AreEqual(" my ", richString.ElementAt(2).Text);
            Assert.AreEqual("neig", richString.ElementAt(3).Text);
            Assert.AreEqual("hbors!", richString.ElementAt(4).Text);
        }
示例#2
0
        public void Substring_IndexOutsideRange3()
        {
            IXLWorksheet ws         = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLRichText  richString = ws.Cell(1, 1).RichText;

            richString.AddText("Hello");

            Assert.That(() => richString.Substring(1, 10), Throws.TypeOf <IndexOutOfRangeException>());
        }
示例#3
0
        public void Substring_IndexOutsideRange3()
        {
            IXLWorksheet ws         = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLRichText  richString = ws.Cell(1, 1).RichText;

            richString.AddText("Hello");

            IXLFormattedText <IXLRichText> richText = richString.Substring(1, 10);
        }
示例#4
0
        public void CountTest()
        {
            IXLWorksheet ws         = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLRichText  richString = ws.Cell(1, 1).RichText;

            richString.AddText("Hello");
            richString.AddText(" ");
            richString.AddText("World!");

            Assert.AreEqual(3, richString.Count);
        }
示例#5
0
        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);
        }
示例#6
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);
        }
示例#7
0
        public void ClearTest()
        {
            IXLWorksheet ws         = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLRichText  richString = ws.Cell(1, 1).RichText;

            richString.AddText("Hello");
            richString.AddText(" ");
            richString.AddText("World!");

            richString.ClearText();
            String expected = String.Empty;
            String actual   = richString.ToString();

            Assert.AreEqual(expected, actual);

            Assert.AreEqual(0, richString.Count);
        }
示例#8
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");
        }
示例#9
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);
        }
示例#10
0
        public void AccessRichTextTest1()
        {
            IXLWorksheet ws   = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLCell      cell = ws.Cell(1, 1);

            cell.RichText.AddText("12");
            cell.DataType = XLCellValues.Number;

            Assert.AreEqual(12.0, cell.GetDouble());

            IXLRichText richText = cell.RichText;

            Assert.AreEqual("12", richText.ToString());

            richText.AddText("34");

            Assert.AreEqual("1234", cell.GetString());

            Assert.AreEqual(XLCellValues.Number, cell.DataType);

            Assert.AreEqual(1234.0, cell.GetDouble());
        }
示例#11
0
        public void Substring_All_From_ThreeStrings()
        {
            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);

            Assert.AreEqual(richString.ElementAt(0), actual.ElementAt(0));
            Assert.AreEqual(richString.ElementAt(1), actual.ElementAt(1));
            Assert.AreEqual(richString.ElementAt(2), actual.ElementAt(2));

            Assert.AreEqual(3, actual.Count);
            Assert.AreEqual(3, richString.Count);

            actual.First().SetBold();

            Assert.AreEqual(true, ws.Cell(1, 1).RichText.First().Bold);
            Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(1).Bold);
            Assert.AreEqual(false, ws.Cell(1, 1).RichText.Last().Bold);
        }
 private static void SetChemicalFormula(IXLRichText text, string formula)
 {
     text.ClearText();
     foreach (var item in formula.ToCharArray())
     {
         var current = text.AddText(item.ToString());
         if (Regex.IsMatch(item.ToString(), @"\d"))
         {
             current.VerticalAlignment = XLFontVerticalTextAlignmentValues.Subscript;
         }
     }
 }