|
|
@ -6,6 +6,7 @@ import java.time.ZoneId; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.enums.NumericCellTypeEnum; |
|
|
|
import com.alibaba.excel.metadata.data.FormulaData; |
|
|
|
import com.alibaba.excel.metadata.data.FormulaData; |
|
|
|
|
|
|
|
|
|
|
|
import lombok.AccessLevel; |
|
|
|
import lombok.AccessLevel; |
|
|
@ -17,6 +18,7 @@ import org.apache.poi.ss.usermodel.CellBase; |
|
|
|
import org.apache.poi.ss.usermodel.CellStyle; |
|
|
|
import org.apache.poi.ss.usermodel.CellStyle; |
|
|
|
import org.apache.poi.ss.usermodel.CellType; |
|
|
|
import org.apache.poi.ss.usermodel.CellType; |
|
|
|
import org.apache.poi.ss.usermodel.Comment; |
|
|
|
import org.apache.poi.ss.usermodel.Comment; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.DateUtil; |
|
|
|
import org.apache.poi.ss.usermodel.Hyperlink; |
|
|
|
import org.apache.poi.ss.usermodel.Hyperlink; |
|
|
|
import org.apache.poi.ss.usermodel.RichTextString; |
|
|
|
import org.apache.poi.ss.usermodel.RichTextString; |
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
@ -44,6 +46,17 @@ public class CsvCell extends CellBase { |
|
|
|
@Getter(value = AccessLevel.NONE) |
|
|
|
@Getter(value = AccessLevel.NONE) |
|
|
|
@Setter(value = AccessLevel.NONE) |
|
|
|
@Setter(value = AccessLevel.NONE) |
|
|
|
private CellType cellType; |
|
|
|
private CellType cellType; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* workbook |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private final CsvWorkbook csvWorkbook; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* sheet |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private final CsvSheet csvSheet; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* row |
|
|
|
* row |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -52,7 +65,7 @@ public class CsvCell extends CellBase { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@link CellType#NUMERIC} |
|
|
|
* {@link CellType#NUMERIC} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private BigDecimal numberValue; |
|
|
|
private Double numberValue; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@link CellType#STRING} and {@link CellType#ERROR} {@link CellType#FORMULA} |
|
|
|
* {@link CellType#STRING} and {@link CellType#ERROR} {@link CellType#FORMULA} |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -62,11 +75,6 @@ public class CsvCell extends CellBase { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Boolean booleanValue; |
|
|
|
private Boolean booleanValue; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* {@link CellType#NUMERIC} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private LocalDateTime dateValue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* formula |
|
|
|
* formula |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -82,7 +90,9 @@ public class CsvCell extends CellBase { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private CellStyle cellStyle; |
|
|
|
private CellStyle cellStyle; |
|
|
|
|
|
|
|
|
|
|
|
public CsvCell(CsvRow csvRow, Integer columnIndex, CellType cellType) { |
|
|
|
public CsvCell(CsvWorkbook csvWorkbook, CsvSheet csvSheet, CsvRow csvRow, Integer columnIndex, CellType cellType) { |
|
|
|
|
|
|
|
this.csvWorkbook = csvWorkbook; |
|
|
|
|
|
|
|
this.csvSheet = csvSheet; |
|
|
|
this.csvRow = csvRow; |
|
|
|
this.csvRow = csvRow; |
|
|
|
this.columnIndex = columnIndex; |
|
|
|
this.columnIndex = columnIndex; |
|
|
|
this.cellType = cellType; |
|
|
|
this.cellType = cellType; |
|
|
@ -111,31 +121,25 @@ public class CsvCell extends CellBase { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void setCellValueImpl(double value) { |
|
|
|
protected void setCellValueImpl(double value) { |
|
|
|
numberValue = BigDecimal.valueOf(value); |
|
|
|
this.numberValue = value; |
|
|
|
this.cellType = CellType.NUMERIC; |
|
|
|
this.cellType = CellType.NUMERIC; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void setCellValueImpl(Date value) { |
|
|
|
protected void setCellValueImpl(Date value) { |
|
|
|
if (value == null) { |
|
|
|
this.numberValue = DateUtil.getExcelDate(value, csvWorkbook.getUse1904windowing()); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.dateValue = LocalDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault()); |
|
|
|
|
|
|
|
this.cellType = CellType.NUMERIC; |
|
|
|
this.cellType = CellType.NUMERIC; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void setCellValueImpl(LocalDateTime value) { |
|
|
|
protected void setCellValueImpl(LocalDateTime value) { |
|
|
|
this.dateValue = value; |
|
|
|
this.numberValue = DateUtil.getExcelDate(value, csvWorkbook.getUse1904windowing()); |
|
|
|
this.cellType = CellType.NUMERIC; |
|
|
|
this.cellType = CellType.NUMERIC; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void setCellValueImpl(Calendar value) { |
|
|
|
protected void setCellValueImpl(Calendar value) { |
|
|
|
if (value == null) { |
|
|
|
this.numberValue = DateUtil.getExcelDate(value, csvWorkbook.getUse1904windowing()); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.dateValue = LocalDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault()); |
|
|
|
|
|
|
|
this.cellType = CellType.NUMERIC; |
|
|
|
this.cellType = CellType.NUMERIC; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -227,15 +231,18 @@ public class CsvCell extends CellBase { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Date getDateCellValue() { |
|
|
|
public Date getDateCellValue() { |
|
|
|
if (dateValue == null) { |
|
|
|
if (numberValue == null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
return Date.from(dateValue.atZone(ZoneId.systemDefault()).toInstant()); |
|
|
|
return DateUtil.getJavaDate(numberValue, csvWorkbook.getUse1904windowing()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public LocalDateTime getLocalDateTimeCellValue() { |
|
|
|
public LocalDateTime getLocalDateTimeCellValue() { |
|
|
|
return dateValue; |
|
|
|
if (numberValue == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return DateUtil.getLocalDateTime(numberValue, csvWorkbook.getUse1904windowing()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -256,12 +263,15 @@ public class CsvCell extends CellBase { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setCellErrorValue(byte value) { |
|
|
|
public void setCellErrorValue(byte value) { |
|
|
|
this.numberValue = BigDecimal.valueOf(value); |
|
|
|
this.numberValue = value; |
|
|
|
this.cellType = CellType.ERROR; |
|
|
|
this.cellType = CellType.ERROR; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean getBooleanCellValue() { |
|
|
|
public boolean getBooleanCellValue() { |
|
|
|
|
|
|
|
if (booleanValue == null) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
return booleanValue; |
|
|
|
return booleanValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|