Browse Source

Merge pull request #2069 in CORE/base-third from release/10.0 to feature/10.0

* commit 'a5aee3a7d9d415c420cf7c1bbfafc1a05e6f2453':
  REPORT-50649 导出-生僻字导出问题 Excel导出
feature/10.0
superman 4 years ago
parent
commit
22c46929e0
  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:
// YK: XmlBeans silently replaces all ISO control characters ( < 32) with question marks.
// the same rule applies to unicode surrogates and "not a character" symbols.
if( c < ' ' || Character.isLowSurrogate(c) || Character.isHighSurrogate(c) ||
('\uFFFE' <= c && c <= '\uFFFF')) {
// Excel SXSSF deals with special chars.
// 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) {
sb.append(chars, last, counter - last);
}
sb.append('?');
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) {
if (counter > last) {
sb.append(chars, last, counter - last);
@ -412,4 +420,8 @@ public class SheetDataWriter {
_out.close();
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();
}
/**
* 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 ( )
{
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
*/
@ -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 )
{
// TODO: systemId production http://www.w3.org/TR/REC-xml/#NT-SystemLiteral

Loading…
Cancel
Save