You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/12/12 17:58:50 UTC

svn commit: r1905937 - in /poi/trunk/poi-ooxml/src: main/java/org/apache/poi/xssf/streaming/SXSSFCell.java main/java/org/apache/poi/xssf/streaming/SXSSFRow.java test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java

Author: fanningpj
Date: Mon Dec 12 17:58:50 2022
New Revision: 1905937

URL: http://svn.apache.org/viewvc?rev=1905937&view=rev
Log:
try to speed up SXSSFCell getColumnIndex

Modified:
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java
    poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java?rev=1905937&r1=1905936&r2=1905937&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java Mon Dec 12 17:58:50 2022
@@ -52,14 +52,28 @@ public class SXSSFCell extends CellBase
     private CellStyle _style;
     private Property _firstProperty;
 
-    public SXSSFCell(SXSSFRow row, CellType cellType)
+    private int _columnIndex = -1;
+
+    public SXSSFCell(final SXSSFRow row, final CellType cellType)
     {
-        _row=row;
+        _row = row;
         _value = new BlankValue();
         setType(cellType);
     }
 
     /**
+     * @param row the {@link SXSSFRow}
+     * @param cellType the {@link CellType}
+     * @param columnIndex the column index (zero based)
+     * @since POI 5.2.4
+     */
+    public SXSSFCell(final SXSSFRow row, final CellType cellType, final int columnIndex)
+    {
+        this(row, cellType);
+        _columnIndex = columnIndex;
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override
@@ -75,6 +89,9 @@ public class SXSSFCell extends CellBase
     @Override
     public int getColumnIndex()
     {
+        if (_columnIndex >= 0) {
+            return _columnIndex;
+        }
         return _row.getCellIndex(this);
     }
 

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java?rev=1905937&r1=1905936&r2=1905937&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java Mon Dec 12 17:58:50 2022
@@ -113,7 +113,7 @@ public class SXSSFRow implements Row, Co
      * The cell that is returned is a {@link CellType#BLANK}. The type can be changed
      * either through calling {@code setCellValue} or {@code setCellType}.
      *
-     * @param column - the column number this cell represents
+     * @param column - the column number this cell represents (zero-based)
      * @return Cell a high level representation of the created cell.
      * @throws IllegalArgumentException if columnIndex < 0 or greater than the maximum number of supported columns
      * (255 for *.xls, 1048576 for *.xlsx)
@@ -130,16 +130,16 @@ public class SXSSFRow implements Row, Co
      * The cell that is returned is a {@link CellType#BLANK}. The type can be changed
      * either through calling setCellValue or setCellType.
      *
-     * @param column - the column number this cell represents
+     * @param column - the column number this cell represents (zero-based)
      * @return Cell a high level representation of the created cell.
      * @throws IllegalArgumentException if columnIndex < 0 or greater than a maximum number of supported columns
      * (255 for *.xls, 1048576 for *.xlsx)
      */
     @Override
-    public SXSSFCell createCell(int column, CellType type)
+    public SXSSFCell createCell(final int column, final CellType type)
     {
         checkBounds(column);
-        SXSSFCell cell = new SXSSFCell(this, type);
+        SXSSFCell cell = new SXSSFCell(this, type, column);
         _cells.put(column, cell);
         _sheet.trackNewCell(cell);
         return cell;

Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java?rev=1905937&r1=1905936&r2=1905937&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java Mon Dec 12 17:58:50 2022
@@ -23,6 +23,11 @@ import org.apache.poi.ss.tests.usermodel
 import org.apache.poi.xssf.SXSSFITestDataProvider;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 /**
  * Tests for XSSFRow
@@ -51,5 +56,14 @@ public final class TestSXSSFRow extends
         // Remove when SXSSFRow.shiftCellsLeft() is implemented.
     }
 
+    @Test
+    void testCellColumn() throws IOException {
+        try (SXSSFWorkbook wb = new SXSSFWorkbook()) {
+            SXSSFSheet sheet = wb.createSheet();
+            SXSSFRow row = sheet.createRow(0);
+            SXSSFCell cell5 = row.createCell(5);
+            assertEquals(5, cell5.getColumnIndex());
+        }
+    }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org