Commit 08967a90 authored by Matija Obreza's avatar Matija Obreza

Fixed skiprows for Excel sheets

parent 706f7425
......@@ -54,6 +54,10 @@ public class XlsxRowReader implements RowReader {
private Queue<Object[]> rowsQueue = new LinkedBlockingQueue<Object[]>(MAX_XLSXREADER_BUFFER);
private int skipRows = 0;
private int rowCount = 0;
public XlsxRowReader(File sourceFile, String sheetName) {
if (sheetName == null) {
throw new IllegalArgumentException("sheetName cannot be null");
......@@ -115,7 +119,7 @@ public class XlsxRowReader implements RowReader {
}
List<Object[]> readRows = new ArrayList<Object[]>(rowsToRead);
for (; rowsToRead > 0; rowsToRead--) {
do {
while (rowsQueue.size() == 0) {
_log.debug("Queue is empty.");
try {
......@@ -130,15 +134,23 @@ public class XlsxRowReader implements RowReader {
return readRows;
}
}
readRows.add(rowsQueue.poll());
}
Object[] row = rowsQueue.poll();
rowCount++;
if (skipRows >= rowCount) {
_log.debug("Skipping row " + rowCount + " skipRows=" + skipRows);
continue;
}
readRows.add(row);
} while (readRows.size() < rowsToRead);
return readRows;
}
@Override
public void setSkipRows(int skipRows) {
threadedReader.setSkipRows(skipRows);
this.skipRows = skipRows;
}
@Override
......@@ -167,8 +179,6 @@ public class XlsxRowReader implements RowReader {
private XMLReader parser;
private InputStream sheet;
private int startAt = 0;
int rowCount = 0;
private Queue<Object[]> rows;
private OPCPackage pkg;
......@@ -200,10 +210,6 @@ public class XlsxRowReader implements RowReader {
this.pkg = null;
}
public void setSkipRows(int skipRows) {
this.startAt = skipRows;
}
@Override
public void run() {
try {
......@@ -237,13 +243,6 @@ public class XlsxRowReader implements RowReader {
throw new StopParsingException("Xlsx reader thread was interrupted. Stop parsing.");
}
rowCount++;
if (startAt >= rowCount) {
_log.debug("Skipping row " + rowCount + " startAt=" + startAt);
return;
}
while (true) {
try {
rows.add(row);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment