Sha256: 31cbe11f15804e890a578247ba4ad83f6c0dd916f1cf35aa38b23dbe1c367530

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

package org.embulk.parser.poi_excel.bean.record;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
import org.embulk.spi.Exec;
import org.slf4j.Logger;

public class PoiExcelRecordColumn extends PoiExcelRecord {
	private final Logger log = Exec.getLogger(getClass());

	private int maxColumnIndex;
	private int currentColumnIndex;

	@Override
	protected void initializeLoop(int skipHeaderLines) {
		int minColumnIndex = Integer.MAX_VALUE;
		maxColumnIndex = 0;
		Sheet sheet = getSheet();
		for (Row row : sheet) {
			int firstIndex = row.getFirstCellNum();
			if (firstIndex >= 0) {
				minColumnIndex = Math.min(minColumnIndex, firstIndex);
			}
			maxColumnIndex = Math.max(maxColumnIndex, row.getLastCellNum());
		}

		this.currentColumnIndex = maxColumnIndex;
		for (int i = minColumnIndex; i < maxColumnIndex; i++) {
			if (i < skipHeaderLines) {
				if (log.isDebugEnabled()) {
					log.debug("column({}) skipped", i);
				}
				continue;
			}

			this.currentColumnIndex = i;
			break;
		}
	}

	@Override
	public boolean exists() {
		return currentColumnIndex < maxColumnIndex;
	}

	@Override
	public void moveNext() {
		currentColumnIndex++;
	}

	@Override
	protected void logStartEnd(String part) {
		if (log.isDebugEnabled()) {
			log.debug("column({}) {}", currentColumnIndex, part);
		}
	}

	@Override
	public int getRowIndex(PoiExcelColumnBean bean) {
		return bean.getColumnIndex();
	}

	@Override
	public int getColumnIndex(PoiExcelColumnBean bean) {
		return currentColumnIndex;
	}

	@Override
	public Cell getCell(PoiExcelColumnBean bean) {
		int rowIndex = getRowIndex(bean);
		Row row = getSheet().getRow(rowIndex);
		if (row == null) {
			return null;
		}
		int columnIndex = getColumnIndex(bean);
		return row.getCell(columnIndex);
	}
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
embulk-parser-poi_excel-0.1.13 src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecordColumn.java
embulk-parser-poi_excel-0.1.12 src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecordColumn.java