|
|
|
|
@ -30,6 +30,7 @@ public abstract class XLS extends AbstractComponent {
|
|
|
|
|
protected Row row;
|
|
|
|
|
/**현재 처리 중인 cell*/
|
|
|
|
|
protected Cell cell;
|
|
|
|
|
protected boolean sxssf;
|
|
|
|
|
|
|
|
|
|
/**주어진 InputStream을 로드한다.
|
|
|
|
|
* @param <T> XLS 유형
|
|
|
|
|
@ -67,8 +68,9 @@ public abstract class XLS extends AbstractComponent {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
workbook = newWorkbook(null);
|
|
|
|
|
if (workbook instanceof SXSSFWorkbook swb)
|
|
|
|
|
swb.setCompressTempFiles(true);
|
|
|
|
|
sxssf = workbook instanceof SXSSFWorkbook;
|
|
|
|
|
if (sxssf)
|
|
|
|
|
((SXSSFWorkbook)workbook).setCompressTempFiles(true);
|
|
|
|
|
return workbook;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
@ -93,12 +95,13 @@ public abstract class XLS extends AbstractComponent {
|
|
|
|
|
try {
|
|
|
|
|
sheet = workbook().getSheetAt(index);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
sheet = workbook().createSheet();
|
|
|
|
|
if (sheet instanceof SXSSFSheet sst)
|
|
|
|
|
sst.setRandomAccessWindowSize(rowAccessWindowSize);
|
|
|
|
|
if (sxssf) {
|
|
|
|
|
sheet = workbook().createSheet();
|
|
|
|
|
((SXSSFSheet)sheet).setRandomAccessWindowSize(rowAccessWindowSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sheet.equals(worksheet)) {
|
|
|
|
|
if (!equals(sheet, worksheet)) {
|
|
|
|
|
clear(false);
|
|
|
|
|
worksheet = sheet;
|
|
|
|
|
}
|
|
|
|
|
@ -116,13 +119,12 @@ public abstract class XLS extends AbstractComponent {
|
|
|
|
|
try {
|
|
|
|
|
Workbook wb = workbook();
|
|
|
|
|
sheet = wb.getSheet(name);
|
|
|
|
|
if (sheet == null) {
|
|
|
|
|
if (sheet == null && sxssf) {
|
|
|
|
|
sheet = wb.createSheet(name);
|
|
|
|
|
if (sheet instanceof SXSSFSheet sst)
|
|
|
|
|
sst.setRandomAccessWindowSize(rowAccessWindowSize);
|
|
|
|
|
((SXSSFSheet)sheet).setRandomAccessWindowSize(rowAccessWindowSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sheet.equals(worksheet)) {
|
|
|
|
|
if (!equals(sheet, worksheet)) {
|
|
|
|
|
clear(false);
|
|
|
|
|
worksheet = sheet;
|
|
|
|
|
}
|
|
|
|
|
@ -139,7 +141,9 @@ public abstract class XLS extends AbstractComponent {
|
|
|
|
|
* @return 현재 XLS
|
|
|
|
|
*/
|
|
|
|
|
public XLS row(int index) {
|
|
|
|
|
row = ifEmpty(worksheet.getRow(index), () -> worksheet.createRow(index));
|
|
|
|
|
row = worksheet.getRow(index);
|
|
|
|
|
if (row == null && sxssf)
|
|
|
|
|
row = worksheet.createRow(index);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -149,7 +153,9 @@ public abstract class XLS extends AbstractComponent {
|
|
|
|
|
* @return 현재 XLS
|
|
|
|
|
*/
|
|
|
|
|
public XLS col(int index) {
|
|
|
|
|
cell = ifEmpty(row.getCell(index), () -> row.createCell(index));
|
|
|
|
|
cell = row != null ? row.getCell(index) : null;
|
|
|
|
|
if (cell == null && sxssf)
|
|
|
|
|
cell = row.createCell(index);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -162,6 +168,10 @@ public abstract class XLS extends AbstractComponent {
|
|
|
|
|
return row(row).col(col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Position cellPosition() {
|
|
|
|
|
return cell != null ? new Position(cell.getRowIndex(), cell.getColumnIndex()) : Position.NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**현재 XLS의 row, cell, worksheet 등 내부 상태를 초기화한다.
|
|
|
|
|
* @param all 초기화에 워크북 포함 여부
|
|
|
|
|
* <ul><li>워크북을 포함한 모두를 초기화하려면 true</li>
|
|
|
|
|
@ -177,6 +187,26 @@ public abstract class XLS extends AbstractComponent {
|
|
|
|
|
rowAccessWindowSize = 128;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class Position {
|
|
|
|
|
private static final Position NULL = new Position(-1, -1);
|
|
|
|
|
|
|
|
|
|
private int row;
|
|
|
|
|
private int col;
|
|
|
|
|
|
|
|
|
|
public Position(int row, int col) {
|
|
|
|
|
this.row = row;
|
|
|
|
|
this.col = col;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getRow() {
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getCol() {
|
|
|
|
|
return col;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**이미지 추가 유틸리티
|
|
|
|
|
* @author mjkhan
|
|
|
|
|
*/
|
|
|
|
|
|