From c2863241947144732c9563d9c3b571fca2d9a8cd Mon Sep 17 00:00:00 2001 From: abel Date: Wed, 11 May 2022 16:56:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-71241=20=E5=A4=A7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E5=AF=BC=E5=87=BA=E5=8F=98=E6=85=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poi/xssf/streaming/SheetDataWriter.java | 192 +++++++++--------- 1 file changed, 98 insertions(+), 94 deletions(-) diff --git a/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/streaming/SheetDataWriter.java b/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/streaming/SheetDataWriter.java index 8c9bc9242..074ded2b0 100644 --- a/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/streaming/SheetDataWriter.java +++ b/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/streaming/SheetDataWriter.java @@ -36,6 +36,7 @@ import com.fr.third.v2.org.apache.poi.ss.usermodel.Cell; import com.fr.third.v2.org.apache.poi.ss.usermodel.CellStyle; import com.fr.third.v2.org.apache.poi.ss.usermodel.CellType; import com.fr.third.v2.org.apache.poi.ss.usermodel.FormulaError; +import com.fr.third.v2.org.apache.poi.ss.usermodel.RichTextString; import com.fr.third.v2.org.apache.poi.ss.util.CellReference; import com.fr.third.v2.org.apache.poi.util.POILogFactory; import com.fr.third.v2.org.apache.poi.util.POILogger; @@ -201,113 +202,116 @@ public class SheetDataWriter implements Closeable { _numberLastFlushedRow = Math.max(rownum, _numberLastFlushedRow); _numberOfCellsOfLastFlushedRow = row.getLastCellNum(); _numberOfFlushedRows++; - beginRow(rownum, row); + int size = this._numberOfCellsOfLastFlushedRow > 0 ? this._numberOfCellsOfLastFlushedRow : 1; + StringBuilder sb = new StringBuilder(size << 6); + beginRow(rownum, row, sb); Iterator cells = row.allCellsIterator(); int columnIndex = 0; 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 { - _out.write("\n"); + sb.append(">\n"); this._rownum = rownum; } - void endRow() throws IOException { - _out.write("\n"); + void endRow(StringBuilder sb) throws IOException { + sb.append("\n"); } - public void writeCell(int columnIndex, Cell cell) throws IOException { + public void writeCell(int columnIndex, Cell cell,StringBuilder sb) throws IOException { if (cell == null) { return; } String ref = new CellReference(_rownum, columnIndex).formatAsString(); - _out.write("'); + sb.append('>'); break; } case FORMULA: { switch (cell.getCachedFormulaResultType()) { case NUMERIC: - writeAttribute("t", "n"); + writeAttribute("t", "n",sb); break; case STRING: - writeAttribute("t", STCellType.STR.toString()); + writeAttribute("t", STCellType.STR.toString(),sb); break; case BOOLEAN: - writeAttribute("t", "b"); + writeAttribute("t", "b",sb); break; case ERROR: - writeAttribute("t", "e"); + writeAttribute("t", "e",sb); break; } - _out.write(">"); - outputQuotedString(cell.getCellFormula()); - _out.write(""); + sb.append(">"); + outputQuotedString(cell.getCellFormula(),sb); + sb.append(""); switch (cell.getCachedFormulaResultType()) { case NUMERIC: double nval = cell.getNumericCellValue(); if (!Double.isNaN(nval)) { - _out.write(""); - _out.write(Double.toString(nval)); - _out.write(""); + sb.append(""); + sb.append(Double.toString(nval)); + sb.append(""); } break; case STRING: String value = cell.getStringCellValue(); if (value != null && !value.isEmpty()) { - _out.write(""); - _out.write(value); - _out.write(""); + sb.append(""); + sb.append(value); + sb.append(""); } break; case BOOLEAN: - _out.write(">"); - _out.write(cell.getBooleanCellValue() ? "1" : "0"); - _out.write(""); + sb.append(">"); + sb.append(cell.getBooleanCellValue() ? "1" : "0"); + sb.append(""); break; case ERROR: { FormulaError error = FormulaError.forInt(cell.getErrorCellValue()); - _out.write(">"); - _out.write(error.getString()); - _out.write(""); + sb.append(">"); + sb.append(error.getString()); + sb.append(""); break; } } @@ -315,81 +319,81 @@ public class SheetDataWriter implements Closeable { } case STRING: { if (_sharedStringSource != null&& cell.isRichText()) { - XSSFRichTextString rt = new XSSFRichTextString(cell.getStringCellValue()); + RichTextString rt = cell.getRichStringCellValue(); int sRef = _sharedStringSource.addSharedStringItem(rt); - writeAttribute("t", STCellType.S.toString()); - _out.write(">"); - _out.write(String.valueOf(sRef)); - _out.write(""); + writeAttribute("t", STCellType.S.toString(),sb); + sb.append(">"); + sb.append(String.valueOf(sRef)); + sb.append(""); } else { - writeAttribute("t", "inlineStr"); - _out.write(">"); - outputQuotedString(cell.getStringCellValue()); - _out.write(""); + sb.append(">"); + outputQuotedString(cell.getStringCellValue(),sb); + sb.append(""); } break; } case NUMERIC_STRING: { - _out.write(" t=\"n\">"); - _out.write(cell.getNumericStringCellValue()); - _out.write(""); + sb.append(" t=\"n\">"); + sb.append(cell.getNumericStringCellValue()); + sb.append(""); break; } case NUMERIC_BIG_DECIMAL: { - _out.write(" t=\"n\">"); - _out.write(""); - _out.write(cell.getNumericBigDecimalCellValue().toString()); - _out.write(""); + sb.append(" t=\"n\">"); + sb.append(""); + sb.append(cell.getNumericBigDecimalCellValue().toString()); + sb.append(""); break; } case NUMERIC_BIG_INTEGER: { - _out.write(" t=\"n\">"); - _out.write(""); - _out.write(cell.getNumericBigIntegerCellValue().toString()); - _out.write(""); + sb.append(" t=\"n\">"); + sb.append(""); + sb.append(cell.getNumericBigIntegerCellValue().toString()); + sb.append(""); break; } case NUMERIC: { - writeAttribute("t", "n"); - _out.write(">"); - _out.write(Double.toString(cell.getNumericCellValue())); - _out.write(""); + writeAttribute("t", "n",sb); + sb.append(">"); + sb.append(Double.toString(cell.getNumericCellValue())); + sb.append(""); break; } case BOOLEAN: { - writeAttribute("t", "b"); - _out.write(">"); - _out.write(cell.getBooleanCellValue() ? "1" : "0"); - _out.write(""); + writeAttribute("t", "b",sb); + sb.append(">"); + sb.append(cell.getBooleanCellValue() ? "1" : "0"); + sb.append(""); break; } case ERROR: { FormulaError error = FormulaError.forInt(cell.getErrorCellValue()); - writeAttribute("t", "e"); - _out.write(">"); - _out.write(error.getString()); - _out.write(""); + writeAttribute("t", "e",sb); + sb.append(">"); + sb.append(error.getString()); + sb.append(""); break; } default: { throw new IllegalStateException("Invalid cell type: " + cellType); } } - _out.write(""); + sb.append(""); } - private void writeAttribute(String name, String value) throws IOException { - _out.write(' '); - _out.write(name); - _out.write("=\""); - _out.write(value); - _out.write('\"'); + private void writeAttribute(String name, String value,StringBuilder sb) throws IOException { + sb.append(' '); + sb.append(name); + sb.append("=\""); + sb.append(value); + sb.append('\"'); } /** @@ -405,7 +409,7 @@ public class SheetDataWriter implements Closeable { return false; } - protected void outputQuotedString(String s) throws IOException { + protected void outputQuotedString(String s,StringBuilder sb) throws IOException { if (s == null || s.length() == 0) { return; } @@ -413,29 +417,29 @@ public class SheetDataWriter implements Closeable { for (String codepoint : new StringCodepointsIterable(s)) { switch (codepoint) { case "<": - _out.write("<"); + sb.append("<"); break; case ">": - _out.write(">"); + sb.append(">"); break; case "&": - _out.write("&"); + sb.append("&"); break; case "\"": - _out.write("""); + sb.append("""); break; // Special characters case "\n": - _out.write(" "); + sb.append(" "); break; case "\r": - _out.write(" "); + sb.append(" "); break; case "\t": - _out.write(" "); + sb.append(" "); break; case "\u00A0": // NO-BREAK SPACE - _out.write(" "); + sb.append(" "); break; default: if (codepoint.length() == 1) { @@ -443,12 +447,12 @@ public class SheetDataWriter implements Closeable { // YK: XmlBeans silently replaces all ISO control characters ( < 32) with question marks. // the same rule applies to "not a character" symbols. if (replaceWithQuestionMark(c)) { - _out.write('?'); + sb.append('?'); } else { - _out.write(c); + sb.append(c); } } else { - _out.write(codepoint); + sb.append(codepoint); } break; } From a26d461c8d3bf0c3d40119d8ca01c13deeb811b8 Mon Sep 17 00:00:00 2001 From: abel Date: Wed, 1 Jun 2022 11:24:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?BI-105913=20BI=E5=AF=BC=E5=87=BA=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E9=97=AE=E9=A2=98,valueof=E7=9A=84=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=AF=94=E8=BE=83=E4=BD=8E,=E5=A4=A7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=87=8F=E4=BC=9A=E6=AF=94=E8=BE=83=E6=85=A2=EF=BC=8C=E8=BF=99?= =?UTF-8?q?=E6=98=AF=E4=B9=8B=E5=89=8D10.0=E5=AE=9A=E5=88=B6=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AE=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/third/v2/org/apache/poi/xssf/usermodel/XSSFSheet.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/usermodel/XSSFSheet.java b/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/usermodel/XSSFSheet.java index 750635c6d..143fe60cf 100644 --- a/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -408,10 +408,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { // throw IllegalStateException if the argument CellRangeAddress intersects with // a multi-cell array formula defined in this sheet validateArrayFormulas(region); - - // Throw IllegalStateException if the argument CellRangeAddress intersects with - // a merged region already in this sheet - validateMergedRegions(region); } CTMergeCells ctMergeCells = worksheet.isSetMergeCells() ? worksheet.getMergeCells() : worksheet.addNewMergeCells();