clevertension
5 years ago
56 changed files with 2038 additions and 1025 deletions
@ -0,0 +1,27 @@
|
||||
package com.alibaba.excel.analysis.v03; |
||||
|
||||
public abstract class AbstractXlsRecordHandler implements XlsRecordHandler { |
||||
protected int row = -1; |
||||
protected int column = -1; |
||||
protected String value = null; |
||||
|
||||
@Override |
||||
public int getRow() { |
||||
return row; |
||||
} |
||||
|
||||
@Override |
||||
public int getColumn() { |
||||
return column; |
||||
} |
||||
|
||||
@Override |
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
@Override |
||||
public int compareTo(XlsRecordHandler o) { |
||||
return this.getOrder() - o.getOrder(); |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.alibaba.excel.analysis.v03; |
||||
|
||||
import org.apache.poi.hssf.record.Record; |
||||
|
||||
public interface XlsRecordHandler extends Comparable<XlsRecordHandler> { |
||||
boolean support(Record record); |
||||
void init(); |
||||
void processRecord(Record record); |
||||
int getRow(); |
||||
int getColumn(); |
||||
String getValue(); |
||||
int getOrder(); |
||||
} |
@ -0,0 +1,71 @@
|
||||
package com.alibaba.excel.analysis.v03.handlers; |
||||
|
||||
import com.alibaba.excel.analysis.v03.AbstractXlsRecordHandler; |
||||
import com.alibaba.excel.analysis.v03.XlsRecordHandler; |
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.metadata.Sheet; |
||||
import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder; |
||||
import org.apache.poi.hssf.record.BOFRecord; |
||||
import org.apache.poi.hssf.record.BoundSheetRecord; |
||||
import org.apache.poi.hssf.record.Record; |
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class BOFRecordHandler extends AbstractXlsRecordHandler { |
||||
private List<BoundSheetRecord> boundSheetRecords = new ArrayList<BoundSheetRecord>(); |
||||
private BoundSheetRecord[] orderedBSRs; |
||||
private int sheetIndex; |
||||
private List<Sheet> sheets; |
||||
private AnalysisContext context; |
||||
private boolean analyAllSheet; |
||||
private EventWorkbookBuilder.SheetRecordCollectingListener workbookBuildingListener; |
||||
public BOFRecordHandler(EventWorkbookBuilder.SheetRecordCollectingListener workbookBuildingListener, AnalysisContext context, List<Sheet> sheets) { |
||||
this.context = context; |
||||
this.workbookBuildingListener = workbookBuildingListener; |
||||
this.sheets = sheets; |
||||
} |
||||
@Override |
||||
public boolean support(Record record) { |
||||
return BoundSheetRecord.sid == record.getSid() || BOFRecord.sid == record.getSid(); |
||||
} |
||||
|
||||
@Override |
||||
public void processRecord(Record record) { |
||||
if (record.getSid() == BoundSheetRecord.sid) { |
||||
boundSheetRecords.add((BoundSheetRecord)record); |
||||
} else if (record.getSid() == BOFRecord.sid) { |
||||
BOFRecord br = (BOFRecord)record; |
||||
if (br.getType() == BOFRecord.TYPE_WORKSHEET) { |
||||
if (orderedBSRs == null) { |
||||
orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords); |
||||
} |
||||
sheetIndex++; |
||||
|
||||
Sheet sheet = new Sheet(sheetIndex, 0); |
||||
sheet.setSheetName(orderedBSRs[sheetIndex - 1].getSheetname()); |
||||
sheets.add(sheet); |
||||
if (this.analyAllSheet) { |
||||
context.setCurrentSheet(sheet); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void init() { |
||||
if (context.getCurrentSheet() == null) { |
||||
this.analyAllSheet = true; |
||||
} |
||||
sheetIndex = 0; |
||||
orderedBSRs = null; |
||||
boundSheetRecords.clear(); |
||||
sheets.clear(); |
||||
} |
||||
|
||||
@Override |
||||
public int getOrder() { |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.alibaba.excel.analysis.v03.handlers; |
||||
|
||||
import com.alibaba.excel.analysis.v03.AbstractXlsRecordHandler; |
||||
import org.apache.poi.hssf.record.*; |
||||
|
||||
public class BlankOrErrorRecordHandler extends AbstractXlsRecordHandler { |
||||
|
||||
@Override |
||||
public boolean support(Record record) { |
||||
return BlankRecord.sid == record.getSid() || BoolErrRecord.sid == record.getSid(); |
||||
} |
||||
|
||||
@Override |
||||
public void processRecord(Record record) { |
||||
if (record.getSid() == BlankRecord.sid) { |
||||
BlankRecord br = (BlankRecord)record; |
||||
this.row = br.getRow(); |
||||
this.column = br.getColumn(); |
||||
this.value = ""; |
||||
} else if (record.getSid() == BoolErrRecord.sid) { |
||||
BoolErrRecord ber = (BoolErrRecord)record; |
||||
this.row = ber.getRow(); |
||||
this.column = ber.getColumn(); |
||||
this.value = ""; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void init() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public int getOrder() { |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,71 @@
|
||||
package com.alibaba.excel.analysis.v03.handlers; |
||||
|
||||
import com.alibaba.excel.analysis.v03.AbstractXlsRecordHandler; |
||||
import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener; |
||||
import org.apache.poi.hssf.model.HSSFFormulaParser; |
||||
import org.apache.poi.hssf.record.*; |
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
||||
|
||||
public class FormulaRecordHandler extends AbstractXlsRecordHandler { |
||||
private int nextRow; |
||||
private int nextColumn; |
||||
/** |
||||
* Should we output the formula, or the value it has? |
||||
*/ |
||||
private boolean outputFormulaValues = true; |
||||
private boolean outputNextStringRecord; |
||||
private FormatTrackingHSSFListener formatListener; |
||||
private HSSFWorkbook stubWorkbook; |
||||
public FormulaRecordHandler(HSSFWorkbook stubWorkbook, FormatTrackingHSSFListener formatListener) { |
||||
this.stubWorkbook = stubWorkbook; |
||||
this.formatListener = formatListener; |
||||
} |
||||
@Override |
||||
public boolean support(Record record) { |
||||
return FormulaRecord.sid == record.getSid() || StringRecord.sid == record.getSid(); |
||||
} |
||||
|
||||
@Override |
||||
public void processRecord(Record record) { |
||||
if (record.getSid() == FormulaRecord.sid) { |
||||
FormulaRecord frec = (FormulaRecord)record; |
||||
|
||||
this.row = frec.getRow(); |
||||
this.column = frec.getColumn(); |
||||
|
||||
if (outputFormulaValues) { |
||||
if (Double.isNaN(frec.getValue())) { |
||||
// Formula result is a string
|
||||
// This is stored in the next record
|
||||
outputNextStringRecord = true; |
||||
nextRow = frec.getRow(); |
||||
nextColumn = frec.getColumn(); |
||||
} else { |
||||
this.value = formatListener.formatNumberDateCell(frec); |
||||
} |
||||
} else { |
||||
this.value = HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()); |
||||
} |
||||
} else if (record.getSid() == StringRecord.sid) { |
||||
if (outputNextStringRecord) { |
||||
// String for formula
|
||||
StringRecord srec = (StringRecord)record; |
||||
this.value = srec.getString(); |
||||
this.row = nextRow; |
||||
this.column = nextColumn; |
||||
outputNextStringRecord = false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void init() { |
||||
this.nextRow = 0; |
||||
this.nextColumn = 0; |
||||
} |
||||
|
||||
@Override |
||||
public int getOrder() { |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
package com.alibaba.excel.analysis.v03.handlers; |
||||
|
||||
import com.alibaba.excel.analysis.v03.AbstractXlsRecordHandler; |
||||
import org.apache.poi.hssf.record.LabelRecord; |
||||
import org.apache.poi.hssf.record.Record; |
||||
|
||||
public class LabelRecordHandler extends AbstractXlsRecordHandler { |
||||
@Override |
||||
public boolean support(Record record) { |
||||
return LabelRecord.sid == record.getSid(); |
||||
} |
||||
|
||||
@Override |
||||
public void processRecord(Record record) { |
||||
LabelRecord lrec = (LabelRecord)record; |
||||
this.row = lrec.getRow(); |
||||
this.column = lrec.getColumn(); |
||||
this.value = lrec.getValue(); |
||||
} |
||||
|
||||
@Override |
||||
public void init() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public int getOrder() { |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
package com.alibaba.excel.analysis.v03.handlers; |
||||
|
||||
import com.alibaba.excel.analysis.v03.AbstractXlsRecordHandler; |
||||
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord; |
||||
import org.apache.poi.hssf.record.Record; |
||||
|
||||
public class MissingCellDummyRecordHandler extends AbstractXlsRecordHandler { |
||||
@Override |
||||
public boolean support(Record record) { |
||||
return record instanceof MissingCellDummyRecord; |
||||
} |
||||
|
||||
@Override |
||||
public void init() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void processRecord(Record record) { |
||||
MissingCellDummyRecord mcdr = (MissingCellDummyRecord)record; |
||||
this.row = mcdr.getRow(); |
||||
this.column = mcdr.getColumn(); |
||||
this.value = ""; |
||||
} |
||||
|
||||
@Override |
||||
public int getOrder() { |
||||
return 1; |
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.alibaba.excel.analysis.v03.handlers; |
||||
|
||||
import com.alibaba.excel.analysis.v03.AbstractXlsRecordHandler; |
||||
import org.apache.poi.hssf.record.NoteRecord; |
||||
import org.apache.poi.hssf.record.Record; |
||||
|
||||
public class NoteRecordHandler extends AbstractXlsRecordHandler { |
||||
@Override |
||||
public boolean support(Record record) { |
||||
return NoteRecord.sid == record.getSid(); |
||||
} |
||||
|
||||
@Override |
||||
public void processRecord(Record record) { |
||||
NoteRecord nrec = (NoteRecord)record; |
||||
|
||||
this.row = nrec.getRow(); |
||||
this.column = nrec.getColumn(); |
||||
// TODO: Find object to match nrec.getShapeId()
|
||||
this.value = "(TODO)"; |
||||
} |
||||
|
||||
@Override |
||||
public void init() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public int getOrder() { |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.alibaba.excel.analysis.v03.handlers; |
||||
|
||||
import com.alibaba.excel.analysis.v03.AbstractXlsRecordHandler; |
||||
import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener; |
||||
import org.apache.poi.hssf.record.NumberRecord; |
||||
import org.apache.poi.hssf.record.Record; |
||||
|
||||
public class NumberRecordHandler extends AbstractXlsRecordHandler { |
||||
private FormatTrackingHSSFListener formatListener; |
||||
public NumberRecordHandler(FormatTrackingHSSFListener formatListener) { |
||||
this.formatListener = formatListener; |
||||
} |
||||
@Override |
||||
public boolean support(Record record) { |
||||
return NumberRecord.sid == record.getSid(); |
||||
} |
||||
|
||||
@Override |
||||
public void processRecord(Record record) { |
||||
NumberRecord numrec = (NumberRecord)record; |
||||
this.row = numrec.getRow(); |
||||
this.column = numrec.getColumn(); |
||||
// Format
|
||||
this.value = formatListener.formatNumberDateCell(numrec); |
||||
} |
||||
|
||||
@Override |
||||
public void init() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public int getOrder() { |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.alibaba.excel.analysis.v03.handlers; |
||||
|
||||
import com.alibaba.excel.analysis.v03.AbstractXlsRecordHandler; |
||||
import org.apache.poi.hssf.record.RKRecord; |
||||
import org.apache.poi.hssf.record.Record; |
||||
|
||||
public class RKRecordHandler extends AbstractXlsRecordHandler { |
||||
@Override |
||||
public boolean support(Record record) { |
||||
return RKRecord.sid == record.getSid(); |
||||
} |
||||
|
||||
@Override |
||||
public void processRecord(Record record) { |
||||
RKRecord rkrec = (RKRecord)record; |
||||
|
||||
this.row = rkrec.getRow(); |
||||
this.row = rkrec.getColumn(); |
||||
this.value = ""; |
||||
} |
||||
|
||||
@Override |
||||
public void init() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public int getOrder() { |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.alibaba.excel.analysis.v03.handlers; |
||||
|
||||
import com.alibaba.excel.analysis.v03.AbstractXlsRecordHandler; |
||||
import org.apache.poi.hssf.record.*; |
||||
|
||||
public class SSTRecordHandler extends AbstractXlsRecordHandler { |
||||
private SSTRecord sstRecord; |
||||
@Override |
||||
public boolean support(Record record) { |
||||
return SSTRecord.sid == record.getSid() || LabelSSTRecord.sid == record.getSid(); |
||||
} |
||||
|
||||
@Override |
||||
public void processRecord(Record record) { |
||||
if (record.getSid() == SSTRecord.sid) { |
||||
sstRecord = (SSTRecord)record; |
||||
} else if (record.getSid() == LabelSSTRecord.sid) { |
||||
LabelSSTRecord lsrec = (LabelSSTRecord)record; |
||||
|
||||
this.row = lsrec.getRow(); |
||||
this.column = lsrec.getColumn(); |
||||
if (sstRecord == null) { |
||||
this.value = ""; |
||||
} else { |
||||
this.value = sstRecord.getString(lsrec.getSSTIndex()).toString(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void init() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public int getOrder() { |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.alibaba.excel.analysis.v07; |
||||
|
||||
import org.xml.sax.Attributes; |
||||
|
||||
public interface XlsxCellHandler { |
||||
boolean support(String name); |
||||
|
||||
void startHandle(String name, Attributes attributes); |
||||
|
||||
void endHandle(String name); |
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.alibaba.excel.analysis.v07; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.apache.poi.xssf.model.SharedStringsTable; |
||||
|
||||
import com.alibaba.excel.analysis.v07.handlers.CountRowCellHandler; |
||||
import com.alibaba.excel.analysis.v07.handlers.DefaultCellHandler; |
||||
import com.alibaba.excel.analysis.v07.handlers.ProcessResultCellHandler; |
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.event.AnalysisEventRegistryCenter; |
||||
|
||||
public class XlsxHandlerFactory { |
||||
public static List<XlsxCellHandler> buildCellHandlers(AnalysisContext analysisContext, |
||||
AnalysisEventRegistryCenter registerCenter, SharedStringsTable sst) { |
||||
List<XlsxCellHandler> result = new ArrayList<XlsxCellHandler>(); |
||||
result.add(new CountRowCellHandler(analysisContext)); |
||||
DefaultCellHandler defaultCellHandler = buildXlsxRowResultHandler(analysisContext, registerCenter, sst); |
||||
result.add(defaultCellHandler); |
||||
result.add(new ProcessResultCellHandler(registerCenter, defaultCellHandler)); |
||||
return result; |
||||
} |
||||
|
||||
private static DefaultCellHandler buildXlsxRowResultHandler(AnalysisContext analysisContext, |
||||
AnalysisEventRegistryCenter registerCenter, SharedStringsTable sst) { |
||||
return new DefaultCellHandler(analysisContext, registerCenter, sst); |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.alibaba.excel.analysis.v07; |
||||
|
||||
public interface XlsxRowResultHolder { |
||||
void clearResult(); |
||||
|
||||
void appendCurrentCellValue(String currentCellValue); |
||||
|
||||
String[] getCurRowContent(); |
||||
|
||||
int getColumnSize(); |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.alibaba.excel.analysis.v07.handlers; |
||||
|
||||
import static com.alibaba.excel.constant.ExcelXmlConstants.DIMENSION; |
||||
import static com.alibaba.excel.constant.ExcelXmlConstants.DIMENSION_REF; |
||||
|
||||
import org.xml.sax.Attributes; |
||||
|
||||
import com.alibaba.excel.analysis.v07.XlsxCellHandler; |
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
|
||||
public class CountRowCellHandler implements XlsxCellHandler { |
||||
|
||||
private final AnalysisContext analysisContext; |
||||
|
||||
public CountRowCellHandler(AnalysisContext analysisContext) { |
||||
this.analysisContext = analysisContext; |
||||
} |
||||
@Override |
||||
public boolean support(String name) { |
||||
return DIMENSION.equals(name); |
||||
} |
||||
|
||||
@Override |
||||
public void startHandle(String name, Attributes attributes) { |
||||
String d = attributes.getValue(DIMENSION_REF); |
||||
String totalStr = d.substring(d.indexOf(":") + 1, d.length()); |
||||
String c = totalStr.toUpperCase().replaceAll("[A-Z]", ""); |
||||
analysisContext.setTotalCount(Integer.parseInt(c)); |
||||
} |
||||
|
||||
@Override |
||||
public void endHandle(String name) { |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,121 @@
|
||||
package com.alibaba.excel.analysis.v07.handlers; |
||||
|
||||
import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_VALUE_TAG; |
||||
import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_TAG; |
||||
import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_VALUE_TAG_1; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
import org.apache.poi.xssf.model.SharedStringsTable; |
||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString; |
||||
import org.xml.sax.Attributes; |
||||
|
||||
import com.alibaba.excel.analysis.v07.XlsxCellHandler; |
||||
import com.alibaba.excel.analysis.v07.XlsxRowResultHolder; |
||||
import com.alibaba.excel.annotation.FieldType; |
||||
import com.alibaba.excel.constant.ExcelXmlConstants; |
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.event.AnalysisEventRegistryCenter; |
||||
import com.alibaba.excel.util.PositionUtils; |
||||
|
||||
public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder { |
||||
private String currentCellIndex; |
||||
|
||||
private FieldType currentCellType; |
||||
|
||||
private int curRow; |
||||
|
||||
private int curCol; |
||||
|
||||
private String[] curRowContent = new String[20]; |
||||
|
||||
private String currentCellValue; |
||||
|
||||
private final AnalysisContext analysisContext; |
||||
|
||||
private final AnalysisEventRegistryCenter registerCenter; |
||||
|
||||
private final SharedStringsTable sst; |
||||
|
||||
public DefaultCellHandler(AnalysisContext analysisContext, AnalysisEventRegistryCenter registerCenter, SharedStringsTable sst) { |
||||
this.analysisContext = analysisContext; |
||||
this.registerCenter = registerCenter; |
||||
this.sst = sst; |
||||
} |
||||
|
||||
@Override |
||||
public void clearResult() { |
||||
curRowContent = new String[20]; |
||||
} |
||||
|
||||
@Override |
||||
public boolean support(String name) { |
||||
return CELL_VALUE_TAG.equals(name) || CELL_VALUE_TAG_1.equals(name) || CELL_TAG.equals(name); |
||||
} |
||||
|
||||
@Override |
||||
public void startHandle(String name, Attributes attributes) { |
||||
if (CELL_TAG.equals(name)) { |
||||
currentCellIndex = attributes.getValue(ExcelXmlConstants.POSITION); |
||||
int nextRow = PositionUtils.getRow(currentCellIndex); |
||||
if (nextRow > curRow) { |
||||
curRow = nextRow; |
||||
// endRow(ROW_TAG);
|
||||
} |
||||
analysisContext.setCurrentRowNum(curRow); |
||||
curCol = PositionUtils.getCol(currentCellIndex); |
||||
|
||||
String cellType = attributes.getValue("t"); |
||||
currentCellType = FieldType.EMPTY; |
||||
if (cellType != null && cellType.equals("s")) { |
||||
currentCellType = FieldType.STRING; |
||||
} |
||||
} |
||||
if (name.equals(CELL_VALUE_TAG) || name.equals(CELL_VALUE_TAG_1)) { |
||||
// initialize current cell value
|
||||
currentCellValue = ""; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void endHandle(String name) { |
||||
ensureSize(); |
||||
if (CELL_VALUE_TAG.equals(name)) { |
||||
switch (currentCellType) { |
||||
case STRING: |
||||
int idx = Integer.parseInt(currentCellValue); |
||||
currentCellValue = new XSSFRichTextString(sst.getEntryAt(idx)).toString(); |
||||
currentCellType = FieldType.EMPTY; |
||||
break; |
||||
} |
||||
curRowContent[curCol] = currentCellValue; |
||||
} else if (CELL_VALUE_TAG_1.equals(name)) { |
||||
curRowContent[curCol] = currentCellValue; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
private void ensureSize() { |
||||
// try to size
|
||||
if (curCol >= curRowContent.length) { |
||||
curRowContent = Arrays.copyOf(curRowContent, (int) (curCol * 1.5)); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void appendCurrentCellValue(String currentCellValue) { |
||||
this.currentCellValue += currentCellValue; |
||||
} |
||||
|
||||
@Override |
||||
public String[] getCurRowContent() { |
||||
return this.curRowContent; |
||||
} |
||||
|
||||
@Override |
||||
public int getColumnSize() { |
||||
return this.curCol; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.alibaba.excel.analysis.v07.handlers; |
||||
|
||||
import org.xml.sax.Attributes; |
||||
import static com.alibaba.excel.constant.ExcelXmlConstants.ROW_TAG; |
||||
import com.alibaba.excel.analysis.v07.XlsxCellHandler; |
||||
import com.alibaba.excel.analysis.v07.XlsxRowResultHolder; |
||||
import com.alibaba.excel.event.AnalysisEventRegistryCenter; |
||||
import com.alibaba.excel.event.EachRowAnalysisFinishEvent; |
||||
|
||||
public class ProcessResultCellHandler implements XlsxCellHandler { |
||||
private AnalysisEventRegistryCenter registerCenter; |
||||
private XlsxRowResultHolder rowResultHandler; |
||||
|
||||
public ProcessResultCellHandler(AnalysisEventRegistryCenter registerCenter, |
||||
XlsxRowResultHolder rowResultHandler) { |
||||
this.registerCenter = registerCenter; |
||||
this.rowResultHandler = rowResultHandler; |
||||
} |
||||
|
||||
@Override |
||||
public boolean support(String name) { |
||||
return ROW_TAG.equals(name); |
||||
} |
||||
|
||||
@Override |
||||
public void startHandle(String name, Attributes attributes) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void endHandle(String name) { |
||||
registerCenter.notify(new EachRowAnalysisFinishEvent(rowResultHandler.getCurRowContent(), |
||||
rowResultHandler.getColumnSize())); |
||||
rowResultHandler.clearResult(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,311 @@
|
||||
package com.alibaba.excel.context; |
||||
|
||||
import static com.alibaba.excel.util.StyleUtil.buildSheetStyle; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.io.OutputStream; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.concurrent.ConcurrentHashMap; |
||||
|
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
import org.apache.poi.ss.usermodel.CellStyle; |
||||
import org.apache.poi.ss.usermodel.Row; |
||||
import org.apache.poi.ss.usermodel.Sheet; |
||||
import org.apache.poi.ss.usermodel.Workbook; |
||||
import org.apache.poi.ss.util.CellRangeAddress; |
||||
|
||||
import com.alibaba.excel.converters.ConverterRegistryCenter; |
||||
import com.alibaba.excel.event.WriteHandler; |
||||
import com.alibaba.excel.metadata.BaseRowModel; |
||||
import com.alibaba.excel.metadata.ExcelHeadProperty; |
||||
import com.alibaba.excel.metadata.Table; |
||||
import com.alibaba.excel.support.ExcelTypeEnum; |
||||
import com.alibaba.excel.util.CollectionUtils; |
||||
import com.alibaba.excel.util.StyleUtil; |
||||
import com.alibaba.excel.util.WorkBookUtil; |
||||
|
||||
/** |
||||
* A context is the main anchorage point of a excel writer. |
||||
* |
||||
* @author jipengfei |
||||
*/ |
||||
public class WriteContextImpl implements WriteContext { |
||||
|
||||
/*** |
||||
* The sheet currently written |
||||
*/ |
||||
private Sheet currentSheet; |
||||
|
||||
/** |
||||
* current param |
||||
*/ |
||||
private com.alibaba.excel.metadata.Sheet currentSheetParam; |
||||
|
||||
/** |
||||
* The sheet currently written's name |
||||
*/ |
||||
private String currentSheetName; |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
private Table currentTable; |
||||
|
||||
/** |
||||
* Excel type |
||||
*/ |
||||
private ExcelTypeEnum excelType; |
||||
|
||||
/** |
||||
* POI Workbook |
||||
*/ |
||||
private Workbook workbook; |
||||
|
||||
/** |
||||
* Final output stream |
||||
*/ |
||||
private OutputStream outputStream; |
||||
|
||||
/** |
||||
* Written form collection |
||||
*/ |
||||
private Map<Integer, Table> tableMap = new ConcurrentHashMap<Integer, Table>(); |
||||
|
||||
/** |
||||
* Cell default style |
||||
*/ |
||||
private CellStyle defaultCellStyle; |
||||
|
||||
/** |
||||
* Current table head style |
||||
*/ |
||||
private CellStyle currentHeadCellStyle; |
||||
|
||||
/** |
||||
* Current table content style |
||||
*/ |
||||
private CellStyle currentContentCellStyle; |
||||
|
||||
/** |
||||
* the header attribute of excel |
||||
*/ |
||||
private ExcelHeadProperty excelHeadProperty; |
||||
|
||||
private boolean needHead = true; |
||||
|
||||
private WriteHandler writeHandler; |
||||
|
||||
private ConverterRegistryCenter registryCenter; |
||||
|
||||
public WriteHandler getWriteHandler() { |
||||
return writeHandler; |
||||
} |
||||
|
||||
public WriteContextImpl(InputStream templateInputStream, OutputStream out, ExcelTypeEnum excelType, |
||||
boolean needHead, WriteHandler writeHandler, ConverterRegistryCenter registryCenter) throws IOException { |
||||
this.needHead = needHead; |
||||
this.outputStream = out; |
||||
this.writeHandler = writeHandler; |
||||
this.workbook = WorkBookUtil.createWorkBook(templateInputStream, excelType); |
||||
this.defaultCellStyle = StyleUtil.buildDefaultCellStyle(this.workbook); |
||||
this.registryCenter = registryCenter; |
||||
} |
||||
|
||||
/** |
||||
* @param sheet |
||||
*/ |
||||
@Override |
||||
public void currentSheet(com.alibaba.excel.metadata.Sheet sheet) { |
||||
if (null == currentSheetParam || currentSheetParam.getSheetNo() != sheet.getSheetNo()) { |
||||
cleanCurrentSheet(); |
||||
currentSheetParam = sheet; |
||||
try { |
||||
this.currentSheet = workbook.getSheetAt(sheet.getSheetNo() - 1); |
||||
} catch (Exception e) { |
||||
this.currentSheet = WorkBookUtil.createSheet(workbook, sheet); |
||||
if (null != writeHandler) { |
||||
this.writeHandler.sheet(sheet.getSheetNo(), currentSheet); |
||||
} |
||||
} |
||||
buildSheetStyle(currentSheet, sheet.getColumnWidthMap()); |
||||
/** **/ |
||||
this.initCurrentSheet(sheet); |
||||
} |
||||
|
||||
} |
||||
|
||||
private void initCurrentSheet(com.alibaba.excel.metadata.Sheet sheet) { |
||||
|
||||
/** **/ |
||||
initExcelHeadProperty(sheet.getHead(), sheet.getClazz()); |
||||
|
||||
initTableStyle(sheet.getTableStyle()); |
||||
|
||||
initTableHead(); |
||||
|
||||
} |
||||
|
||||
private void cleanCurrentSheet() { |
||||
this.currentSheet = null; |
||||
this.currentSheetParam = null; |
||||
this.excelHeadProperty = null; |
||||
this.currentHeadCellStyle = null; |
||||
this.currentContentCellStyle = null; |
||||
this.currentTable = null; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* init excel header |
||||
* |
||||
* @param head |
||||
* @param clazz |
||||
*/ |
||||
private void initExcelHeadProperty(List<List<String>> head, Class<? extends BaseRowModel> clazz) { |
||||
if (head != null || clazz != null) { this.excelHeadProperty = new ExcelHeadProperty(clazz, head); } |
||||
} |
||||
|
||||
public void initTableHead() { |
||||
if (needHead && null != excelHeadProperty && !CollectionUtils.isEmpty(excelHeadProperty.getHead())) { |
||||
int startRow = currentSheet.getLastRowNum(); |
||||
if (startRow > 0) { |
||||
startRow += 4; |
||||
} else { |
||||
startRow = currentSheetParam.getStartRow(); |
||||
} |
||||
addMergedRegionToCurrentSheet(startRow); |
||||
int i = startRow; |
||||
for (; i < this.excelHeadProperty.getRowNum() + startRow; i++) { |
||||
Row row = WorkBookUtil.createRow(currentSheet, i); |
||||
if (null != writeHandler) { |
||||
this.writeHandler.row(i, row); |
||||
} |
||||
addOneRowOfHeadDataToExcel(row, this.excelHeadProperty.getHeadByRowNum(i - startRow)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void addMergedRegionToCurrentSheet(int startRow) { |
||||
for (com.alibaba.excel.metadata.CellRange cellRangeModel : excelHeadProperty.getCellRangeModels()) { |
||||
currentSheet.addMergedRegion(new CellRangeAddress(cellRangeModel.getFirstRow() + startRow, |
||||
cellRangeModel.getLastRow() + startRow, |
||||
cellRangeModel.getFirstCol(), cellRangeModel.getLastCol())); |
||||
} |
||||
} |
||||
|
||||
private void addOneRowOfHeadDataToExcel(Row row, List<String> headByRowNum) { |
||||
if (headByRowNum != null && headByRowNum.size() > 0) { |
||||
for (int i = 0; i < headByRowNum.size(); i++) { |
||||
Cell cell = WorkBookUtil.createCell(row, i, getCurrentHeadCellStyle(), headByRowNum.get(i)); |
||||
if (null != writeHandler) { |
||||
this.writeHandler.cell(i, cell); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void initTableStyle(com.alibaba.excel.metadata.TableStyle tableStyle) { |
||||
if (tableStyle != null) { |
||||
this.currentHeadCellStyle = StyleUtil.buildCellStyle(this.workbook, tableStyle.getTableHeadFont(), |
||||
tableStyle.getTableHeadBackGroundColor()); |
||||
this.currentContentCellStyle = StyleUtil.buildCellStyle(this.workbook, tableStyle.getTableContentFont(), |
||||
tableStyle.getTableContentBackGroundColor()); |
||||
} |
||||
} |
||||
|
||||
private void cleanCurrentTable() { |
||||
this.excelHeadProperty = null; |
||||
this.currentHeadCellStyle = null; |
||||
this.currentContentCellStyle = null; |
||||
this.currentTable = null; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void currentTable(Table table) { |
||||
if (null == currentTable || currentTable.getTableNo() != table.getTableNo()) { |
||||
cleanCurrentTable(); |
||||
this.currentTable = table; |
||||
this.initExcelHeadProperty(table.getHead(), table.getClazz()); |
||||
this.initTableStyle(table.getTableStyle()); |
||||
this.initTableHead(); |
||||
} |
||||
|
||||
} |
||||
|
||||
public ExcelHeadProperty getExcelHeadProperty() { |
||||
return this.excelHeadProperty; |
||||
} |
||||
|
||||
public boolean needHead() { |
||||
return this.needHead; |
||||
} |
||||
|
||||
@Override |
||||
public Sheet getCurrentSheet() { |
||||
return currentSheet; |
||||
} |
||||
|
||||
public void setCurrentSheet(Sheet currentSheet) { |
||||
this.currentSheet = currentSheet; |
||||
} |
||||
|
||||
public String getCurrentSheetName() { |
||||
return currentSheetName; |
||||
} |
||||
|
||||
public void setCurrentSheetName(String currentSheetName) { |
||||
this.currentSheetName = currentSheetName; |
||||
} |
||||
|
||||
public ExcelTypeEnum getExcelType() { |
||||
return excelType; |
||||
} |
||||
|
||||
public void setExcelType(ExcelTypeEnum excelType) { |
||||
this.excelType = excelType; |
||||
} |
||||
|
||||
@Override |
||||
public OutputStream getOutputStream() { |
||||
return outputStream; |
||||
} |
||||
|
||||
public CellStyle getCurrentHeadCellStyle() { |
||||
return this.currentHeadCellStyle == null ? defaultCellStyle : this.currentHeadCellStyle; |
||||
} |
||||
|
||||
public CellStyle getCurrentContentStyle() { |
||||
return this.currentContentCellStyle; |
||||
} |
||||
|
||||
@Override |
||||
public Workbook getWorkbook() { |
||||
return workbook; |
||||
} |
||||
|
||||
public com.alibaba.excel.metadata.Sheet getCurrentSheetParam() { |
||||
return currentSheetParam; |
||||
} |
||||
|
||||
public void setCurrentSheetParam(com.alibaba.excel.metadata.Sheet currentSheetParam) { |
||||
this.currentSheetParam = currentSheetParam; |
||||
} |
||||
|
||||
public Table getCurrentTable() { |
||||
return currentTable; |
||||
} |
||||
|
||||
public void setCurrentTable(Table currentTable) { |
||||
this.currentTable = currentTable; |
||||
} |
||||
|
||||
@Override |
||||
public ConverterRegistryCenter getConverterRegistryCenter() { |
||||
return registryCenter; |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
|
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
public class BigDecimalConverter implements Converter { |
||||
@Override |
||||
public String getName() { |
||||
return "big-decimal-converter"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean support(ExcelColumnProperty columnProperty) { |
||||
return BigDecimal.class.equals(columnProperty.getField().getType()); |
||||
} |
||||
@Override |
||||
public Object convert(String value, ExcelColumnProperty columnProperty) { |
||||
return new BigDecimal(value); |
||||
} |
||||
@Override |
||||
public Cell convert(Cell cell, Object value, ExcelColumnProperty columnProperty) { |
||||
cell.setCellValue(Double.parseDouble(value.toString())); |
||||
return cell; |
||||
} |
||||
@Override |
||||
public boolean support(Object cellValue) { |
||||
return cellValue instanceof BigDecimal; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import java.lang.reflect.Field; |
||||
|
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
|
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
public class BooleanConverter implements Converter { |
||||
@Override |
||||
public String getName() { |
||||
return "boolean-converter"; |
||||
} |
||||
@Override |
||||
public boolean support(ExcelColumnProperty columnProperty) { |
||||
Field field = columnProperty.getField(); |
||||
return Boolean.class.equals(field.getType()) || boolean.class.equals(field.getType()); |
||||
} |
||||
@Override |
||||
public Object convert(String value, ExcelColumnProperty columnProperty) { |
||||
String valueLower = value.toLowerCase(); |
||||
if (valueLower.equals("true") || valueLower.equals("false")) { |
||||
return Boolean.parseBoolean(value.toLowerCase()); |
||||
} |
||||
Integer integer = Integer.parseInt(value); |
||||
if (integer == 0) { |
||||
return false; |
||||
} else { |
||||
return true; |
||||
} |
||||
} |
||||
@Override |
||||
public Cell convert(Cell cell, Object value, ExcelColumnProperty columnProperty) { |
||||
cell.setCellValue(String.valueOf(value)); |
||||
return cell; |
||||
} |
||||
|
||||
@Override |
||||
public boolean support(Object cellValue) { |
||||
return cellValue instanceof Boolean || boolean.class.equals(cellValue.getClass()); |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
|
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
public interface Converter { |
||||
String getName(); |
||||
boolean support(ExcelColumnProperty columnProperty); |
||||
boolean support(Object cellValue); |
||||
Object convert(String value, ExcelColumnProperty columnProperty); |
||||
Cell convert(Cell cell, Object value, ExcelColumnProperty columnProperty); |
||||
} |
@ -0,0 +1,8 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import java.util.Collection; |
||||
|
||||
public interface ConverterRegistryCenter { |
||||
void register(Converter converter); |
||||
Collection<Converter> getConverters(); |
||||
} |
@ -0,0 +1,55 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import java.util.Date; |
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
|
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
import com.alibaba.excel.util.StringUtils; |
||||
import com.alibaba.excel.util.TypeUtil; |
||||
|
||||
public class DateConverter implements Converter { |
||||
private final AnalysisContext context; |
||||
|
||||
public DateConverter(AnalysisContext context) { |
||||
this.context = context; |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return "date-converter"; |
||||
} |
||||
@Override |
||||
public boolean support(ExcelColumnProperty columnProperty) { |
||||
return Date.class.equals(columnProperty.getField().getType()); |
||||
} |
||||
|
||||
@Override |
||||
public Object convert(String value, ExcelColumnProperty columnProperty) { |
||||
if (value.contains("-") || value.contains("/") || value.contains(":")) { |
||||
return TypeUtil.getSimpleDateFormatDate(value, columnProperty.getFormat()); |
||||
} else { |
||||
Double d = Double.parseDouble(value); |
||||
return HSSFDateUtil.getJavaDate(d, context != null ? context.use1904WindowDate() : false); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Cell convert(Cell cell, Object value, ExcelColumnProperty columnProperty) { |
||||
Date d = (Date)value; |
||||
if (columnProperty != null && StringUtils.isEmpty(columnProperty.getFormat()) == false) { |
||||
cell.setCellValue(TypeUtil.formatDate(d, columnProperty.getFormat())); |
||||
} else { |
||||
cell.setCellValue(d); |
||||
} |
||||
|
||||
return cell; |
||||
} |
||||
|
||||
@Override |
||||
public boolean support(Object cellValue) { |
||||
return cellValue instanceof Date; |
||||
} |
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import java.lang.reflect.Field; |
||||
|
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
|
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
import com.alibaba.excel.util.TypeUtil; |
||||
|
||||
public class DoubleConverter implements Converter { |
||||
@Override |
||||
public String getName() { |
||||
return "double-converter"; |
||||
} |
||||
@Override |
||||
public boolean support(ExcelColumnProperty columnProperty) { |
||||
Field field = columnProperty.getField(); |
||||
return Double.class.equals(field.getType()) || double.class.equals(field.getType()); |
||||
} |
||||
@Override |
||||
public Object convert(String value, ExcelColumnProperty columnProperty) { |
||||
return TypeUtil.formatFloat(value); |
||||
} |
||||
@Override |
||||
public Cell convert(Cell cell, Object value, ExcelColumnProperty columnProperty) { |
||||
cell.setCellValue(Double.parseDouble(value.toString())); |
||||
return cell; |
||||
} |
||||
@Override |
||||
public boolean support(Object cellValue) { |
||||
return cellValue instanceof Double || double.class.equals(cellValue.getClass()); |
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
|
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
import com.alibaba.excel.util.TypeUtil; |
||||
|
||||
public class FloatConverter implements Converter { |
||||
@Override |
||||
public String getName() { |
||||
return "float-converter"; |
||||
} |
||||
@Override |
||||
public boolean support(ExcelColumnProperty columnProperty) { |
||||
return Float.class.equals(columnProperty.getField().getType()); |
||||
} |
||||
@Override |
||||
public Object convert(String value, ExcelColumnProperty columnProperty) { |
||||
return TypeUtil.formatFloat(value); |
||||
} |
||||
@Override |
||||
public Cell convert(Cell cell, Object value, ExcelColumnProperty columnProperty) { |
||||
cell.setCellValue(Double.parseDouble(value.toString())); |
||||
return cell; |
||||
} |
||||
|
||||
@Override |
||||
public boolean support(Object cellValue) { |
||||
return cellValue instanceof Float || float.class.equals(cellValue.getClass()); |
||||
} |
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import java.lang.reflect.Field; |
||||
|
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
|
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
public class IntegerConverter implements Converter { |
||||
@Override |
||||
public String getName() { |
||||
return "integer-converter"; |
||||
} |
||||
@Override |
||||
public boolean support(ExcelColumnProperty columnProperty) { |
||||
Field field = columnProperty.getField(); |
||||
return Integer.class.equals(field.getType()) || int.class.equals(field.getType()); |
||||
} |
||||
@Override |
||||
public Object convert(String value, ExcelColumnProperty columnProperty) { |
||||
return Integer.parseInt(value); |
||||
} |
||||
@Override |
||||
public Cell convert(Cell cell, Object value, ExcelColumnProperty columnProperty) { |
||||
cell.setCellValue(Double.parseDouble(value.toString())); |
||||
return cell; |
||||
} |
||||
|
||||
@Override |
||||
public boolean support(Object cellValue) { |
||||
return cellValue instanceof Integer || int.class.equals(cellValue.getClass()); |
||||
} |
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import java.lang.reflect.Field; |
||||
|
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
|
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
public class LongConverter implements Converter { |
||||
@Override |
||||
public String getName() { |
||||
return "long-converter"; |
||||
} |
||||
@Override |
||||
public boolean support(ExcelColumnProperty columnProperty) { |
||||
Field field = columnProperty.getField(); |
||||
return Long.class.equals(field.getType()) || long.class.equals(field.getType()); |
||||
} |
||||
@Override |
||||
public Object convert(String value, ExcelColumnProperty columnProperty) { |
||||
return Long.parseLong(value); |
||||
} |
||||
@Override |
||||
public Cell convert(Cell cell, Object value, ExcelColumnProperty columnProperty) { |
||||
cell.setCellValue(Double.parseDouble(value.toString())); |
||||
return cell; |
||||
} |
||||
|
||||
@Override |
||||
public boolean support(Object cellValue) { |
||||
return cellValue instanceof Long || long.class.equals(cellValue.getClass()); |
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import org.apache.poi.ss.usermodel.Cell; |
||||
|
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
import com.alibaba.excel.util.TypeUtil; |
||||
|
||||
public class StringConverter implements Converter { |
||||
@Override |
||||
public String getName() { |
||||
return "string-converter"; |
||||
} |
||||
@Override |
||||
public boolean support(ExcelColumnProperty columnProperty) { |
||||
return String.class.equals(columnProperty.getField().getType()); |
||||
} |
||||
@Override |
||||
public Object convert(String value, ExcelColumnProperty columnProperty) { |
||||
return TypeUtil.formatFloat(value); |
||||
} |
||||
@Override |
||||
public Cell convert(Cell cell, Object value, ExcelColumnProperty columnProperty) { |
||||
cell.setCellValue(String.valueOf(value)); |
||||
return cell; |
||||
} |
||||
|
||||
@Override |
||||
public boolean support(Object cellValue) { |
||||
return cellValue instanceof String; |
||||
} |
||||
} |
@ -0,0 +1,5 @@
|
||||
package com.alibaba.excel.event; |
||||
|
||||
public interface AnalysisFinishEvent { |
||||
Object getAnalysisResult(); |
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.alibaba.excel.event; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author jipengfei |
||||
*/ |
||||
public class EachRowAnalysisFinishEvent implements AnalysisFinishEvent { |
||||
private Object result; |
||||
public EachRowAnalysisFinishEvent(Object content) { |
||||
this.result = content; |
||||
} |
||||
|
||||
public EachRowAnalysisFinishEvent(String[] content, int length) { |
||||
if (content != null) { |
||||
List<String> ls = new ArrayList<String>(length); |
||||
for (int i = 0; i <= length; i++) { |
||||
ls.add(content[i]); |
||||
} |
||||
result = ls; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Object getAnalysisResult() { |
||||
return result; |
||||
} |
||||
} |
@ -1,34 +0,0 @@
|
||||
package com.alibaba.excel.event; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author jipengfei |
||||
*/ |
||||
public class OneRowAnalysisFinishEvent { |
||||
|
||||
public OneRowAnalysisFinishEvent(Object content) { |
||||
this.data = content; |
||||
} |
||||
|
||||
public OneRowAnalysisFinishEvent(String[] content, int length) { |
||||
if (content != null) { |
||||
List<String> ls = new ArrayList<String>(length); |
||||
for (int i = 0; i <= length; i++) { |
||||
ls.add(content[i]); |
||||
} |
||||
data = ls; |
||||
} |
||||
} |
||||
|
||||
private Object data; |
||||
|
||||
public Object getData() { |
||||
return data; |
||||
} |
||||
|
||||
public void setData(Object data) { |
||||
this.data = data; |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
package com.alibaba.excel.write; |
||||
|
||||
public interface MergeStrategy { |
||||
int getFirstRow(); |
||||
int getLastRow(); |
||||
int getFirstCol(); |
||||
int getLastCol(); |
||||
} |
Loading…
Reference in new issue