Skip to content

Commit

Permalink
ExcelReader/Writer/Schema: Honor font strikeout style in RichText run…
Browse files Browse the repository at this point in the history
…s (unvell/ReoGrid PR unvell#367) / _* in number formats lead to wrong number of fractional digits (unvell/ReoGrid PR unvell#336)
  • Loading branch information
datadiode committed Dec 30, 2020
1 parent 7d8b8eb commit 38db9b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ReoGrid/IO/ExcelReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,13 +1553,11 @@ private static NumberDataFormatter.INumberFormatArgs ReadNumberFormatArgs(string
pattern = pattern.Substring(1, pattern.Length - 2);
}

int len = pattern.Length;

int decimalSeparatorIndex = pattern.LastIndexOf(ExcelWriter.EnglishCulture.NumberFormat.NumberDecimalSeparator, len - 1);

if (decimalSeparatorIndex >= 0 && decimalSeparatorIndex < len - 1)
int decimalSeparatorIndex = pattern.LastIndexOf(ExcelWriter.EnglishCulture.NumberFormat.NumberDecimalSeparator);
int lastDecimalIndex = pattern.LastIndexOf("0");
if (decimalSeparatorIndex >= 0 && decimalSeparatorIndex < lastDecimalIndex)
{
arg.DecimalPlaces = (short)(len - 1 - decimalSeparatorIndex);
arg.DecimalPlaces = (short)(lastDecimalIndex - decimalSeparatorIndex);
}
else
{
Expand Down Expand Up @@ -2507,6 +2505,11 @@ private static void AddRunIntoRichText(Document doc, RichText rt, Run r)
foreColor = doc.ConvertFromCompColor(rpr.solidFill);
}

if (rpr.strike != null)
{
fontStyles |= Drawing.Text.FontStyles.Strikethrough;
}

if (rpr.b != null)
{
fontStyles |= Drawing.Text.FontStyles.Bold;
Expand Down
3 changes: 3 additions & 0 deletions ReoGrid/IO/ExcelSchame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,9 @@ public class RunProperty
[XmlElement("sz")]
public ElementValue<string> size;

[XmlElement("strike")]
public ElementValue<string> strike;

[XmlElement("b")]
public ElementValue<string> b;

Expand Down
5 changes: 5 additions & 0 deletions ReoGrid/IO/ExcelWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,11 @@ private static int AddSharedString(Document doc, Drawing.RichText rt)
//schema = "minor",
};

if ((r.FontStyles & Drawing.Text.FontStyles.Bold) == Drawing.Text.FontStyles.Strikethrough)
{
rpr.strike = new ElementValue<string>();
}

if ((r.FontStyles & Drawing.Text.FontStyles.Bold) == Drawing.Text.FontStyles.Bold)
{
rpr.b = new ElementValue<string>();
Expand Down

0 comments on commit 38db9b3

Please sign in to comment.