gustavnavar / Grid.Blazor

Grid component with CRUD for Blazor (client-side and server-side) and ASP.NET Core MVC
GNU Lesser General Public License v2.1
696 stars 134 forks source link

Export grid to excel, hexadecimal value 0x1D, is an invalid character. #413

Closed RedSoxXx closed 4 months ago

RedSoxXx commented 4 months ago

If grid row column contains  symbol, export crash the system.

for exmple column string:

0104066752617374215&HY7wBKPSzSF91EE09921+/yC17ohCznulAYWaWbHLL3oHwVY+pvaKsvJZ9i8CI=

gustavnavar commented 4 months ago

I've tried to reproduce this error with a column value "zSF�91EE09�921+/yC17ohC" and everything is working fine.

Are you using WASM or Blazor Server?

Could you send me a project with a grid producing this error?

RedSoxXx commented 4 months ago

@gustavnavar Blazor Server, please try with \ u001d unicode symbol, reproduced only if this unicode simbol in string, if you will not able to reproduce, I will create small project with example

gustavnavar commented 4 months ago

I could reproduce it inserting \u001d unicode character in a text field of the database.

I get this exception:

Unhandled exception rendering component: '', hexadecimal value 0x1D, is an invalid character.
      System.ArgumentException: '', hexadecimal value 0x1D, is an invalid character.
         at System.Xml.XmlUtf8RawTextWriter.InvalidXmlChar(Int32 ch, Byte* pDst, Boolean entitize)
         at System.Xml.XmlUtf8RawTextWriter.WriteElementTextBlock(Char* pSrc, Char* pSrcEnd)
         at System.Xml.XmlUtf8RawTextWriter.WriteString(String text)
         at System.Xml.XmlWellFormedWriter.WriteString(String text)
         at DocumentFormat.OpenXml.OpenXmlLeafTextElement.WriteContentTo(XmlWriter w)
         at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
         at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
         at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
         at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
         at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
         at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
         at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
         at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
         at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
         at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
         at DocumentFormat.OpenXml.OpenXmlPartRootElement.WriteTo(XmlWriter xmlWriter)
         at DocumentFormat.OpenXml.OpenXmlPartRootElement.Save(Stream stream)
         at DocumentFormat.OpenXml.OpenXmlPartRootElement.SaveToPart(OpenXmlPart openXmlPart)
         at DocumentFormat.OpenXml.OpenXmlPartRootElement.Save()
         at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.TrySavePartContent(OpenXmlPart part)
         at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.SavePartContents(Boolean save)
         at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose(Boolean disposing)
         at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose()
         at GridBlazor.ExcelWriter.GenerateExcel(ExcelData data) in C:\Users\GustauNavarro\source\repos\Grid.Blazor\GridBlazor\ExcelWriter.cs:line 201
         at GridBlazor.ExcelWriter.GenerateExcel[T](IGridColumnCollection`1 columns, IEnumerable`1 items) in C:\Users\GustauNavarro\source\repos\Grid.Blazor\GridBlazor\ExcelWriter.cs:line 168
gustavnavar commented 4 months ago

Package 5.0.12 cleans all excel cell content (remove all XML invalid characters) before export is done.