Browse Source

Merge pull request #5808 in CORE/base-third from release/11.0 to bugfix/11.0

* commit '2adee25ebf01ebf8d0f99887a9310a63008e3126':
  REPORT-71241 大数据集导出变慢
  REPORT-71241 大数据集导出变慢
  REPORT-71241 大数据集导出变慢
  REPORT-71021 恢复创建线程启停机制
bugfix/KERNEL-11409-jackson
superman 3 years ago
parent
commit
f905edbaa3
  1. 2
      fine-druid/readme.MD
  2. 173
      fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java
  3. 4
      fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/hssf/usermodel/HSSFCell.java
  4. 2
      fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/ss/usermodel/Cell.java
  5. 5
      fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/streaming/SXSSFCell.java
  6. 192
      fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/streaming/SheetDataWriter.java
  7. 4
      fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/usermodel/XSSFCell.java

2
fine-druid/readme.MD

@ -1,4 +1,5 @@
# Alibaba Druid # Alibaba Druid
- FineReport更新时间 `2022-04-27` - FineReport更新时间 `2022-04-27`
- Druid版本 1.2.9 - Druid版本 1.2.9
- [github地址](https://github.com/alibaba/druid) - [github地址](https://github.com/alibaba/druid)
@ -14,3 +15,4 @@
| 1.2.9 | 2022-05-05 | MysqlUtils.getLastPacketReceivedTimeMs根据类加载器区分连接实现等,不在使用全局变量 | | 1.2.9 | 2022-05-05 | MysqlUtils.getLastPacketReceivedTimeMs根据类加载器区分连接实现等,不在使用全局变量 |
| 1.2.9 | 2022-05-05 | com.fr.third.alibaba.druid.util.Utils.loadClass改为优先从线程类加载器加载类 | | 1.2.9 | 2022-05-05 | com.fr.third.alibaba.druid.util.Utils.loadClass改为优先从线程类加载器加载类 |
| 1.2.9 | 2022-05-05 | 恢复com.fr.third.alibaba.druid.pool.DruidDataSourceFactory对hibernate配置属性的支持 | | 1.2.9 | 2022-05-05 | 恢复com.fr.third.alibaba.druid.pool.DruidDataSourceFactory对hibernate配置属性的支持 |
| 1.2.9 | 2022-05-10 | 恢复DruidDataSource中的创建线程启停机制 |

173
fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java

@ -134,6 +134,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
private volatile Future<?> createSchedulerFuture; private volatile Future<?> createSchedulerFuture;
private CreateConnectionThread createConnectionThread; private CreateConnectionThread createConnectionThread;
private PeriodDetectionThread periodDetectionThread;
private DestroyConnectionThread destroyConnectionThread; private DestroyConnectionThread destroyConnectionThread;
private LogStatsThread logStatsThread; private LogStatsThread logStatsThread;
private int createTaskCount; private int createTaskCount;
@ -141,7 +142,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
private volatile long createTaskIdSeed = 1L; private volatile long createTaskIdSeed = 1L;
private long[] createTasks; private long[] createTasks;
private final CountDownLatch initedLatch = new CountDownLatch(2); private CountDownLatch initedLatch = new CountDownLatch(2);
private volatile boolean enable = true; private volatile boolean enable = true;
@ -161,6 +162,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public static ThreadLocal<Long> waitNanosLocal = new ThreadLocal<Long>(); public static ThreadLocal<Long> waitNanosLocal = new ThreadLocal<Long>();
private boolean logDifferentThread = true; private boolean logDifferentThread = true;
private volatile boolean keepAlive = false; private volatile boolean keepAlive = false;
private SQLException initException = null;
private boolean asyncInit = false; private boolean asyncInit = false;
protected boolean killWhenSocketReadTimeout = false; protected boolean killWhenSocketReadTimeout = false;
protected boolean checkExecuteTime = false; protected boolean checkExecuteTime = false;
@ -526,6 +528,45 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
} }
private synchronized void doSomethingBeforeCreationThreadBreak() {
String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(this) + this.getUrl();
createConnectionThread = new CreateConnectionThread(threadName);
createConnectionThread.setStarted(false);
String destroyName = "Druid-ConnectionPool-Destroy-" + System.identityHashCode(this) + this.getUrl();
if (destroyConnectionThread != null) {
if (!destroyConnectionThread.isInterrupted()) {
destroyConnectionThread.interrupt();
}
}
destroyConnectionThread = new DestroyConnectionThread(destroyName);
destroyConnectionThread.setStarted(false);
initedLatch = new CountDownLatch(2);
}
private void checkThread() throws SQLException {
if (createConnectionThread == null) {
throw new IllegalStateException("createConnectionThread not start!");
}
if (destroyConnectionThread == null) {
throw new IllegalStateException("destroyConnectionThread not start!");
}
if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) {
synchronized (this) {//线程安全问题,加个双检锁
if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) {
createConnectionThread.setStarted(true);
createConnectionThread.start();
destroyConnectionThread.setStarted(true);
destroyConnectionThread.start();
try {
initedLatch.await();
} catch (InterruptedException e) {
throw new SQLException(e.getMessage(), e);
}
}
}
}
}
public boolean isKillWhenSocketReadTimeout() { public boolean isKillWhenSocketReadTimeout() {
return killWhenSocketReadTimeout; return killWhenSocketReadTimeout;
} }
@ -798,6 +839,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
public void init() throws SQLException { public void init() throws SQLException {
if (initException != null) {
LOG.error("{dataSource-" + this.getID() + "} init error", initException);
throw initException;
}
if (inited) { if (inited) {
return; return;
} }
@ -944,6 +990,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
createAndLogThread(); createAndLogThread();
createAndStartCreatorThread(); createAndStartCreatorThread();
createAndStartDestroyThread(); createAndStartDestroyThread();
createAndStartDetectThread();
initedLatch.await(); initedLatch.await();
init = true; init = true;
@ -968,16 +1015,13 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} catch (SQLException e) { } catch (SQLException e) {
LOG.error("{dataSource-" + this.getID() + "} init error", e); LOG.error("{dataSource-" + this.getID() + "} init error", e);
initException = e;
throw e; throw e;
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new SQLException(e.getMessage(), e); throw new SQLException(e.getMessage(), e);
} catch (RuntimeException e){ } catch (Throwable e) {
LOG.error("{dataSource-" + this.getID() + "} init error", e); initException = new SQLException(e.getMessage());
throw e;
} catch (Error e){
LOG.error("{dataSource-" + this.getID() + "} init error", e);
throw e; throw e;
} finally { } finally {
inited = true; inited = true;
lock.unlock(); lock.unlock();
@ -1087,7 +1131,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
protected void createAndStartCreatorThread() { protected void createAndStartCreatorThread() {
if (createScheduler == null) { if (createScheduler == null) {
String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(this); String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(this) + this.getUrl();
createConnectionThread = new CreateConnectionThread(threadName); createConnectionThread = new CreateConnectionThread(threadName);
createConnectionThread.start(); createConnectionThread.start();
return; return;
@ -1096,6 +1140,15 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
initedLatch.countDown(); initedLatch.countDown();
} }
private void createAndStartDetectThread() {
if (createScheduler == null) {
String threadName = "Druid-ConnectionPool-Detection-" + System.identityHashCode(this) + this.getUrl();
periodDetectionThread = new PeriodDetectionThread(threadName);
periodDetectionThread.start();
}
}
/** /**
* load filters from SPI ServiceLoader * load filters from SPI ServiceLoader
* *
@ -1181,21 +1234,21 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
return; return;
} }
String errorMessage = ""; String infoMessage = "";
if (testOnBorrow) { if (isTestOnBorrow()) {
errorMessage += "testOnBorrow is true, "; infoMessage += "testOnBorrow is true, ";
} }
if (testOnReturn) { if (isTestOnReturn()) {
errorMessage += "testOnReturn is true, "; infoMessage += "testOnReturn is true, ";
} }
if (testWhileIdle) { if (isTestWhileIdle()) {
errorMessage += "testWhileIdle is true, "; infoMessage += "testWhileIdle is true, ";
} }
LOG.error(errorMessage + "validationQuery not set"); LOG.info(infoMessage + "validationQuery not set");
} }
protected void resolveDriver() throws SQLException { protected void resolveDriver() throws SQLException {
@ -1402,6 +1455,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public DruidPooledConnection getConnection(long maxWaitMillis) throws SQLException { public DruidPooledConnection getConnection(long maxWaitMillis) throws SQLException {
init(); init();
checkThread();
if (filters.size() > 0) { if (filters.size() > 0) {
FilterChainImpl filterChain = new FilterChainImpl(this); FilterChainImpl filterChain = new FilterChainImpl(this);
return filterChain.dataSource_connect(this, maxWaitMillis); return filterChain.dataSource_connect(this, maxWaitMillis);
@ -1756,7 +1810,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
buf.append(", createErrorCount ").append(createErrorCount); buf.append(", createErrorCount ").append(createErrorCount);
} }
List<JdbcSqlStatValue> sqlList = this.getDataSourceStat().getRuningSqlList(); JdbcDataSourceStat sourceStat = this.getDataSourceStat();
if (sourceStat != null) {
List<JdbcSqlStatValue> sqlList = sourceStat.getRuningSqlList();
for (int i = 0; i < sqlList.size(); ++i) { for (int i = 0; i < sqlList.size(); ++i) {
if (i != 0) { if (i != 0) {
buf.append('\n'); buf.append('\n');
@ -1764,10 +1820,12 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
buf.append(", "); buf.append(", ");
} }
JdbcSqlStatValue sql = sqlList.get(i); JdbcSqlStatValue sql = sqlList.get(i);
buf.append("runningSqlCount ").append(sql.getRunningCount()); buf.append("runningSqlCount ");
buf.append(sql.getRunningCount());
buf.append(" : "); buf.append(" : ");
buf.append(sql.getSql()); buf.append(sql.getSql());
} }
}
String errorMessage = buf.toString(); String errorMessage = buf.toString();
@ -1863,8 +1921,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
dataSourceLock.lock(); dataSourceLock.lock();
try { try {
emptySignal(); emptySignal();
} } finally {
finally {
dataSourceLock.unlock(); dataSourceLock.unlock();
} }
} }
@ -2097,6 +2154,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
destroyConnectionThread.interrupt(); destroyConnectionThread.interrupt();
} }
if (periodDetectionThread != null) {
periodDetectionThread.interrupt();
}
if (createSchedulerFuture != null) { if (createSchedulerFuture != null) {
createSchedulerFuture.cancel(true); createSchedulerFuture.cancel(true);
} }
@ -2769,6 +2830,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
public class CreateConnectionThread extends Thread { public class CreateConnectionThread extends Thread {
private volatile boolean started = true;
public CreateConnectionThread(String name) { public CreateConnectionThread(String name) {
super(name); super(name);
@ -2829,6 +2891,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if ((!closing) && (!closed)) { if ((!closing) && (!closed)) {
LOG.error("create connection Thread Interrupted, url: " + jdbcUrl, e); LOG.error("create connection Thread Interrupted, url: " + jdbcUrl, e);
} }
DruidDataSource.this.doSomethingBeforeCreationThreadBreak();
break; break;
} finally { } finally {
lock.unlock(); lock.unlock();
@ -2838,9 +2901,13 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
try { try {
connection = createPhysicalConnection(); connection = createPhysicalConnection();
} catch (SQLException e) { } catch (SQLException | RuntimeException e) {
LOG.error("create connection SQLException, url: " + jdbcUrl + ", errorCode " + e.getErrorCode() if (e instanceof SQLException) {
+ ", state " + e.getSQLState(), e); LOG.error("create connection error, url: " + jdbcUrl + ", errorCode " + ((SQLException) e).getErrorCode()
+ ", state " + ((SQLException) e).getSQLState(), e);
} else {
LOG.error("create connection error", e);
}
errorCount++; errorCount++;
if (errorCount > connectionErrorRetryAttempts && timeBetweenConnectErrorMillis > 0) { if (errorCount > connectionErrorRetryAttempts && timeBetweenConnectErrorMillis > 0) {
@ -2861,17 +2928,16 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
try { try {
Thread.sleep(timeBetweenConnectErrorMillis); Thread.sleep(timeBetweenConnectErrorMillis);
} catch (InterruptedException interruptEx) { } catch (InterruptedException ignore) {
break;
} }
DruidDataSource.this.doSomethingBeforeCreationThreadBreak();
break;
} }
} catch (RuntimeException e) {
LOG.error("create connection RuntimeException", e);
setFailContinuous(true);
continue;
} catch (Error e) { } catch (Error e) {
LOG.error("create connection Error", e); LOG.error("create connection Error", e);
setFailContinuous(true); setFailContinuous(true);
DruidDataSource.this.doSomethingBeforeCreationThreadBreak();
break; break;
} }
@ -2892,10 +2958,48 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
} }
} }
public boolean isStarted() {
return started;
}
public void setStarted(boolean started) {
this.started = started;
}
}
//周期性检查生产线程状态,因为在终止生产线程的时候,为了不让生产线程疯狂重试数据库,只是生成了一个生产线程,但是并没有start,需要一个守护线程
//周期性检查线程状态,帮助其启动。
private class PeriodDetectionThread extends Thread {
public PeriodDetectionThread(String name) {
super(name);
this.setDaemon(true);
}
public void run() {
while (true) {
synchronized (DruidDataSource.this) {
//生产线程发生了切换,并且有线程在等待连接,需要主动唤醒生产线程,否则由getConnection方法来唤醒生产线程
if (!createConnectionThread.started && !destroyConnectionThread.started && notEmptyWaitThreadCount > 0) {
createConnectionThread.setStarted(true);
createConnectionThread.start();
destroyConnectionThread.setStarted(true);
destroyConnectionThread.start();
}
}
try {
Thread.sleep(30000);
} catch (InterruptedException ignore) {
break;
}
}
}
} }
public class DestroyConnectionThread extends Thread { public class DestroyConnectionThread extends Thread {
private volatile boolean started = true;
public DestroyConnectionThread(String name) { public DestroyConnectionThread(String name) {
super(name); super(name);
this.setDaemon(true); this.setDaemon(true);
@ -2928,6 +3032,13 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
} }
public boolean isStarted() {
return started;
}
public void setStarted(boolean started) {
this.started = started;
}
} }
public class DestroyTask implements Runnable { public class DestroyTask implements Runnable {
@ -3049,7 +3160,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
return removeCount; return removeCount;
} }
/** Instance key */ /**
* Instance key
*/
protected String instanceKey = null; protected String instanceKey = null;
public Reference getReference() throws NamingException { public Reference getReference() throws NamingException {

4
fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/hssf/usermodel/HSSFCell.java

@ -1258,5 +1258,9 @@ public class HSSFCell extends CellBase {
return styleIndex; return styleIndex;
} }
public boolean isRichText() {
return false;
}
} }

2
fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/ss/usermodel/Cell.java

@ -253,7 +253,7 @@ public interface Cell {
*/ */
void setCellValue(String value); void setCellValue(String value);
boolean isRichText();
/** /**
* Sets formula for this cell. * Sets formula for this cell.
* <p>If {@code formula} is not null, sets or updates the formula. If {@code formula} is null, removes the formula. * <p>If {@code formula} is not null, sets or updates the formula. If {@code formula} is null, removes the formula.

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

@ -741,6 +741,11 @@ public class SXSSFCell extends CellBase {
} }
} }
public boolean isRichText() {
CellType cellType = this.getCellType();
return cellType == CellType.STRING ? ((SXSSFCell.StringValue)this._value).isRichText() : false;
}
@Override @Override
public void setCellValue(BigInteger value) { public void setCellValue(BigInteger value) {
ensureTypeOrFormulaType(CellType.NUMERIC_BIG_INTEGER); ensureTypeOrFormulaType(CellType.NUMERIC_BIG_INTEGER);

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

@ -202,196 +202,198 @@ public class SheetDataWriter implements Closeable {
_numberLastFlushedRow = Math.max(rownum, _numberLastFlushedRow); _numberLastFlushedRow = Math.max(rownum, _numberLastFlushedRow);
_numberOfCellsOfLastFlushedRow = row.getLastCellNum(); _numberOfCellsOfLastFlushedRow = row.getLastCellNum();
_numberOfFlushedRows++; _numberOfFlushedRows++;
beginRow(rownum, row); int size = this._numberOfCellsOfLastFlushedRow > 0 ? this._numberOfCellsOfLastFlushedRow : 1;
StringBuilder sb = new StringBuilder(size << 6);
beginRow(rownum, row, sb);
Iterator<Cell> cells = row.allCellsIterator(); Iterator<Cell> cells = row.allCellsIterator();
int columnIndex = 0; int columnIndex = 0;
while (cells.hasNext()) { while (cells.hasNext()) {
writeCell(columnIndex++, cells.next()); writeCell(columnIndex++, cells.next(),sb);
} }
endRow(); endRow(sb);
this._out.write(sb.toString());
} }
void beginRow(int rownum, SXSSFRow row) throws IOException { void beginRow(int rownum, SXSSFRow row,StringBuilder sb) throws IOException {
_out.write("<row"); sb.append("<row");
writeAttribute("r", Integer.toString(rownum + 1)); writeAttribute("r", Integer.toString(rownum + 1), sb);
if (row.hasCustomHeight()) { if (row.hasCustomHeight()) {
writeAttribute("customHeight", "true"); writeAttribute("customHeight", "true", sb);
writeAttribute("ht", Float.toString(row.getHeightInPoints())); writeAttribute("ht", Float.toString(row.getHeightInPoints()), sb);
} }
if (row.getZeroHeight()) { if (row.getZeroHeight()) {
writeAttribute("hidden", "true"); writeAttribute("hidden", "true", sb);
} }
if (row.isFormatted()) { if (row.isFormatted()) {
writeAttribute("s", Integer.toString(row.getRowStyleIndex())); writeAttribute("s", Integer.toString(row.getRowStyleIndex()), sb);
writeAttribute("customFormat", "1"); writeAttribute("customFormat", "1", sb);
} }
if (row.getOutlineLevel() != 0) { if (row.getOutlineLevel() != 0) {
writeAttribute("outlineLevel", Integer.toString(row.getOutlineLevel())); writeAttribute("outlineLevel", Integer.toString(row.getOutlineLevel()), sb);
} }
if (row.getHidden() != null) { if (row.getHidden() != null) {
writeAttribute("hidden", row.getHidden() ? "1" : "0"); writeAttribute("hidden", row.getHidden() ? "1" : "0", sb);
} }
if (row.getCollapsed() != null) { if (row.getCollapsed() != null) {
writeAttribute("collapsed", row.getCollapsed() ? "1" : "0"); writeAttribute("collapsed", row.getCollapsed() ? "1" : "0", sb);
} }
_out.write(">\n"); sb.append(">\n");
this._rownum = rownum; this._rownum = rownum;
} }
void endRow() throws IOException { void endRow(StringBuilder sb) throws IOException {
_out.write("</row>\n"); sb.append("</row>\n");
} }
public void writeCell(int columnIndex, Cell cell) throws IOException { public void writeCell(int columnIndex, Cell cell,StringBuilder sb) throws IOException {
if (cell == null) { if (cell == null) {
return; return;
} }
String ref = new CellReference(_rownum, columnIndex).formatAsString(); String ref = new CellReference(_rownum, columnIndex).formatAsString();
_out.write("<c"); sb.append("<c");
writeAttribute("r", ref); writeAttribute("r", ref,sb);
CellStyle cellStyle = cell.getCellStyle(); CellStyle cellStyle = cell.getCellStyle();
if (cellStyle.getIndex() != 0) { if (cellStyle.getIndex() != 0) {
// need to convert the short to unsigned short as the indexes can be up to 64k // need to convert the short to unsigned short as the indexes can be up to 64k
// ideally we would use int for this index, but that would need changes to some more // ideally we would use int for this index, but that would need changes to some more
// APIs // APIs
writeAttribute("s", Integer.toString(cellStyle.getIndex() & 0xffff)); writeAttribute("s", Integer.toString(cellStyle.getIndex() & 0xffff),sb);
} }
CellType cellType = cell.getCellType(); CellType cellType = cell.getCellType();
switch (cellType) { switch (cellType) {
case BLANK: { case BLANK: {
_out.write('>'); sb.append('>');
break; break;
} }
case FORMULA: { case FORMULA: {
switch (cell.getCachedFormulaResultType()) { switch (cell.getCachedFormulaResultType()) {
case NUMERIC: case NUMERIC:
writeAttribute("t", "n"); writeAttribute("t", "n",sb);
break; break;
case STRING: case STRING:
writeAttribute("t", STCellType.STR.toString()); writeAttribute("t", STCellType.STR.toString(),sb);
break; break;
case BOOLEAN: case BOOLEAN:
writeAttribute("t", "b"); writeAttribute("t", "b",sb);
break; break;
case ERROR: case ERROR:
writeAttribute("t", "e"); writeAttribute("t", "e",sb);
break; break;
} }
_out.write("><f>"); sb.append("><f>");
outputQuotedString(cell.getCellFormula()); outputQuotedString(cell.getCellFormula(),sb);
_out.write("</f>"); sb.append("</f>");
switch (cell.getCachedFormulaResultType()) { switch (cell.getCachedFormulaResultType()) {
case NUMERIC: case NUMERIC:
double nval = cell.getNumericCellValue(); double nval = cell.getNumericCellValue();
if (!Double.isNaN(nval)) { if (!Double.isNaN(nval)) {
_out.write("<v>"); sb.append("<v>");
_out.write(Double.toString(nval)); sb.append(Double.toString(nval));
_out.write("</v>"); sb.append("</v>");
} }
break; break;
case STRING: case STRING:
String value = cell.getStringCellValue(); String value = cell.getStringCellValue();
if (value != null && !value.isEmpty()) { if (value != null && !value.isEmpty()) {
_out.write("<v>"); sb.append("<v>");
_out.write(value); sb.append(value);
_out.write("</v>"); sb.append("</v>");
} }
break; break;
case BOOLEAN: case BOOLEAN:
_out.write("><v>"); sb.append("><v>");
_out.write(cell.getBooleanCellValue() ? "1" : "0"); sb.append(cell.getBooleanCellValue() ? "1" : "0");
_out.write("</v>"); sb.append("</v>");
break; break;
case ERROR: { case ERROR: {
FormulaError error = FormulaError.forInt(cell.getErrorCellValue()); FormulaError error = FormulaError.forInt(cell.getErrorCellValue());
_out.write("><v>"); sb.append("><v>");
_out.write(error.getString()); sb.append(error.getString());
_out.write("</v>"); sb.append("</v>");
break; break;
} }
} }
break; break;
} }
case STRING: { case STRING: {
if (_sharedStringSource != null) { if (_sharedStringSource != null&& cell.isRichText()) {
//XSSFRichTextString rt = new XSSFRichTextString(cell.getStringCellValue());
RichTextString rt = cell.getRichStringCellValue(); RichTextString rt = cell.getRichStringCellValue();
int sRef = _sharedStringSource.addSharedStringItem(rt); int sRef = _sharedStringSource.addSharedStringItem(rt);
writeAttribute("t", STCellType.S.toString()); writeAttribute("t", STCellType.S.toString(),sb);
_out.write("><v>"); sb.append("><v>");
_out.write(String.valueOf(sRef)); sb.append(String.valueOf(sRef));
_out.write("</v>"); sb.append("</v>");
} else { } else {
writeAttribute("t", "inlineStr"); writeAttribute("t", "inlineStr",sb);
_out.write("><is><t"); sb.append("><is><t");
if (hasLeadingTrailingSpaces(cell.getStringCellValue())) { if (hasLeadingTrailingSpaces(cell.getStringCellValue())) {
writeAttribute("xml:space", "preserve"); writeAttribute("xml:space", "preserve",sb);
} }
_out.write(">"); sb.append(">");
outputQuotedString(cell.getStringCellValue()); outputQuotedString(cell.getStringCellValue(),sb);
_out.write("</t></is>"); sb.append("</t></is>");
} }
break; break;
} }
case NUMERIC_STRING: { case NUMERIC_STRING: {
_out.write(" t=\"n\"><v>"); sb.append(" t=\"n\"><v>");
_out.write(cell.getNumericStringCellValue()); sb.append(cell.getNumericStringCellValue());
_out.write("</v>"); sb.append("</v>");
break; break;
} }
case NUMERIC_BIG_DECIMAL: { case NUMERIC_BIG_DECIMAL: {
_out.write(" t=\"n\">"); sb.append(" t=\"n\">");
_out.write("<v>"); sb.append("<v>");
_out.write(cell.getNumericBigDecimalCellValue().toString()); sb.append(cell.getNumericBigDecimalCellValue().toString());
_out.write("</v>"); sb.append("</v>");
break; break;
} }
case NUMERIC_BIG_INTEGER: { case NUMERIC_BIG_INTEGER: {
_out.write(" t=\"n\">"); sb.append(" t=\"n\">");
_out.write("<v>"); sb.append("<v>");
_out.write(cell.getNumericBigIntegerCellValue().toString()); sb.append(cell.getNumericBigIntegerCellValue().toString());
_out.write("</v>"); sb.append("</v>");
break; break;
} }
case NUMERIC: { case NUMERIC: {
writeAttribute("t", "n"); writeAttribute("t", "n",sb);
_out.write("><v>"); sb.append("><v>");
_out.write(Double.toString(cell.getNumericCellValue())); sb.append(Double.toString(cell.getNumericCellValue()));
_out.write("</v>"); sb.append("</v>");
break; break;
} }
case BOOLEAN: { case BOOLEAN: {
writeAttribute("t", "b"); writeAttribute("t", "b",sb);
_out.write("><v>"); sb.append("><v>");
_out.write(cell.getBooleanCellValue() ? "1" : "0"); sb.append(cell.getBooleanCellValue() ? "1" : "0");
_out.write("</v>"); sb.append("</v>");
break; break;
} }
case ERROR: { case ERROR: {
FormulaError error = FormulaError.forInt(cell.getErrorCellValue()); FormulaError error = FormulaError.forInt(cell.getErrorCellValue());
writeAttribute("t", "e"); writeAttribute("t", "e",sb);
_out.write("><v>"); sb.append("><v>");
_out.write(error.getString()); sb.append(error.getString());
_out.write("</v>"); sb.append("</v>");
break; break;
} }
default: { default: {
throw new IllegalStateException("Invalid cell type: " + cellType); throw new IllegalStateException("Invalid cell type: " + cellType);
} }
} }
_out.write("</c>"); sb.append("</c>");
} }
private void writeAttribute(String name, String value) throws IOException { private void writeAttribute(String name, String value,StringBuilder sb) throws IOException {
_out.write(' '); sb.append(' ');
_out.write(name); sb.append(name);
_out.write("=\""); sb.append("=\"");
_out.write(value); sb.append(value);
_out.write('\"'); sb.append('\"');
} }
/** /**
@ -407,7 +409,7 @@ public class SheetDataWriter implements Closeable {
return false; return false;
} }
protected void outputQuotedString(String s) throws IOException { protected void outputQuotedString(String s,StringBuilder sb) throws IOException {
if (s == null || s.length() == 0) { if (s == null || s.length() == 0) {
return; return;
} }
@ -415,29 +417,29 @@ public class SheetDataWriter implements Closeable {
for (String codepoint : new StringCodepointsIterable(s)) { for (String codepoint : new StringCodepointsIterable(s)) {
switch (codepoint) { switch (codepoint) {
case "<": case "<":
_out.write("&lt;"); sb.append("&lt;");
break; break;
case ">": case ">":
_out.write("&gt;"); sb.append("&gt;");
break; break;
case "&": case "&":
_out.write("&amp;"); sb.append("&amp;");
break; break;
case "\"": case "\"":
_out.write("&quot;"); sb.append("&quot;");
break; break;
// Special characters // Special characters
case "\n": case "\n":
_out.write("&#xa;"); sb.append("&#xa;");
break; break;
case "\r": case "\r":
_out.write("&#xd;"); sb.append("&#xd;");
break; break;
case "\t": case "\t":
_out.write("&#x9;"); sb.append("&#x9;");
break; break;
case "\u00A0": // NO-BREAK SPACE case "\u00A0": // NO-BREAK SPACE
_out.write("&#xa0;"); sb.append("&#xa0;");
break; break;
default: default:
if (codepoint.length() == 1) { if (codepoint.length() == 1) {
@ -445,12 +447,12 @@ public class SheetDataWriter implements Closeable {
// 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 "not a character" symbols. // the same rule applies to "not a character" symbols.
if (replaceWithQuestionMark(c)) { if (replaceWithQuestionMark(c)) {
_out.write('?'); sb.append('?');
} else { } else {
_out.write(c); sb.append(c);
} }
} else { } else {
_out.write(codepoint); sb.append(codepoint);
} }
break; break;
} }

4
fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/usermodel/XSSFCell.java

@ -1266,5 +1266,9 @@ public final class XSSFCell extends CellBase {
ctCell.setR(r); ctCell.setR(r);
} }
public boolean isRichText() {
return false;
}
} }

Loading…
Cancel
Save