diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
index 48bee04..be87678 100644
--- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
@@ -157,6 +157,8 @@
+
+
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs
index 773a0a4..4d3b727 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs
@@ -3,41 +3,8 @@
namespace ClosedXML.Excel
{
- public interface IXLComment: IXLDrawing, IEnumerable, IEquatable
+ public interface IXLComment : IXLFormattedText
{
- Boolean Bold { set; }
- Boolean Italic { set; }
- XLFontUnderlineValues Underline { set; }
- Boolean Strikethrough { set; }
- XLFontVerticalTextAlignmentValues VerticalAlignment { set; }
- Boolean Shadow { set; }
- Double FontSize { set; }
- IXLColor FontColor { set; }
- String FontName { set; }
- XLFontFamilyNumberingValues FontFamilyNumbering { set; }
-
- IXLComment SetBold(); IXLComment SetBold(Boolean value);
- IXLComment SetItalic(); IXLComment SetItalic(Boolean value);
- IXLComment SetUnderline(); IXLComment SetUnderline(XLFontUnderlineValues value);
- IXLComment SetStrikethrough(); IXLComment SetStrikethrough(Boolean value);
- IXLComment SetVerticalAlignment(XLFontVerticalTextAlignmentValues value);
- IXLComment SetShadow(); IXLComment SetShadow(Boolean value);
- IXLComment SetFontSize(Double value);
- IXLComment SetFontColor(IXLColor value);
- IXLComment SetFontName(String value);
- IXLComment SetFontFamilyNumbering(XLFontFamilyNumberingValues value);
-
- IXLRichString AddText(String text);
- IXLRichString AddText(String text, IXLFontBase font);
- IXLComment ClearText();
- IXLComment ClearFont();
- IXLComment Substring(Int32 index);
- IXLComment Substring(Int32 index, Int32 length);
- Int32 Count { get; }
- Int32 Length { get; }
-
- String Text { get; }
- IXLPhonetics Phonetics { get; }
- Boolean HasPhonetics { get; }
}
+
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs
index ee929cf..e6e4ff6 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs
@@ -5,181 +5,27 @@
namespace ClosedXML.Excel
{
- internal class XLComment: XLDrawing, IXLComment
+ internal class XLComment : XLFormattedText, IXLComment
{
- List _richTexts = new List();
- readonly IXLFontBase _defaultFont;
public XLComment(IXLFontBase defaultFont)
+ : base(defaultFont)
{
- Length = 0;
- _defaultFont = defaultFont;
Container = this;
}
- public XLComment(IXLComment defaultComment, IXLFontBase defaultFont)
- :this(defaultFont)
+ public XLComment(XLFormattedText defaultComment, IXLFontBase defaultFont)
+ : base(defaultComment, defaultFont)
{
- foreach (var rt in defaultComment)
- AddText(rt.Text, rt);
- if (defaultComment.HasPhonetics)
- {
- _phonetics = new XLPhonetics(defaultComment.Phonetics, defaultFont);
- }
-
+ Container = this;
}
public XLComment(String text, IXLFontBase defaultFont)
- :this(defaultFont)
+ : base(text, defaultFont)
{
- AddText(text);
+ Container = this;
}
- public Int32 Count { get { return _richTexts.Count; } }
- public int Length { get; private set; }
-
- public IXLRichString AddText(String text)
- {
- return AddText(text, _defaultFont);
- }
- public IXLRichString AddText(String text, IXLFontBase font)
- {
- var richText = new XLRichString(text, font);
- return AddText(richText);
- }
-
- public IXLRichString AddText(IXLRichString richText)
- {
- _richTexts.Add(richText);
- Length += richText.Text.Length;
- return richText;
- }
- public IXLComment ClearText()
- {
- _richTexts.Clear();
- Length = 0;
- return Container;
- }
- public IXLComment ClearFont()
- {
- String text = Text;
- ClearText();
- AddText(text);
- return Container;
- }
-
- public override string ToString()
- {
- var sb = new StringBuilder(_richTexts.Count);
- _richTexts.ForEach(rt => sb.Append(rt.Text));
- return sb.ToString();
- }
-
- public IXLComment Substring(Int32 index)
- {
- return Substring(index, Length - index);
- }
- public IXLComment 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 newRichTexts = new List();
- XLComment retVal = new XLComment(_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));
- 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);
- newRichTexts.Add(newRt);
- retVal.AddText(newRt);
-
- if (startIndex + leftToTake < rt.Text.Length)
- newRichTexts.Add(new XLRichString(rt.Text.Substring(startIndex + leftToTake), rt));
- }
- else // We haven't reached the desired position yet
- {
- newRichTexts.Add(rt);
- }
- lastPosition += rt.Text.Length;
- }
- _richTexts = newRichTexts;
- return retVal;
- }
-
- public IEnumerator GetEnumerator()
- {
- return _richTexts.GetEnumerator();
- }
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public Boolean Bold { set { _richTexts.ForEach(rt => rt.Bold = value); } }
- public Boolean Italic { set { _richTexts.ForEach(rt => rt.Italic = value); } }
- public XLFontUnderlineValues Underline { set { _richTexts.ForEach(rt => rt.Underline = value); } }
- public Boolean Strikethrough { set { _richTexts.ForEach(rt => rt.Strikethrough = value); } }
- public XLFontVerticalTextAlignmentValues VerticalAlignment { set { _richTexts.ForEach(rt => rt.VerticalAlignment = value); } }
- public Boolean Shadow { set { _richTexts.ForEach(rt => rt.Shadow = value); } }
- public Double FontSize { set { _richTexts.ForEach(rt => rt.FontSize = value); } }
- public IXLColor FontColor { set { _richTexts.ForEach(rt => rt.FontColor = value); } }
- public String FontName { set { _richTexts.ForEach(rt => rt.FontName = value); } }
- public XLFontFamilyNumberingValues FontFamilyNumbering { set { _richTexts.ForEach(rt => rt.FontFamilyNumbering = value); } }
-
- public IXLComment SetBold() { Bold = true; return Container; } public IXLComment SetBold(Boolean value) { Bold = value; return Container; }
- public IXLComment SetItalic() { Italic = true; return Container; } public IXLComment SetItalic(Boolean value) { Italic = value; return Container; }
- public IXLComment SetUnderline() { Underline = XLFontUnderlineValues.Single; return Container; } public IXLComment SetUnderline(XLFontUnderlineValues value) { Underline = value; return Container; }
- public IXLComment SetStrikethrough() { Strikethrough = true; return Container; } public IXLComment SetStrikethrough(Boolean value) { Strikethrough = value; return Container; }
- public IXLComment SetVerticalAlignment(XLFontVerticalTextAlignmentValues value) { VerticalAlignment = value; return Container; }
- public IXLComment SetShadow() { Shadow = true; return Container; } public IXLComment SetShadow(Boolean value) { Shadow = value; return Container; }
- public IXLComment SetFontSize(Double value) { FontSize = value; return Container; }
- public IXLComment SetFontColor(IXLColor value) { FontColor = value; return Container; }
- public IXLComment SetFontName(String value) { FontName = value; return Container; }
- public IXLComment SetFontFamilyNumbering(XLFontFamilyNumberingValues value) { FontFamilyNumbering = value; return Container; }
-
- public bool Equals(IXLComment other)
- {
- Int32 count = Count;
- if (count != other.Count)
- return false;
-
- for (Int32 i = 0; i < count; i++)
- {
- if (_richTexts.ElementAt(i) != other.ElementAt(i))
- return false;
- }
-
- return _phonetics == null || Phonetics.Equals(other.Phonetics);
- }
-
- public String Text { get { return ToString(); } }
-
- private IXLPhonetics _phonetics;
- public IXLPhonetics Phonetics
- {
- get { return _phonetics ?? (_phonetics = new XLPhonetics(_defaultFont)); }
- }
-
- public Boolean HasPhonetics { get { return _phonetics != null; } }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLFormattedText.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLFormattedText.cs
new file mode 100644
index 0000000..70f1c93
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLFormattedText.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+
+namespace ClosedXML.Excel
+{
+ public interface IXLFormattedText : IEnumerable, IEquatable>
+ {
+ Boolean Bold { set; }
+ Boolean Italic { set; }
+ XLFontUnderlineValues Underline { set; }
+ Boolean Strikethrough { set; }
+ XLFontVerticalTextAlignmentValues VerticalAlignment { set; }
+ Boolean Shadow { set; }
+ Double FontSize { set; }
+ IXLColor FontColor { set; }
+ String FontName { set; }
+ XLFontFamilyNumberingValues FontFamilyNumbering { set; }
+
+ IXLFormattedText SetBold(); IXLFormattedText SetBold(Boolean value);
+ IXLFormattedText SetItalic(); IXLFormattedText SetItalic(Boolean value);
+ IXLFormattedText SetUnderline(); IXLFormattedText SetUnderline(XLFontUnderlineValues value);
+ IXLFormattedText SetStrikethrough(); IXLFormattedText SetStrikethrough(Boolean value);
+ IXLFormattedText SetVerticalAlignment(XLFontVerticalTextAlignmentValues value);
+ IXLFormattedText SetShadow(); IXLFormattedText SetShadow(Boolean value);
+ IXLFormattedText SetFontSize(Double value);
+ IXLFormattedText SetFontColor(IXLColor value);
+ IXLFormattedText SetFontName(String value);
+ IXLFormattedText SetFontFamilyNumbering(XLFontFamilyNumberingValues value);
+
+ IXLRichString AddText(String text);
+ IXLRichString AddText(String text, IXLFontBase font);
+ IXLFormattedText ClearText();
+ IXLFormattedText ClearFont();
+ IXLFormattedText Substring(Int32 index);
+ IXLFormattedText Substring(Int32 index, Int32 length);
+ Int32 Count { get; }
+ Int32 Length { get; }
+
+ String Text { get; }
+ IXLPhonetics Phonetics { get; }
+ Boolean HasPhonetics { get; }
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLRichText.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLRichText.cs
index 9832a7e..36ac6fc 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLRichText.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLRichText.cs
@@ -3,41 +3,7 @@
namespace ClosedXML.Excel
{
- public interface IXLRichText : IEnumerable, IEquatable
+ public interface IXLRichText : IXLFormattedText
{
- Boolean Bold { set; }
- Boolean Italic { set; }
- XLFontUnderlineValues Underline { set; }
- Boolean Strikethrough { set; }
- XLFontVerticalTextAlignmentValues VerticalAlignment { set; }
- Boolean Shadow { set; }
- Double FontSize { set; }
- IXLColor FontColor { set; }
- String FontName { set; }
- XLFontFamilyNumberingValues FontFamilyNumbering { set; }
-
- IXLRichText SetBold(); IXLRichText SetBold(Boolean value);
- IXLRichText SetItalic(); IXLRichText SetItalic(Boolean value);
- IXLRichText SetUnderline(); IXLRichText SetUnderline(XLFontUnderlineValues value);
- IXLRichText SetStrikethrough(); IXLRichText SetStrikethrough(Boolean value);
- IXLRichText SetVerticalAlignment(XLFontVerticalTextAlignmentValues value);
- IXLRichText SetShadow(); IXLRichText SetShadow(Boolean value);
- IXLRichText SetFontSize(Double value);
- IXLRichText SetFontColor(IXLColor value);
- IXLRichText SetFontName(String value);
- IXLRichText SetFontFamilyNumbering(XLFontFamilyNumberingValues value);
-
- IXLRichString AddText(String text);
- IXLRichString AddText(String text, IXLFontBase font);
- IXLRichText ClearText();
- IXLRichText ClearFont();
- IXLRichText Substring(Int32 index);
- IXLRichText Substring(Int32 index, Int32 length);
- Int32 Count { get; }
- Int32 Length { get; }
-
- String Text { get; }
- IXLPhonetics Phonetics { get; }
- Boolean HasPhonetics { get; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLFormattedText.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLFormattedText.cs
new file mode 100644
index 0000000..6c879d1
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLFormattedText.cs
@@ -0,0 +1,183 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Linq;
+
+namespace ClosedXML.Excel
+{
+ internal class XLFormattedText: IXLFormattedText
+ {
+ List _richTexts = new List();
+
+ protected T Container;
+ readonly IXLFontBase _defaultFont;
+ public XLFormattedText(IXLFontBase defaultFont)
+ {
+ Length = 0;
+ _defaultFont = defaultFont;
+ }
+
+ public XLFormattedText(IXLFormattedText defaultRichText, IXLFontBase defaultFont)
+ : this(defaultFont)
+ {
+ foreach (var rt in defaultRichText)
+ AddText(rt.Text, rt);
+ if (defaultRichText.HasPhonetics)
+ {
+ _phonetics = new XLPhonetics(defaultRichText.Phonetics, defaultFont);
+ }
+ }
+
+ public XLFormattedText(String text, IXLFontBase defaultFont)
+ :this(defaultFont)
+ {
+ AddText(text);
+ }
+
+ public Int32 Count { get { return _richTexts.Count; } }
+ public int Length { get; private set; }
+
+ public IXLRichString AddText(String text)
+ {
+ return AddText(text, _defaultFont);
+ }
+ public IXLRichString AddText(String text, IXLFontBase font)
+ {
+ var richText = new XLRichString(text, font);
+ return AddText(richText);
+ }
+
+ public IXLRichString AddText(IXLRichString richText)
+ {
+ _richTexts.Add(richText);
+ Length += richText.Text.Length;
+ return richText;
+ }
+ public IXLFormattedText ClearText()
+ {
+ _richTexts.Clear();
+ Length = 0;
+ return this;
+ }
+ public IXLFormattedText ClearFont()
+ {
+ String text = Text;
+ ClearText();
+ AddText(text);
+ return this;
+ }
+
+ public override string ToString()
+ {
+ var sb = new StringBuilder(_richTexts.Count);
+ _richTexts.ForEach(rt => sb.Append(rt.Text));
+ return sb.ToString();
+ }
+
+ public IXLFormattedText Substring(Int32 index)
+ {
+ return Substring(index, Length - index);
+ }
+ public IXLFormattedText 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 newRichTexts = new List();
+ var retVal = new XLFormattedText(_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));
+ 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);
+ newRichTexts.Add(newRt);
+ retVal.AddText(newRt);
+
+ if (startIndex + leftToTake < rt.Text.Length)
+ newRichTexts.Add(new XLRichString(rt.Text.Substring(startIndex + leftToTake), rt));
+ }
+ else // We haven't reached the desired position yet
+ {
+ newRichTexts.Add(rt);
+ }
+ lastPosition += rt.Text.Length;
+ }
+ _richTexts = newRichTexts;
+ return retVal;
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return _richTexts.GetEnumerator();
+ }
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ public Boolean Bold { set { _richTexts.ForEach(rt => rt.Bold = value); } }
+ public Boolean Italic { set { _richTexts.ForEach(rt => rt.Italic = value); } }
+ public XLFontUnderlineValues Underline { set { _richTexts.ForEach(rt => rt.Underline = value); } }
+ public Boolean Strikethrough { set { _richTexts.ForEach(rt => rt.Strikethrough = value); } }
+ public XLFontVerticalTextAlignmentValues VerticalAlignment { set { _richTexts.ForEach(rt => rt.VerticalAlignment = value); } }
+ public Boolean Shadow { set { _richTexts.ForEach(rt => rt.Shadow = value); } }
+ public Double FontSize { set { _richTexts.ForEach(rt => rt.FontSize = value); } }
+ public IXLColor FontColor { set { _richTexts.ForEach(rt => rt.FontColor = value); } }
+ public String FontName { set { _richTexts.ForEach(rt => rt.FontName = value); } }
+ public XLFontFamilyNumberingValues FontFamilyNumbering { set { _richTexts.ForEach(rt => rt.FontFamilyNumbering = value); } }
+
+ public IXLFormattedText SetBold() { Bold = true; return this; } public IXLFormattedText SetBold(Boolean value) { Bold = value; return this; }
+ public IXLFormattedText SetItalic() { Italic = true; return this; } public IXLFormattedText SetItalic(Boolean value) { Italic = value; return this; }
+ public IXLFormattedText SetUnderline() { Underline = XLFontUnderlineValues.Single; return this; } public IXLFormattedText SetUnderline(XLFontUnderlineValues value) { Underline = value; return this; }
+ public IXLFormattedText SetStrikethrough() { Strikethrough = true; return this; } public IXLFormattedText SetStrikethrough(Boolean value) { Strikethrough = value; return this; }
+ public IXLFormattedText SetVerticalAlignment(XLFontVerticalTextAlignmentValues value) { VerticalAlignment = value; return this; }
+ public IXLFormattedText SetShadow() { Shadow = true; return this; } public IXLFormattedText SetShadow(Boolean value) { Shadow = value; return this; }
+ public IXLFormattedText SetFontSize(Double value) { FontSize = value; return this; }
+ public IXLFormattedText SetFontColor(IXLColor value) { FontColor = value; return this; }
+ public IXLFormattedText SetFontName(String value) { FontName = value; return this; }
+ public IXLFormattedText SetFontFamilyNumbering(XLFontFamilyNumberingValues value) { FontFamilyNumbering = value; return this; }
+
+ public bool Equals(IXLFormattedText other)
+ {
+ Int32 count = Count;
+ if (count != other.Count)
+ return false;
+
+ for (Int32 i = 0; i < count; i++)
+ {
+ if (_richTexts.ElementAt(i) != other.ElementAt(i))
+ return false;
+ }
+
+ return _phonetics == null || Phonetics.Equals(other.Phonetics);
+ }
+
+ public String Text { get { return ToString(); } }
+
+ private IXLPhonetics _phonetics;
+ public IXLPhonetics Phonetics
+ {
+ get { return _phonetics ?? (_phonetics = new XLPhonetics(_defaultFont)); }
+ }
+
+ public Boolean HasPhonetics { get { return _phonetics != null; } }
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs
index 9418929..7d4c65b 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs
@@ -5,183 +5,26 @@
namespace ClosedXML.Excel
{
- internal class XLRichText: IXLRichText
+ internal class XLRichText: XLFormattedText, IXLRichText
{
- List _richTexts = new List();
-
- readonly IXLFontBase _defaultFont;
+
public XLRichText(IXLFontBase defaultFont)
+ :base(defaultFont)
{
- _defaultFont = defaultFont;
+ Container = this;
}
- public XLRichText(IXLRichText defaultRichText, IXLFontBase defaultFont)
+ public XLRichText(XLFormattedText defaultRichText, IXLFontBase defaultFont)
+ :base(defaultRichText, defaultFont)
{
- _defaultFont = defaultFont;
- foreach (var rt in defaultRichText)
- AddText(rt.Text, rt);
- if (defaultRichText.HasPhonetics)
- {
- _phonetics = new XLPhonetics(defaultRichText.Phonetics, defaultFont);
- }
+ Container = this;
}
public XLRichText(String text, IXLFontBase defaultFont)
- :this(defaultFont)
+ :base(text, defaultFont)
{
- AddText(text);
+ Container = this;
}
- public Int32 Count { get { return _richTexts.Count; } }
- private Int32 _length = 0;
- public Int32 Length
- {
- get
- {
- return _length;
- }
- }
- public IXLRichString AddText(String text)
- {
- return AddText(text, _defaultFont);
- }
- public IXLRichString AddText(String text, IXLFontBase font)
- {
- var richText = new XLRichString(text, font);
- return AddText(richText);
- }
-
- public IXLRichString AddText(IXLRichString richText)
- {
- _richTexts.Add(richText);
- _length += richText.Text.Length;
- return richText;
- }
- public IXLRichText ClearText()
- {
- _richTexts.Clear();
- _length = 0;
- return this;
- }
- public IXLRichText ClearFont()
- {
- String text = Text;
- ClearText();
- AddText(text);
- return this;
- }
-
- public override string ToString()
- {
- var sb = new StringBuilder(_richTexts.Count);
- _richTexts.ForEach(rt => sb.Append(rt.Text));
- return sb.ToString();
- }
-
- public IXLRichText Substring(Int32 index)
- {
- return Substring(index, _length - index);
- }
- public IXLRichText 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 newRichTexts = new List();
- XLRichText retVal = new XLRichText(_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));
- 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);
- newRichTexts.Add(newRt);
- retVal.AddText(newRt);
-
- if (startIndex + leftToTake < rt.Text.Length)
- newRichTexts.Add(new XLRichString(rt.Text.Substring(startIndex + leftToTake), rt));
- }
- else // We haven't reached the desired position yet
- {
- newRichTexts.Add(rt);
- }
- lastPosition += rt.Text.Length;
- }
- _richTexts = newRichTexts;
- return retVal;
- }
-
- public IEnumerator GetEnumerator()
- {
- return _richTexts.GetEnumerator();
- }
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public Boolean Bold { set { _richTexts.ForEach(rt => rt.Bold = value); } }
- public Boolean Italic { set { _richTexts.ForEach(rt => rt.Italic = value); } }
- public XLFontUnderlineValues Underline { set { _richTexts.ForEach(rt => rt.Underline = value); } }
- public Boolean Strikethrough { set { _richTexts.ForEach(rt => rt.Strikethrough = value); } }
- public XLFontVerticalTextAlignmentValues VerticalAlignment { set { _richTexts.ForEach(rt => rt.VerticalAlignment = value); } }
- public Boolean Shadow { set { _richTexts.ForEach(rt => rt.Shadow = value); } }
- public Double FontSize { set { _richTexts.ForEach(rt => rt.FontSize = value); } }
- public IXLColor FontColor { set { _richTexts.ForEach(rt => rt.FontColor = value); } }
- public String FontName { set { _richTexts.ForEach(rt => rt.FontName = value); } }
- public XLFontFamilyNumberingValues FontFamilyNumbering { set { _richTexts.ForEach(rt => rt.FontFamilyNumbering = value); } }
-
- public IXLRichText SetBold() { Bold = true; return this; } public IXLRichText SetBold(Boolean value) { Bold = value; return this; }
- public IXLRichText SetItalic() { Italic = true; return this; } public IXLRichText SetItalic(Boolean value) { Italic = value; return this; }
- public IXLRichText SetUnderline() { Underline = XLFontUnderlineValues.Single; return this; } public IXLRichText SetUnderline(XLFontUnderlineValues value) { Underline = value; return this; }
- public IXLRichText SetStrikethrough() { Strikethrough = true; return this; } public IXLRichText SetStrikethrough(Boolean value) { Strikethrough = value; return this; }
- public IXLRichText SetVerticalAlignment(XLFontVerticalTextAlignmentValues value) { VerticalAlignment = value; return this; }
- public IXLRichText SetShadow() { Shadow = true; return this; } public IXLRichText SetShadow(Boolean value) { Shadow = value; return this; }
- public IXLRichText SetFontSize(Double value) { FontSize = value; return this; }
- public IXLRichText SetFontColor(IXLColor value) { FontColor = value; return this; }
- public IXLRichText SetFontName(String value) { FontName = value; return this; }
- public IXLRichText SetFontFamilyNumbering(XLFontFamilyNumberingValues value) { FontFamilyNumbering = value; return this; }
-
- public bool Equals(IXLRichText other)
- {
- Int32 count = Count;
- if (count != other.Count)
- return false;
-
- for (Int32 i = 0; i < count; i++)
- {
- if (_richTexts.ElementAt(i) != other.ElementAt(i))
- return false;
- }
-
- return _phonetics == null || Phonetics.Equals(other.Phonetics);
- }
-
- public String Text { get { return ToString(); } }
-
- private IXLPhonetics _phonetics;
- public IXLPhonetics Phonetics
- {
- get { return _phonetics ?? (_phonetics = new XLPhonetics(_defaultFont)); }
- }
-
- public Boolean HasPhonetics { get { return _phonetics != null; } }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
index 231cf70..48b9af4 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
@@ -427,6 +427,9 @@
Excel\Ranges\XLRanges.cs
+
+ Excel\RichText\IXLFormattedText.cs
+
Excel\RichText\IXLPhonetic.cs
@@ -439,6 +442,9 @@
Excel\RichText\IXLRichText.cs
+
+ Excel\RichText\XLFormattedText.cs
+
Excel\RichText\XLPhonetic.cs