Excel accepts some characters whereas OpenXml has error

爱⌒轻易说出口 提交于 2019-12-21 22:32:10

问题


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.


回答1:


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]



来源:https://stackoverflow.com/questions/43094662/excel-accepts-some-characters-whereas-openxml-has-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!