i have a string that i want to export on excel file with openxml component in C#. My text has '\u001f' character and openxml has error with this character. error text: "hexadecimal value 0x1f, is an invalid character".
i copy that test directly to excel and no problem and copy is success.
Does OpenXml have configs for solving this problem or How i can solve this problem.
thanks.
You need to write it using the format _xHHHH_
where H
represents a hexadecimal character. In your particular instance you need to set the value to "_x001F_"
.
From the documentation for a Cell Value:
The possible values for this element are defined by the ST_Xstring simple type (§22.9.2.19).
In turn, the ST_Xstring
(taken from the ECMA-376 standard) is documented as:
22.9.2.19 ST_Xstring (Escaped String)
String of characters with support for escaped invalid-XML characters.
For all characters which cannot be represented in XML as defined by the XML 1.0 specification, the characters
are escaped using the Unicode numerical character representation escape character format xHHHH, where H
represents a hexadecimal character in the character's value. [Example: The Unicode character 8 is not permitted
in an XML 1.0 document, so it must be escaped as x0008. end example]