示例#1
0
        public IXLFormattedText <T> Substring(Int32 index, Int32 length)
        {
            if (index + 1 > Length || (Length - index + 1) < length || length <= 0)
            {
                throw new IndexOutOfRangeException("Index and length must refer to a location within the string.");
            }

            List <IXLRichString> newRichTexts = new List <IXLRichString>();
            var retVal = new XLFormattedText <T>(_defaultFont);

            Int32 lastPosition = 0;

            foreach (var rt in _richTexts)
            {
                if (lastPosition >= index + 1 + length) // We already have what we need
                {
                    newRichTexts.Add(rt);
                }
                else if (lastPosition + rt.Text.Length >= index + 1) // Eureka!
                {
                    Int32 startIndex = index - lastPosition;

                    if (startIndex > 0)
                    {
                        newRichTexts.Add(new XLRichString(rt.Text.Substring(0, startIndex), rt, this));
                    }
                    else if (startIndex < 0)
                    {
                        startIndex = 0;
                    }

                    Int32 leftToTake = length - retVal.Length;
                    if (leftToTake > rt.Text.Length - startIndex)
                    {
                        leftToTake = rt.Text.Length - startIndex;
                    }

                    XLRichString newRt = new XLRichString(rt.Text.Substring(startIndex, leftToTake), rt, this);
                    newRichTexts.Add(newRt);
                    retVal.AddText(newRt);

                    if (startIndex + leftToTake < rt.Text.Length)
                    {
                        newRichTexts.Add(new XLRichString(rt.Text.Substring(startIndex + leftToTake), rt, this));
                    }
                }
                else // We haven't reached the desired position yet
                {
                    newRichTexts.Add(rt);
                }
                lastPosition += rt.Text.Length;
            }
            _richTexts = newRichTexts;
            return(retVal);
        }
示例#2
0
        public IXLRichString AddText(String text, XLHFOccurrence occurrence)
        {
            XLRichString richText = new XLRichString(text, XLWorkbook.DefaultStyle.Font, this);

            var hfText = new XLHFText(richText, _worksheet);
            if (occurrence == XLHFOccurrence.AllPages)
            {
                AddTextToOccurrence(hfText, XLHFOccurrence.EvenPages);
                AddTextToOccurrence(hfText, XLHFOccurrence.FirstPage);
                AddTextToOccurrence(hfText, XLHFOccurrence.OddPages);
            }
            else
            {
                AddTextToOccurrence(hfText, occurrence);
            }

            return richText;
        }
示例#3
0
        public IXLRichString AddText(String text, XLHFOccurrence occurrence)
        {
            XLRichString richText = new XLRichString(text, XLWorkbook.DefaultStyle.Font, this);

            var hfText = new XLHFText(richText, _worksheet);

            if (occurrence == XLHFOccurrence.AllPages)
            {
                AddTextToOccurrence(hfText, XLHFOccurrence.EvenPages);
                AddTextToOccurrence(hfText, XLHFOccurrence.FirstPage);
                AddTextToOccurrence(hfText, XLHFOccurrence.OddPages);
            }
            else
            {
                AddTextToOccurrence(hfText, occurrence);
            }

            return(richText);
        }
示例#4
0
 public XLHFText(XLRichString richText, XLHFItem hfItem)
 {
     RichText = richText;
     _hfItem  = hfItem;
 }
示例#5
0
        public IXLRichString AddText(String text, IXLFontBase font)
        {
            var richText = new XLRichString(text, font, this);

            return(AddText(richText));
        }
示例#6
0
 public XLHFText(XLRichString richText, XLWorksheet worksheet)
 {
     RichText = richText;
     _worksheet = worksheet;
 }
示例#7
0
 public XLHFText(XLRichString richText, XLWorksheet worksheet)
 {
     RichText   = richText;
     _worksheet = worksheet;
 }