Browse Source

Pull request #2052: REPORT-50649 导出-生僻字导出问题 Excel导出 - by Joe.Jiang

Merge in CORE/base-third from ~BRUCE.DENG/base-third:release/10.0 to release/10.0

* commit 'f5c89564c91b874d9a37ab875ab4947c8e882144':
  REPORT-50649 导出-生僻字导出问题 Excel导出
release/10.0
Bruce.Deng 4 years ago
parent
commit
a5aee3a7d9
  1. 16
      fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/streaming/SheetDataWriter.java
  2. 46
      fine-poi/src/main/java/com/fr/third/v2/org/apache/xmlbeans/impl/store/Saver.java

16
fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/streaming/SheetDataWriter.java

@ -377,14 +377,22 @@ public class SheetDataWriter {
default: default:
// YK: XmlBeans silently replaces all ISO control characters ( < 32) with question marks. // YK: XmlBeans silently replaces all ISO control characters ( < 32) with question marks.
// the same rule applies to unicode surrogates and "not a character" symbols. // the same rule applies to unicode surrogates and "not a character" symbols.
if( c < ' ' || Character.isLowSurrogate(c) || Character.isHighSurrogate(c) || // Excel SXSSF deals with special chars.
('\uFFFE' <= c && c <= '\uFFFF')) { // https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java?r1=1791720&r2=1800705&pathrev=1800705&diff_format=f
if (replaceWithQuestionMark(c)) {
if (counter > last) { if (counter > last) {
sb.append(chars, last, counter - last); sb.append(chars, last, counter - last);
} }
sb.append('?'); sb.append('?');
last = counter + 1; last = counter + 1;
} }
else if (Character.isHighSurrogate(c) || Character.isLowSurrogate(c)) {
if (counter > last) {
sb.append(chars, last, counter - last);
}
sb.append(c);
last = counter + 1;
}
else if (c > 127) { else if (c > 127) {
if (counter > last) { if (counter > last) {
sb.append(chars, last, counter - last); sb.append(chars, last, counter - last);
@ -412,4 +420,8 @@ public class SheetDataWriter {
_out.close(); _out.close();
return _fd.delete(); return _fd.delete();
} }
private boolean replaceWithQuestionMark(char c) {
return c < ' ' || '\uFFFE' <= c;
}
} }

46
fine-poi/src/main/java/com/fr/third/v2/org/apache/xmlbeans/impl/store/Saver.java

@ -273,6 +273,23 @@ abstract class Saver
end.toEnd(); end.toEnd();
} }
/**
* Test if a character is valid in xml character content. See
* http://www.w3.org/TR/REC-xml#NT-Char
* Excel XSSF deals with special chars.
* https://svn.apache.org/viewvc/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Saver.java?r1=1025773&r2=1832298&pathrev=1832298&diff_format=h
*/
static boolean isBadChar ( char ch )
{
return ! (
Character.isHighSurrogate(ch) ||
Character.isLowSurrogate(ch) ||
(ch >= 0x20 && ch <= 0xD7FF) ||
(ch >= 0xE000 && ch <= 0xFFFD) ||
(ch == 0x9) || (ch == 0xA) || (ch == 0xD)
);
}
protected boolean saveNamespacesFirst ( ) protected boolean saveNamespacesFirst ( )
{ {
return _saveNamespacesFirst; return _saveNamespacesFirst;
@ -1548,21 +1565,6 @@ abstract class Saver
} }
} }
/**
* Test if a character is valid in xml character content. See
* http://www.w3.org/TR/REC-xml#NT-Char
*/
private boolean isBadChar ( char ch )
{
return ! (
(ch >= 0x20 && ch <= 0xD7FF ) ||
(ch >= 0xE000 && ch <= 0xFFFD) ||
(ch >= 0x10000 && ch <= 0x10FFFF) ||
(ch == 0x9) || (ch == 0xA) || (ch == 0xD)
);
}
/** /**
* Test if a character is to be replaced with an escaped value * Test if a character is to be replaced with an escaped value
*/ */
@ -2187,20 +2189,6 @@ abstract class Saver
} }
} }
/**
* Test if a character is valid in xml character content. See
* http://www.w3.org/TR/REC-xml#NT-Char
*/
private boolean isBadChar ( char ch )
{
return ! (
(ch >= 0x20 && ch <= 0xD7FF ) ||
(ch >= 0xE000 && ch <= 0xFFFD) ||
(ch >= 0x10000 && ch <= 0x10FFFF) ||
(ch == 0x9) || (ch == 0xA) || (ch == 0xD)
);
}
private void emitLiteral ( String literal ) private void emitLiteral ( String literal )
{ {
// TODO: systemId production http://www.w3.org/TR/REC-xml/#NT-SystemLiteral // TODO: systemId production http://www.w3.org/TR/REC-xml/#NT-SystemLiteral

Loading…
Cancel
Save