diff --git a/GridBlazor/ExcelWriter.cs b/GridBlazor/ExcelWriter.cs index b2b069b1..123ccd4b 100644 --- a/GridBlazor/ExcelWriter.cs +++ b/GridBlazor/ExcelWriter.cs @@ -14,7 +14,14 @@ namespace GridBlazor { public class ExcelCell { - public string Content { get; set; } + private string _content; + + public string Content { + get { return _content; } + set { + _content = RemoveInvalidXmlChars(value); + } + } public int ColumnIndex { get; set; } public int RowIndex { get; set; } public int ColSpan { get; set; } @@ -46,6 +53,11 @@ public ExcelCell(string value, Type type = null) else Type = CellValues.InlineString; } + + private string RemoveInvalidXmlChars(string content) + { + return new string(content.Where(ch => System.Xml.XmlConvert.IsXmlChar(ch)).ToArray()); + } } public class ExcelStatus