mirror of https://github.com/apache/poi.git
try to improve performance when removing rows
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895125 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9c81d7f588
commit
106557ede6
|
@ -24,18 +24,7 @@ import static org.apache.poi.xssf.usermodel.helpers.XSSFPasswordHelper.validateP
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
@ -3035,12 +3024,14 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
|
||||
// remove all rows which will be overwritten
|
||||
private void removeOverwritten(XSSFVMLDrawing vml, int startRow, int endRow, final int n) {
|
||||
HashSet<Integer> rowsToRemoveSet = new HashSet<>();
|
||||
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
|
||||
XSSFRow row = (XSSFRow)it.next();
|
||||
int rownum = row.getRowNum();
|
||||
|
||||
// check if we should remove this row as it will be overwritten by the data later
|
||||
if (shouldRemoveRow(startRow, endRow, n, rownum)) {
|
||||
rowsToRemoveSet.add(rownum);
|
||||
for (Cell c : row) {
|
||||
if (!c.isPartOfArrayFormulaGroup()) {
|
||||
//the support for deleting cells that are part of array formulas is not implemented yet
|
||||
|
@ -3056,8 +3047,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
|
||||
// remove row from _rows
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: (performance optimization) this should be moved outside the for-loop so that comments only needs to be iterated over once.
|
||||
// also remove any comments associated with this row
|
||||
if (sheetComments != null) {
|
||||
CTCommentList lst = sheetComments.getCTComments().getCommentList();
|
||||
|
@ -3066,24 +3058,23 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
CellAddress ref = new CellAddress(strRef);
|
||||
|
||||
// is this comment part of the current row?
|
||||
if(ref.getRow() == rownum) {
|
||||
if(rowsToRemoveSet.contains(ref.getRow())) {
|
||||
sheetComments.removeComment(ref);
|
||||
vml.removeCommentShape(ref.getRow(), ref.getColumn());
|
||||
}
|
||||
}
|
||||
}
|
||||
// FIXME: (performance optimization) this should be moved outside the for-loop so that hyperlinks only needs to be iterated over once.
|
||||
|
||||
// also remove any hyperlinks associated with this row
|
||||
if (hyperlinks != null) {
|
||||
for (XSSFHyperlink link : new ArrayList<>(hyperlinks)) {
|
||||
CellReference ref = new CellReference(link.getCellRef());
|
||||
if (ref.getRow() == rownum) {
|
||||
if (rowsToRemoveSet.contains(ref.getRow())) {
|
||||
hyperlinks.remove(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue