diff --git a/src/main/java/com/alibaba/excel/EasyExcelFactory.java b/src/main/java/com/alibaba/excel/EasyExcelFactory.java index a4924973..ef9b3ac3 100644 --- a/src/main/java/com/alibaba/excel/EasyExcelFactory.java +++ b/src/main/java/com/alibaba/excel/EasyExcelFactory.java @@ -3,17 +3,10 @@ package com.alibaba.excel; import java.io.File; import java.io.InputStream; import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; -import com.alibaba.excel.context.AnalysisContext; -import com.alibaba.excel.event.AnalysisEventListener; -import com.alibaba.excel.event.WriteHandler; -import com.alibaba.excel.metadata.Sheet; import com.alibaba.excel.read.builder.ExcelReaderBuilder; import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder; import com.alibaba.excel.read.listener.ReadListener; -import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.write.builder.ExcelWriterBuilder; import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder; import com.alibaba.excel.write.builder.ExcelWriterTableBuilder; @@ -39,138 +32,6 @@ import com.alibaba.excel.write.builder.ExcelWriterTableBuilder; */ public class EasyExcelFactory { - /** - * Quickly read small files,no more than 10,000 lines. - * - * @param in - * the POI filesystem that contains the Workbook stream. - * @param sheet - * read sheet. - * @return analysis result. - * @deprecated please use 'EasyExcel.read(in).sheet(sheetNo).doReadSync();' - */ - @Deprecated - public static List read(InputStream in, Sheet sheet) { - final List rows = new ArrayList(); - new ExcelReader(in, null, new AnalysisEventListener() { - @Override - public void invoke(Object object, AnalysisContext context) { - rows.add(object); - } - - @Override - public void doAfterAllAnalysed(AnalysisContext context) {} - }, false).read(sheet); - return rows; - } - - /** - * Parsing large file - * - * @param in - * the POI filesystem that contains the Workbook stream. - * @param sheet - * read sheet. - * @param listener - * Callback method after each row is parsed. - * @deprecated please use 'EasyExcel.read(in,head,listener).sheet(sheetNo).doRead();' - */ - @Deprecated - public static void readBySax(InputStream in, Sheet sheet, AnalysisEventListener listener) { - new ExcelReader(in, null, listener).read(sheet); - } - - /** - * Get ExcelReader. - * - * @param in - * the POI filesystem that contains the Workbook stream. - * @param listener - * Callback method after each row is parsed. - * @return ExcelReader. - * @deprecated please use {@link EasyExcel#read()} build 'ExcelReader' - */ - @Deprecated - public static ExcelReader getReader(InputStream in, AnalysisEventListener listener) { - return new ExcelReader(in, null, listener); - } - - /** - * Get ExcelWriter - * - * @param outputStream - * the java OutputStream you wish to write the value to. - * @return new ExcelWriter. - * @deprecated please use {@link EasyExcel#write()} - */ - @Deprecated - public static ExcelWriter getWriter(OutputStream outputStream) { - return write().file(outputStream).autoCloseStream(Boolean.FALSE).convertAllFiled(Boolean.FALSE).build(); - } - - /** - * Get ExcelWriter - * - * @param outputStream - * the java OutputStream you wish to write the value to. - * @param typeEnum - * 03 or 07 - * @param needHead - * Do you need to write the header to the file? - * @return new ExcelWriter - * @deprecated please use {@link EasyExcel#write()} - */ - @Deprecated - public static ExcelWriter getWriter(OutputStream outputStream, ExcelTypeEnum typeEnum, boolean needHead) { - return write().file(outputStream).excelType(typeEnum).needHead(needHead).autoCloseStream(Boolean.FALSE) - .convertAllFiled(Boolean.FALSE).build(); - } - - /** - * Get ExcelWriter with a template file - * - * @param temp - * Append value after a POI file , Can be null(the template POI filesystem that contains the Workbook - * stream) - * @param outputStream - * the java OutputStream you wish to write the value to - * @param typeEnum - * 03 or 07 - * @param needHead - * Whether a write header is required - * @return new ExcelWriter - * @deprecated please use {@link EasyExcel#write()} - */ - @Deprecated - public static ExcelWriter getWriterWithTemp(InputStream temp, OutputStream outputStream, ExcelTypeEnum typeEnum, - boolean needHead) { - return write().withTemplate(temp).file(outputStream).excelType(typeEnum).needHead(needHead) - .autoCloseStream(Boolean.FALSE).convertAllFiled(Boolean.FALSE).build(); - } - - /** - * Get ExcelWriter with a template file - * - * @param temp - * Append value after a POI file , Can be null(the template POI filesystem that contains the Workbook - * stream) - * @param outputStream - * the java OutputStream you wish to write the value to - * @param typeEnum - * 03 or 07 - * @param needHead - * Whether a write header is required - * @param handler - * User-defined callback - * @return new ExcelWriter - * @deprecated please use {@link EasyExcel#write()} - */ - @Deprecated - public static ExcelWriter getWriterWithTempAndHandler(InputStream temp, OutputStream outputStream, - ExcelTypeEnum typeEnum, boolean needHead, WriteHandler handler) { - return write().withTemplate(temp).file(outputStream).excelType(typeEnum).needHead(needHead) - .registerWriteHandler(handler).autoCloseStream(Boolean.FALSE).convertAllFiled(Boolean.FALSE).build(); - } /** * Build excel the write diff --git a/src/main/java/com/alibaba/excel/ExcelReader.java b/src/main/java/com/alibaba/excel/ExcelReader.java index 7af49eb6..a1a9c50d 100644 --- a/src/main/java/com/alibaba/excel/ExcelReader.java +++ b/src/main/java/com/alibaba/excel/ExcelReader.java @@ -1,25 +1,17 @@ package com.alibaba.excel; -import java.io.InputStream; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.alibaba.excel.analysis.ExcelAnalyser; import com.alibaba.excel.analysis.ExcelAnalyserImpl; import com.alibaba.excel.analysis.ExcelReadExecutor; -import com.alibaba.excel.cache.MapCache; import com.alibaba.excel.context.AnalysisContext; -import com.alibaba.excel.event.AnalysisEventListener; -import com.alibaba.excel.metadata.Sheet; -import com.alibaba.excel.parameter.AnalysisParam; -import com.alibaba.excel.read.listener.ReadListener; import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.ReadWorkbook; -import com.alibaba.excel.support.ExcelTypeEnum; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Excel readers are all read in event mode. @@ -34,113 +26,6 @@ public class ExcelReader { */ private ExcelAnalyser excelAnalyser; - /** - * Create new reader - * - * @param in - * the POI filesystem that contains the Workbook stream - * @param excelTypeEnum - * 03 or 07 - * @param customContent - * {@link AnalysisEventListener#invoke(Object, AnalysisContext) }AnalysisContext - * @param eventListener - * Callback method after each row is parsed. - * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader' - */ - @Deprecated - public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent, - AnalysisEventListener eventListener) { - this(in, excelTypeEnum, customContent, eventListener, true); - } - - /** - * Create new reader - * - * @param in - * the POI filesystem that contains the Workbook stream - * @param customContent - * {@link AnalysisEventListener#invoke(Object, AnalysisContext) }AnalysisContext - * @param eventListener - * Callback method after each row is parsed - * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader' - */ - @Deprecated - public ExcelReader(InputStream in, Object customContent, AnalysisEventListener eventListener) { - this(in, customContent, eventListener, true); - } - - /** - * Create new reader - * - * @param param - * old param Deprecated - * @param eventListener - * Callback method after each row is parsed. - * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader' - */ - @Deprecated - public ExcelReader(AnalysisParam param, AnalysisEventListener eventListener) { - this(param.getIn(), param.getExcelTypeEnum(), param.getCustomContent(), eventListener, true); - } - - /** - * Create new reader - * - * @param in - * @param customContent - * {@link AnalysisEventListener#invoke(Object, AnalysisContext) }AnalysisContext - * @param eventListener - * @param trim - * The content of the form is empty and needs to be empty. The purpose is to be fault-tolerant, because - * there are often table contents with spaces that can not be converted into custom types. For example: - * '1234 ' contain a space cannot be converted to int. - * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader' - */ - @Deprecated - public ExcelReader(InputStream in, Object customContent, AnalysisEventListener eventListener, boolean trim) { - this(in, null, customContent, eventListener, trim); - } - - /** - * Create new reader - * - * @param in - * the POI filesystem that contains the Workbook stream - * @param excelTypeEnum - * 03 or 07 - * @param customContent - * {@link AnalysisEventListener#invoke(Object, AnalysisContext) }AnalysisContext - * @param eventListener - * Callback method after each row is parsed. - * @param trim - * The content of the form is empty and needs to be empty. The purpose is to be fault-tolerant, because - * there are often table contents with spaces that can not be converted into custom types. For example: - * '1234 ' contain a space cannot be converted to int. - * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader' - */ - @Deprecated - public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent, - AnalysisEventListener eventListener, boolean trim) { - ReadWorkbook readWorkbook = new ReadWorkbook(); - readWorkbook.setInputStream(in); - readWorkbook.setExcelType(excelTypeEnum); - readWorkbook.setCustomObject(customContent); - if (eventListener != null) { - List customReadListenerList = new ArrayList(); - customReadListenerList.add(eventListener); - readWorkbook.setCustomReadListenerList(customReadListenerList); - } - readWorkbook.setAutoTrim(trim); - readWorkbook.setAutoCloseStream(Boolean.FALSE); - readWorkbook.setMandatoryUseInputStream(Boolean.TRUE); - readWorkbook.setReadCache(new MapCache()); - readWorkbook.setConvertAllFiled(Boolean.FALSE); - readWorkbook.setDefaultReturnMap(Boolean.FALSE); - // The previous logic was that Article 0 started reading - readWorkbook.setHeadRowNumber(0); - excelAnalyser = new ExcelAnalyserImpl(readWorkbook); - } - public ExcelReader(ReadWorkbook readWorkbook) { excelAnalyser = new ExcelAnalyserImpl(readWorkbook); } @@ -183,44 +68,6 @@ public class ExcelReader { return this; } - /** - * Parse the specified sheet,SheetNo start from 1 - * - * @param sheet - * Read sheet - * @deprecated please us {@link #read(ReadSheet...)} - */ - @Deprecated - public void read(Sheet sheet) { - ReadSheet readSheet = null; - if (sheet != null) { - readSheet = new ReadSheet(); - readSheet.setSheetNo(sheet.getSheetNo() - 1); - readSheet.setSheetName(sheet.getSheetName()); - readSheet.setClazz(sheet.getClazz()); - readSheet.setHead(sheet.getHead()); - readSheet.setHeadRowNumber(sheet.getHeadLineMun()); - } - read(readSheet); - } - - /** - * Parse the specified sheet - * - * @param sheet - * Read sheet - * @param clazz - * object parsed into each row of value - * - * @deprecated Set the class in the sheet before read - */ - @Deprecated - public void read(Sheet sheet, Class clazz) { - if (sheet != null) { - sheet.setClazz(clazz); - } - read(sheet); - } /** * Context for the entire execution process @@ -240,28 +87,6 @@ public class ExcelReader { return excelAnalyser.excelExecutor(); } - /** - * Parse the workBook get all sheets - * - * @return workBook all sheets - * - * @deprecated please use {@link #excelExecutor()} - */ - @Deprecated - public List getSheets() { - List sheetList = excelExecutor().sheetList(); - List sheets = new ArrayList(); - if (sheetList == null || sheetList.isEmpty()) { - return sheets; - } - for (ReadSheet readSheet : sheetList) { - Sheet sheet = new Sheet(readSheet.getSheetNo() + 1); - sheet.setSheetName(readSheet.getSheetName()); - sheets.add(sheet); - } - return sheets; - } - /** * * @return diff --git a/src/main/java/com/alibaba/excel/ExcelWriter.java b/src/main/java/com/alibaba/excel/ExcelWriter.java index 2f5b61d2..634606f7 100644 --- a/src/main/java/com/alibaba/excel/ExcelWriter.java +++ b/src/main/java/com/alibaba/excel/ExcelWriter.java @@ -1,29 +1,18 @@ package com.alibaba.excel; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.alibaba.excel.context.WriteContext; -import com.alibaba.excel.metadata.Sheet; -import com.alibaba.excel.metadata.Table; -import com.alibaba.excel.parameter.GenerateParam; -import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.write.ExcelBuilder; import com.alibaba.excel.write.ExcelBuilderImpl; -import com.alibaba.excel.write.handler.WriteHandler; -import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteTable; import com.alibaba.excel.write.metadata.WriteWorkbook; import com.alibaba.excel.write.metadata.fill.FillConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Excel Writer This tool is used to write value out to Excel via POI. This object can perform the following two * functions. @@ -49,92 +38,6 @@ public class ExcelWriter { excelBuilder = new ExcelBuilderImpl(writeWorkbook); } - /** - * Create new writer - * - * @param outputStream - * the java OutputStream you wish to write the value to - * @param typeEnum - * 03 or 07 - * @deprecated please use {@link com.alibaba.excel.write.builder.ExcelWriterBuilder} build ExcelWriter - */ - @Deprecated - public ExcelWriter(OutputStream outputStream, ExcelTypeEnum typeEnum) { - this(outputStream, typeEnum, true); - } - - /** - * - * Create new writer - * - * @param outputStream - * the java OutputStream you wish to write the value to - * @param typeEnum - * 03 or 07 - * @param needHead - * Do you need to write the header to the file? - * @deprecated please use {@link com.alibaba.excel.write.builder.ExcelWriterBuilder} build ExcelWriter - */ - @Deprecated - public ExcelWriter(OutputStream outputStream, ExcelTypeEnum typeEnum, boolean needHead) { - this(null, outputStream, typeEnum, needHead, null); - } - - /** - * Create new writer - * - * @param templateInputStream - * Append value after a POI file ,Can be null(the template POI filesystem that contains the Workbook - * stream) - * @param outputStream - * the java OutputStream you wish to write the value to - * @param typeEnum - * 03 or 07 - * @deprecated please use {@link com.alibaba.excel.write.builder.ExcelWriterBuilder} build ExcelWriter - */ - @Deprecated - public ExcelWriter(InputStream templateInputStream, OutputStream outputStream, ExcelTypeEnum typeEnum, - Boolean needHead) { - this(templateInputStream, outputStream, typeEnum, needHead, null); - } - - /** - * Create new writer - * - * @param templateInputStream - * Append value after a POI file ,Can be null(the template POI filesystem that contains the Workbook - * stream) - * @param outputStream - * the java OutputStream you wish to write the value to - * @param typeEnum - * 03 or 07 - * @param writeHandler - * User-defined callback - * @deprecated please use {@link com.alibaba.excel.write.builder.ExcelWriterBuilder} build ExcelWriter - */ - @Deprecated - public ExcelWriter(InputStream templateInputStream, OutputStream outputStream, ExcelTypeEnum typeEnum, - Boolean needHead, WriteHandler writeHandler) { - List customWriteHandlerList = new ArrayList(); - customWriteHandlerList.add(writeHandler); - WriteWorkbook writeWorkbook = new WriteWorkbook(); - writeWorkbook.setTemplateInputStream(templateInputStream); - writeWorkbook.setOutputStream(outputStream); - writeWorkbook.setExcelType(typeEnum); - writeWorkbook.setNeedHead(needHead); - writeWorkbook.setCustomWriteHandlerList(customWriteHandlerList); - excelBuilder = new ExcelBuilderImpl(writeWorkbook); - } - - /** - * @param generateParam - * @deprecated please use {@link com.alibaba.excel.write.builder.ExcelWriterBuilder} build ExcelWriter - */ - @Deprecated - public ExcelWriter(GenerateParam generateParam) { - this(generateParam.getOutputStream(), generateParam.getType(), true); - } - /** * Write data to a sheet * @@ -188,141 +91,6 @@ public class ExcelWriter { return this; } - /** - * Write data to a sheet - * - * @param data - * Data to be written - * @param sheet - * Write to this sheet - * @return this current writer - * @deprecated please use {@link ExcelWriter#write(Collection, WriteSheet)} - */ - @Deprecated - public ExcelWriter write(List data, Sheet sheet) { - return write(data, sheet, null); - } - - /** - * Write value to a sheet - * - * @param data - * Data to be written - * @param sheet - * Write to this sheet - * @param table - * Write to this table - * @return this - * @deprecated * @deprecated please use {@link ExcelWriter#write(Collection, WriteSheet,WriteTable)} - */ - @Deprecated - public ExcelWriter write(List data, Sheet sheet, Table table) { - WriteSheet writeSheet = null; - if (sheet != null) { - writeSheet = new WriteSheet(); - writeSheet.setSheetNo(sheet.getSheetNo() - 1); - writeSheet.setSheetName(sheet.getSheetName()); - writeSheet.setClazz(sheet.getClazz()); - writeSheet.setHead(sheet.getHead()); - writeSheet.setTableStyle(sheet.getTableStyle()); - writeSheet.setRelativeHeadRowIndex(sheet.getStartRow()); - writeSheet.setColumnWidthMap(sheet.getColumnWidthMap()); - } - - WriteTable writeTable = null; - if (table != null) { - writeTable = new WriteTable(); - writeTable.setTableNo(table.getTableNo()); - writeTable.setClazz(table.getClazz()); - writeTable.setHead(table.getHead()); - writeTable.setTableStyle(table.getTableStyle()); - } - return write(data, writeSheet, writeTable); - } - - /** - * Write data to a sheet - * - * @param data - * Data to be written - * @param sheet - * Write to this sheet - * @return this current writer - * @deprecated please use {@link ExcelWriter#write(Collection, WriteSheet)} - */ - @Deprecated - public ExcelWriter write0(List data, Sheet sheet) { - return write(data, sheet, null); - } - - /** - * Write value to a sheet - * - * @param data - * Data to be written - * @param sheet - * Write to this sheet - * @param table - * Write to this table - * @return this - * @deprecated * @deprecated please use {@link ExcelWriter#write(Collection, WriteSheet,WriteTable)} - */ - @Deprecated - public ExcelWriter write0(List data, Sheet sheet, Table table) { - return write(data, sheet, table); - } - - /** - * Write data to a sheet - * - * @param data - * Data to be written - * @param sheet - * Write to this sheet - * @return this current writer - * @deprecated please use {@link ExcelWriter#write(Collection, WriteSheet)} - */ - @Deprecated - public ExcelWriter write1(List data, Sheet sheet) { - return write(data, sheet, null); - } - - /** - * Write value to a sheet - * - * @param data - * Data to be written - * @param sheet - * Write to this sheet - * @param table - * Write to this table - * @return this - * @deprecated * @deprecated please use {@link ExcelWriter#write(Collection, WriteSheet,WriteTable)} - */ - @Deprecated - public ExcelWriter write1(List data, Sheet sheet, Table table) { - return write(data, sheet, table); - } - - /** - * Merge Cells,Indexes are zero-based. - * - * @param firstRow - * Index of first row - * @param lastRow - * Index of last row (inclusive), must be equal to or larger than {@code firstRow} - * @param firstCol - * Index of first column - * @param lastCol - * Index of last column (inclusive), must be equal to or larger than {@code firstCol} - * @deprecated please use{@link OnceAbsoluteMergeStrategy} - */ - @Deprecated - public ExcelWriter merge(int firstRow, int lastRow, int firstCol, int lastCol) { - excelBuilder.merge(firstRow, lastRow, firstCol, lastCol); - return this; - } - /** * Close IO */ diff --git a/src/main/java/com/alibaba/excel/analysis/v03/handlers/BlankRecordHandler.java b/src/main/java/com/alibaba/excel/analysis/v03/handlers/BlankRecordHandler.java index e6290eb5..30f09273 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/handlers/BlankRecordHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/handlers/BlankRecordHandler.java @@ -5,7 +5,7 @@ import org.apache.poi.hssf.record.Record; import com.alibaba.excel.analysis.v03.IgnorableXlsRecordHandler; import com.alibaba.excel.context.xls.XlsReadContext; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; /** * Record handler diff --git a/src/main/java/com/alibaba/excel/analysis/v03/handlers/BoolErrRecordHandler.java b/src/main/java/com/alibaba/excel/analysis/v03/handlers/BoolErrRecordHandler.java index 8d435213..1afb6c1f 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/handlers/BoolErrRecordHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/handlers/BoolErrRecordHandler.java @@ -6,7 +6,7 @@ import org.apache.poi.hssf.record.Record; import com.alibaba.excel.analysis.v03.IgnorableXlsRecordHandler; import com.alibaba.excel.context.xls.XlsReadContext; import com.alibaba.excel.enums.RowTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; /** * Record handler diff --git a/src/main/java/com/alibaba/excel/analysis/v03/handlers/DummyRecordHandler.java b/src/main/java/com/alibaba/excel/analysis/v03/handlers/DummyRecordHandler.java index 54a2d1df..eb5bd2ae 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/handlers/DummyRecordHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/handlers/DummyRecordHandler.java @@ -10,7 +10,7 @@ import com.alibaba.excel.analysis.v03.IgnorableXlsRecordHandler; import com.alibaba.excel.context.xls.XlsReadContext; import com.alibaba.excel.enums.RowTypeEnum; import com.alibaba.excel.metadata.Cell; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.read.metadata.holder.ReadRowHolder; import com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder; diff --git a/src/main/java/com/alibaba/excel/analysis/v03/handlers/FormulaRecordHandler.java b/src/main/java/com/alibaba/excel/analysis/v03/handlers/FormulaRecordHandler.java index 5f18b841..f5d7ff0a 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/handlers/FormulaRecordHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/handlers/FormulaRecordHandler.java @@ -9,29 +9,30 @@ import com.alibaba.excel.context.xls.XlsReadContext; import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.enums.RowTypeEnum; import com.alibaba.excel.metadata.Cell; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.DataFormatData; +import com.alibaba.excel.metadata.data.FormulaData; +import com.alibaba.excel.metadata.data.ReadCellData; +import lombok.extern.slf4j.Slf4j; import org.apache.poi.hssf.model.HSSFFormulaParser; import org.apache.poi.hssf.record.FormulaRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.ss.usermodel.CellType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Record handler * * @author Dan Zheng */ +@Slf4j public class FormulaRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { - private static final Logger LOGGER = LoggerFactory.getLogger(FormulaRecordHandler.class); private static final String ERROR = "#VALUE!"; @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { FormulaRecord frec = (FormulaRecord)record; Map cellMap = xlsReadContext.xlsReadSheetHolder().getCellMap(); - CellData tempCellData = new CellData<>(); + ReadCellData tempCellData = new ReadCellData<>(); tempCellData.setRowIndex(frec.getRow()); tempCellData.setColumnIndex((int)frec.getColumn()); CellType cellType = CellType.forInt(frec.getCachedResultType()); @@ -40,10 +41,11 @@ public class FormulaRecordHandler extends AbstractXlsRecordHandler implements Ig formulaValue = HSSFFormulaParser.toFormulaString(xlsReadContext.xlsReadWorkbookHolder().getHssfWorkbook(), frec.getParsedExpression()); } catch (Exception e) { - LOGGER.debug("Get formula value error.", e); + log.debug("Get formula value error.", e); } - tempCellData.setFormula(Boolean.TRUE); - tempCellData.setFormulaValue(formulaValue); + FormulaData formulaData = new FormulaData(); + formulaData.setFormulaValue(formulaValue); + tempCellData.setFormulaData(formulaData); xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA); switch (cellType) { case STRING: @@ -55,11 +57,11 @@ public class FormulaRecordHandler extends AbstractXlsRecordHandler implements Ig case NUMERIC: tempCellData.setType(CellDataTypeEnum.NUMBER); tempCellData.setNumberValue(BigDecimal.valueOf(frec.getValue())); - Integer dataFormat = + int dataFormat = xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatIndex(frec); - Short dataFormatShort = dataFormat.shortValue(); - tempCellData.setDataFormat(dataFormatShort); - tempCellData.setDataFormatString(BuiltinFormats.getBuiltinFormat(dataFormatShort, + DataFormatData dataFormatData = new DataFormatData(); + dataFormatData.setIndex((short)dataFormat); + dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormatData.getIndex(), xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatString(frec), xlsReadContext.readSheetHolder().getGlobalConfiguration().getLocale())); cellMap.put((int)frec.getColumn(), tempCellData); diff --git a/src/main/java/com/alibaba/excel/analysis/v03/handlers/LabelRecordHandler.java b/src/main/java/com/alibaba/excel/analysis/v03/handlers/LabelRecordHandler.java index 4f63ab0c..39481de0 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/handlers/LabelRecordHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/handlers/LabelRecordHandler.java @@ -6,7 +6,7 @@ import org.apache.poi.hssf.record.Record; import com.alibaba.excel.analysis.v03.IgnorableXlsRecordHandler; import com.alibaba.excel.context.xls.XlsReadContext; import com.alibaba.excel.enums.RowTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; /** * Record handler diff --git a/src/main/java/com/alibaba/excel/analysis/v03/handlers/LabelSstRecordHandler.java b/src/main/java/com/alibaba/excel/analysis/v03/handlers/LabelSstRecordHandler.java index 7fb5cd0d..0075254c 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/handlers/LabelSstRecordHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/handlers/LabelSstRecordHandler.java @@ -10,7 +10,7 @@ import com.alibaba.excel.cache.ReadCache; import com.alibaba.excel.context.xls.XlsReadContext; import com.alibaba.excel.enums.RowTypeEnum; import com.alibaba.excel.metadata.Cell; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; /** * Record handler diff --git a/src/main/java/com/alibaba/excel/analysis/v03/handlers/NumberRecordHandler.java b/src/main/java/com/alibaba/excel/analysis/v03/handlers/NumberRecordHandler.java index f9e27c7a..1573b8e7 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/handlers/NumberRecordHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/handlers/NumberRecordHandler.java @@ -6,7 +6,8 @@ import com.alibaba.excel.analysis.v03.IgnorableXlsRecordHandler; import com.alibaba.excel.constant.BuiltinFormats; import com.alibaba.excel.context.xls.XlsReadContext; import com.alibaba.excel.enums.RowTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.DataFormatData; +import com.alibaba.excel.metadata.data.ReadCellData; import org.apache.poi.hssf.record.NumberRecord; import org.apache.poi.hssf.record.Record; @@ -21,13 +22,16 @@ public class NumberRecordHandler extends AbstractXlsRecordHandler implements Ign @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { NumberRecord nr = (NumberRecord)record; - CellDatacellData = CellData.newInstance(BigDecimal.valueOf(nr.getValue()), nr.getRow(), (int)nr.getColumn()); + ReadCellData cellData = ReadCellData.newInstance(BigDecimal.valueOf(nr.getValue()), nr.getRow(), + (int)nr.getColumn()); short dataFormat = (short)xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatIndex( nr); - cellData.setDataFormat(dataFormat); - cellData.setDataFormatString(BuiltinFormats.getBuiltinFormat(dataFormat, + DataFormatData dataFormatData = new DataFormatData(); + dataFormatData.setIndex(dataFormat); + dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormat, xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatString(nr), xlsReadContext.readSheetHolder().getGlobalConfiguration().getLocale())); + cellData.setDataFormatData(dataFormatData); xlsReadContext.xlsReadSheetHolder().getCellMap().put((int)nr.getColumn(), cellData); xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA); } diff --git a/src/main/java/com/alibaba/excel/analysis/v03/handlers/RkRecordHandler.java b/src/main/java/com/alibaba/excel/analysis/v03/handlers/RkRecordHandler.java index d8317b37..91c3c9f8 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/handlers/RkRecordHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/handlers/RkRecordHandler.java @@ -5,7 +5,7 @@ import org.apache.poi.hssf.record.Record; import com.alibaba.excel.analysis.v03.IgnorableXlsRecordHandler; import com.alibaba.excel.context.xls.XlsReadContext; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; /** * Record handler diff --git a/src/main/java/com/alibaba/excel/analysis/v03/handlers/StringRecordHandler.java b/src/main/java/com/alibaba/excel/analysis/v03/handlers/StringRecordHandler.java index 2408d219..4e78a381 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/handlers/StringRecordHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/handlers/StringRecordHandler.java @@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory; import com.alibaba.excel.analysis.v03.IgnorableXlsRecordHandler; import com.alibaba.excel.context.xls.XlsReadContext; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder; /** diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/AbstractCellValueTagHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/AbstractCellValueTagHandler.java index 770355b0..ac2b8457 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/AbstractCellValueTagHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/AbstractCellValueTagHandler.java @@ -4,7 +4,7 @@ import java.math.BigDecimal; import com.alibaba.excel.context.xlsx.XlsxReadContext; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; import com.alibaba.excel.util.BooleanUtils; import com.alibaba.excel.util.StringUtils; diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellFormulaTagHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellFormulaTagHandler.java index e153a3b1..6e5246d3 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellFormulaTagHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellFormulaTagHandler.java @@ -1,10 +1,11 @@ package com.alibaba.excel.analysis.v07.handlers; -import org.xml.sax.Attributes; - import com.alibaba.excel.context.xlsx.XlsxReadContext; +import com.alibaba.excel.metadata.data.FormulaData; import com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; +import org.xml.sax.Attributes; + /** * Cell Handler * @@ -15,14 +16,15 @@ public class CellFormulaTagHandler extends AbstractXlsxTagHandler { @Override public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) { XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); - xlsxReadSheetHolder.getTempCellData().setFormula(Boolean.TRUE); xlsxReadSheetHolder.setTempFormula(new StringBuilder()); } @Override public void endElement(XlsxReadContext xlsxReadContext, String name) { XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); - xlsxReadSheetHolder.getTempCellData().setFormulaValue(xlsxReadSheetHolder.getTempFormula().toString()); + FormulaData formulaData = new FormulaData(); + formulaData.setFormulaValue(xlsxReadSheetHolder.getTempFormula().toString()); + xlsxReadSheetHolder.getTempCellData().setFormulaData(formulaData); } @Override diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellInlineStringValueTagHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellInlineStringValueTagHandler.java index 3058e8e8..99c4a8c5 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellInlineStringValueTagHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellInlineStringValueTagHandler.java @@ -1,9 +1,9 @@ package com.alibaba.excel.analysis.v07.handlers; -import org.apache.poi.xssf.usermodel.XSSFRichTextString; - import com.alibaba.excel.context.xlsx.XlsxReadContext; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; + +import org.apache.poi.xssf.usermodel.XSSFRichTextString; /** * Cell inline string value handler diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellTagHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellTagHandler.java index 135153e0..4a58bf78 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellTagHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellTagHandler.java @@ -4,7 +4,8 @@ import com.alibaba.excel.constant.BuiltinFormats; import com.alibaba.excel.constant.ExcelXmlConstants; import com.alibaba.excel.context.xlsx.XlsxReadContext; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.DataFormatData; +import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; import com.alibaba.excel.util.PositionUtils; import com.alibaba.excel.util.StringUtils; @@ -36,7 +37,7 @@ public class CellTagHandler extends AbstractXlsxTagHandler { // t="n" ,it's means Number // t is null ,it's means Empty or Number CellDataTypeEnum type = CellDataTypeEnum.buildFromCellType(attributes.getValue(ExcelXmlConstants.ATTRIBUTE_T)); - xlsxReadSheetHolder.setTempCellData(new CellData(type)); + xlsxReadSheetHolder.setTempCellData(new ReadCellData<>(type)); xlsxReadSheetHolder.setTempData(new StringBuilder()); // Put in data transformation information @@ -53,9 +54,11 @@ public class CellTagHandler extends AbstractXlsxTagHandler { } XSSFCellStyle xssfCellStyle = stylesTable.getStyleAt(dateFormatIndexInteger); short dataFormat = xssfCellStyle.getDataFormat(); - xlsxReadSheetHolder.getTempCellData().setDataFormat(dataFormat); - xlsxReadSheetHolder.getTempCellData().setDataFormatString(BuiltinFormats.getBuiltinFormat(dataFormat, + DataFormatData dataFormatData = new DataFormatData(); + dataFormatData.setIndex(dataFormat); + dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormat, xssfCellStyle.getDataFormatString(), xlsxReadSheetHolder.getGlobalConfiguration().getLocale())); + xlsxReadSheetHolder.getTempCellData().setDataFormatData(dataFormatData); } } diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellValueTagHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellValueTagHandler.java index 7e685c97..bd623f4a 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellValueTagHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellValueTagHandler.java @@ -2,7 +2,7 @@ package com.alibaba.excel.analysis.v07.handlers; import com.alibaba.excel.context.xlsx.XlsxReadContext; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.util.StringUtils; /** diff --git a/src/main/java/com/alibaba/excel/context/AnalysisContext.java b/src/main/java/com/alibaba/excel/context/AnalysisContext.java index df17f55d..37039cbc 100644 --- a/src/main/java/com/alibaba/excel/context/AnalysisContext.java +++ b/src/main/java/com/alibaba/excel/context/AnalysisContext.java @@ -4,7 +4,6 @@ import java.io.InputStream; import java.util.List; import com.alibaba.excel.event.AnalysisEventListener; -import com.alibaba.excel.metadata.Sheet; import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.holder.ReadHolder; import com.alibaba.excel.read.metadata.holder.ReadRowHolder; @@ -92,15 +91,6 @@ public interface AnalysisContext { */ void readSheetList(List readSheetList); - /** - * get current sheet - * - * @return current analysis sheet - * @deprecated please use {@link #readSheetHolder()} - */ - @Deprecated - Sheet getCurrentSheet(); - /** * * get excel type diff --git a/src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java b/src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java index ab27e87e..7aeba321 100644 --- a/src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java +++ b/src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java @@ -3,11 +3,7 @@ package com.alibaba.excel.context; import java.io.InputStream; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.alibaba.excel.exception.ExcelAnalysisException; -import com.alibaba.excel.metadata.Sheet; import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.ReadWorkbook; import com.alibaba.excel.read.metadata.holder.ReadHolder; @@ -22,12 +18,13 @@ import com.alibaba.excel.read.processor.AnalysisEventProcessor; import com.alibaba.excel.read.processor.DefaultAnalysisEventProcessor; import com.alibaba.excel.support.ExcelTypeEnum; +import lombok.extern.slf4j.Slf4j; + /** - * * @author jipengfei */ +@Slf4j public class AnalysisContextImpl implements AnalysisContext { - private static final Logger LOGGER = LoggerFactory.getLogger(AnalysisContextImpl.class); /** * The Workbook currently written */ @@ -65,8 +62,8 @@ public class AnalysisContextImpl implements AnalysisContext { } currentReadHolder = readWorkbookHolder; analysisEventProcessor = new DefaultAnalysisEventProcessor(); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Initialization 'AnalysisContextImpl' complete"); + if (log.isDebugEnabled()) { + log.debug("Initialization 'AnalysisContextImpl' complete"); } } @@ -87,8 +84,8 @@ public class AnalysisContextImpl implements AnalysisContext { throw new ExcelAnalysisException("Cannot read sheet repeatedly."); } readWorkbookHolder.getHasReadSheet().add(readSheetHolder.getSheetNo()); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Began to read:{}", readSheetHolder); + if (log.isDebugEnabled()) { + log.debug("Began to read:{}", readSheetHolder); } } @@ -137,15 +134,6 @@ public class AnalysisContextImpl implements AnalysisContext { } - @Override - public Sheet getCurrentSheet() { - Sheet sheet = new Sheet(readSheetHolder.getSheetNo() + 1); - sheet.setSheetName(readSheetHolder.getSheetName()); - sheet.setHead(readSheetHolder.getHead()); - sheet.setClazz(readSheetHolder.getClazz()); - sheet.setHeadLineMun(readSheetHolder.getHeadRowNumber()); - return sheet; - } @Override public ExcelTypeEnum getExcelType() { diff --git a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java index 648a7fe9..175f33da 100644 --- a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java +++ b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java @@ -8,7 +8,7 @@ import java.util.UUID; import com.alibaba.excel.enums.WriteTypeEnum; import com.alibaba.excel.exception.ExcelGenerateException; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.util.DateUtils; diff --git a/src/main/java/com/alibaba/excel/converters/AutoConverter.java b/src/main/java/com/alibaba/excel/converters/AutoConverter.java index 07ad471f..5981e7ac 100644 --- a/src/main/java/com/alibaba/excel/converters/AutoConverter.java +++ b/src/main/java/com/alibaba/excel/converters/AutoConverter.java @@ -1,36 +1,9 @@ package com.alibaba.excel.converters; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; -import com.alibaba.excel.metadata.GlobalConfiguration; -import com.alibaba.excel.metadata.property.ExcelContentProperty; - /** * An empty converter.It's automatically converted by type. * * @author Jiaju Zhuang */ public class AutoConverter implements Converter { - - @Override - public Class supportJavaTypeKey() { - return null; - } - - @Override - public CellDataTypeEnum supportExcelTypeKey() { - return null; - } - - @Override - public Object convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, - GlobalConfiguration globalConfiguration) { - return null; - } - - @Override - public CellData convertToExcelData(Object value, ExcelContentProperty contentProperty, - GlobalConfiguration globalConfiguration) { - return null; - } } diff --git a/src/main/java/com/alibaba/excel/converters/Converter.java b/src/main/java/com/alibaba/excel/converters/Converter.java index 3d1a369d..df7f4719 100644 --- a/src/main/java/com/alibaba/excel/converters/Converter.java +++ b/src/main/java/com/alibaba/excel/converters/Converter.java @@ -1,13 +1,10 @@ package com.alibaba.excel.converters; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; -import com.alibaba.excel.read.metadata.holder.ReadSheetHolder; -import com.alibaba.excel.write.metadata.holder.WriteHolder; -import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; -import com.alibaba.excel.write.metadata.holder.WriteTableHolder; /** * Convert between Java objects and excel objects @@ -44,7 +41,7 @@ public interface Converter { * @return Data to put into a Java object * @throws Exception Exception. */ - default T convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + default T convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { throw new UnsupportedOperationException("The current operation is not supported by the current converter."); } @@ -52,15 +49,13 @@ public interface Converter { /** * Convert excel objects to Java objects * - * @param cellData Excel cell data.NotNull. - * @param contentProperty Content property.Nullable. - * @param readSheetHolder .NotNull. + * @param context read converter context * @return Data to put into a Java object * @throws Exception Exception. */ - default T convertToJavaData(CellData cellData, - ExcelContentProperty contentProperty, ReadSheetHolder readSheetHolder) throws Exception { - return convertToJavaData(cellData, contentProperty, readSheetHolder.globalConfiguration()); + default T convertToJavaData(ReadConverterContext context) throws Exception { + return convertToJavaData(context.getReadCellData(), context.getContentProperty(), + context.getAnalysisContext().currentReadHolder().globalConfiguration()); } /** @@ -72,7 +67,7 @@ public interface Converter { * @return Data to put into a Excel * @throws Exception Exception. */ - default CellData convertToExcelData(T value, ExcelContentProperty contentProperty, + default WriteCellData convertToExcelData(T value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { throw new UnsupportedOperationException("The current operation is not supported by the current converter."); } @@ -80,14 +75,12 @@ public interface Converter { /** * Convert Java objects to excel objects * - * @param value Java Data.NotNull. - * @param contentProperty Content property.Nullable. - * @param currentWriteHolder He would be {@link WriteSheetHolder} or {@link WriteTableHolder}.NotNull. + * @param context write context * @return Data to put into a Excel * @throws Exception Exception. */ - default CellData convertToExcelData(T value, ExcelContentProperty contentProperty, - WriteHolder currentWriteHolder) throws Exception { - return convertToExcelData(value, contentProperty, currentWriteHolder.globalConfiguration()); + default WriteCellData convertToExcelData(WriteConverterContext context) throws Exception { + return convertToExcelData(context.getValue(), context.getContentProperty(), + context.getWriteContext().currentWriteHolder().globalConfiguration()); } } diff --git a/src/main/java/com/alibaba/excel/converters/ReadConverterContext.java b/src/main/java/com/alibaba/excel/converters/ReadConverterContext.java new file mode 100644 index 00000000..e1367065 --- /dev/null +++ b/src/main/java/com/alibaba/excel/converters/ReadConverterContext.java @@ -0,0 +1,30 @@ +package com.alibaba.excel.converters; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * read converter context + * + * @author Jiaju Zhuang + */ +@Data +@AllArgsConstructor +public class ReadConverterContext { + /** + * Excel cell data.NotNull. + */ + private ReadCellData readCellData; + /** + * Content property.Nullable. + */ + private ExcelContentProperty contentProperty; + /** + * context.NotNull. + */ + private AnalysisContext analysisContext; +} diff --git a/src/main/java/com/alibaba/excel/converters/WriteConverterContext.java b/src/main/java/com/alibaba/excel/converters/WriteConverterContext.java new file mode 100644 index 00000000..b1d0a5dd --- /dev/null +++ b/src/main/java/com/alibaba/excel/converters/WriteConverterContext.java @@ -0,0 +1,31 @@ +package com.alibaba.excel.converters; + +import com.alibaba.excel.context.WriteContext; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + +import lombok.Data; + +/** + * write converter context + * + * @author Jiaju Zhuang + */ +@Data +@AllArgsConstructor +public class WriteConverterContext { + + /** + * Java Data.NotNull. + */ + private T value; + + /** + * Content property.Nullable. + */ + private ExcelContentProperty contentProperty; + + /** + * write context + */ + private WriteContext writeContext; +} diff --git a/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalBooleanConverter.java b/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalBooleanConverter.java index f4e9ad6f..31484562 100644 --- a/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalBooleanConverter.java +++ b/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalBooleanConverter.java @@ -4,8 +4,9 @@ import java.math.BigDecimal; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -26,7 +27,7 @@ public class BigDecimalBooleanConverter implements Converter { } @Override - public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public BigDecimal convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return BigDecimal.ONE; @@ -35,12 +36,12 @@ public class BigDecimalBooleanConverter implements Converter { } @Override - public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (BigDecimal.ONE.equals(value)) { - return new CellData<>(Boolean.TRUE); + return new WriteCellData<>(Boolean.TRUE); } - return new CellData<>(Boolean.FALSE); + return new WriteCellData<>(Boolean.FALSE); } } diff --git a/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalNumberConverter.java b/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalNumberConverter.java index 39061d70..6a60b0d7 100644 --- a/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalNumberConverter.java @@ -4,8 +4,9 @@ import java.math.BigDecimal; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; import com.alibaba.excel.write.metadata.holder.WriteHolder; @@ -28,13 +29,13 @@ public class BigDecimalNumberConverter implements Converter { } @Override - public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public BigDecimal convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getNumberValue(); } @Override - public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, WriteHolder currentWriteHolder) { return NumberUtils.formatToCellData(value, contentProperty, currentWriteHolder); } diff --git a/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalStringConverter.java b/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalStringConverter.java index 356a38c5..3b117812 100644 --- a/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalStringConverter.java @@ -5,8 +5,9 @@ import java.text.ParseException; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; @@ -28,13 +29,13 @@ public class BigDecimalStringConverter implements Converter { } @Override - public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public BigDecimal convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { return NumberUtils.parseBigDecimal(cellData.getStringValue(), contentProperty); } @Override - public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellDataString(value, contentProperty); } diff --git a/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanBooleanConverter.java b/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanBooleanConverter.java index 56654cd5..884f6515 100644 --- a/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanBooleanConverter.java +++ b/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanBooleanConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.booleanconverter; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -24,15 +25,15 @@ public class BooleanBooleanConverter implements Converter { } @Override - public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Boolean convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getBooleanValue(); } @Override - public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - return new CellData<>(value); + return new WriteCellData<>(value); } } diff --git a/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java b/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java index 00cd4c2c..b2438e83 100644 --- a/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java @@ -4,8 +4,9 @@ import java.math.BigDecimal; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -25,7 +26,7 @@ public class BooleanNumberConverter implements Converter { } @Override - public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Boolean convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (BigDecimal.ONE.compareTo(cellData.getNumberValue()) == 0) { return Boolean.TRUE; @@ -34,12 +35,12 @@ public class BooleanNumberConverter implements Converter { } @Override - public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (value) { - return new CellData<>(BigDecimal.ONE); + return new WriteCellData<>(BigDecimal.ONE); } - return new CellData<>(BigDecimal.ZERO); + return new WriteCellData<>(BigDecimal.ZERO); } } diff --git a/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanStringConverter.java b/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanStringConverter.java index 9f82f32a..0141ef8d 100644 --- a/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanStringConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.booleanconverter; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -24,15 +25,15 @@ public class BooleanStringConverter implements Converter { } @Override - public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Boolean convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return Boolean.valueOf(cellData.getStringValue()); } @Override - public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - return new CellData<>(value.toString()); + return new WriteCellData<>(value.toString()); } } diff --git a/src/main/java/com/alibaba/excel/converters/bytearray/BoxingByteArrayImageConverter.java b/src/main/java/com/alibaba/excel/converters/bytearray/BoxingByteArrayImageConverter.java index 63f387d7..a1f8d3ac 100644 --- a/src/main/java/com/alibaba/excel/converters/bytearray/BoxingByteArrayImageConverter.java +++ b/src/main/java/com/alibaba/excel/converters/bytearray/BoxingByteArrayImageConverter.java @@ -1,12 +1,8 @@ package com.alibaba.excel.converters.bytearray; -import java.lang.annotation.Annotation; - -import com.alibaba.excel.annotation.write.style.ImagePosition; import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -21,29 +17,13 @@ public class BoxingByteArrayImageConverter implements Converter { } @Override - public CellDataTypeEnum supportExcelTypeKey() { - return CellDataTypeEnum.IMAGE; - } - - @Override - public Byte[] convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, - GlobalConfiguration globalConfiguration) { - throw new UnsupportedOperationException("Cannot convert images to byte arrays"); - } - - @Override - public CellData convertToExcelData(Byte[] value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Byte[] value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { byte[] byteValue = new byte[value.length]; for (int i = 0; i < value.length; i++) { byteValue[i] = value[i]; } - ImagePosition imagePosition = contentProperty.getField().getAnnotation(ImagePosition.class); - if (imagePosition != null) { - return new CellData(byteValue, imagePosition); - } else { - return new CellData(byteValue); - } + return new WriteCellData<>(byteValue); } } diff --git a/src/main/java/com/alibaba/excel/converters/bytearray/ByteArrayImageConverter.java b/src/main/java/com/alibaba/excel/converters/bytearray/ByteArrayImageConverter.java index 48b70cbb..9a871fea 100644 --- a/src/main/java/com/alibaba/excel/converters/bytearray/ByteArrayImageConverter.java +++ b/src/main/java/com/alibaba/excel/converters/bytearray/ByteArrayImageConverter.java @@ -1,12 +1,8 @@ package com.alibaba.excel.converters.bytearray; -import java.lang.annotation.Annotation; - -import com.alibaba.excel.annotation.write.style.ImagePosition; import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -15,32 +11,16 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty; * @author Jiaju Zhuang */ public class ByteArrayImageConverter implements Converter { + @Override public Class supportJavaTypeKey() { return byte[].class; } @Override - public CellDataTypeEnum supportExcelTypeKey() { - return CellDataTypeEnum.IMAGE; - } - - @Override - - public byte[] convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(byte[] value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - throw new UnsupportedOperationException("Cannot convert images to byte arrays"); - } - - @Override - public CellData convertToExcelData(byte[] value, ExcelContentProperty contentProperty, - GlobalConfiguration globalConfiguration) { - ImagePosition imagePosition = contentProperty.getField().getAnnotation(ImagePosition.class); - if (imagePosition != null) { - return new CellData(value, imagePosition); - } else { - return new CellData(value); - } + return new WriteCellData<>(value); } } diff --git a/src/main/java/com/alibaba/excel/converters/byteconverter/ByteBooleanConverter.java b/src/main/java/com/alibaba/excel/converters/byteconverter/ByteBooleanConverter.java index afe079cb..c7da08c4 100644 --- a/src/main/java/com/alibaba/excel/converters/byteconverter/ByteBooleanConverter.java +++ b/src/main/java/com/alibaba/excel/converters/byteconverter/ByteBooleanConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.byteconverter; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -26,7 +27,7 @@ public class ByteBooleanConverter implements Converter { } @Override - public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Byte convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; @@ -35,12 +36,12 @@ public class ByteBooleanConverter implements Converter { } @Override - public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Byte value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { - return new CellData<>(Boolean.TRUE); + return new WriteCellData<>(Boolean.TRUE); } - return new CellData<>(Boolean.FALSE); + return new WriteCellData<>(Boolean.FALSE); } } diff --git a/src/main/java/com/alibaba/excel/converters/byteconverter/ByteNumberConverter.java b/src/main/java/com/alibaba/excel/converters/byteconverter/ByteNumberConverter.java index 891ae714..4103b9cb 100644 --- a/src/main/java/com/alibaba/excel/converters/byteconverter/ByteNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/byteconverter/ByteNumberConverter.java @@ -1,14 +1,12 @@ package com.alibaba.excel.converters.byteconverter; -import java.math.BigDecimal; - import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; -import com.alibaba.excel.write.metadata.holder.WriteHolder; /** * Byte and number converter @@ -28,15 +26,15 @@ public class ByteNumberConverter implements Converter { } @Override - public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Byte convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getNumberValue().byteValue(); } @Override - public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty, - WriteHolder currentWriteHolder) { - return NumberUtils.formatToCellData(value, contentProperty, currentWriteHolder); + public WriteCellData convertToExcelData(Byte value, ExcelContentProperty contentProperty, + GlobalConfiguration globalConfiguration) { + return NumberUtils.formatToCellData(value, contentProperty); } } diff --git a/src/main/java/com/alibaba/excel/converters/byteconverter/ByteStringConverter.java b/src/main/java/com/alibaba/excel/converters/byteconverter/ByteStringConverter.java index 041557cf..988afbc6 100644 --- a/src/main/java/com/alibaba/excel/converters/byteconverter/ByteStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/byteconverter/ByteStringConverter.java @@ -4,8 +4,9 @@ import java.text.ParseException; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; @@ -27,13 +28,13 @@ public class ByteStringConverter implements Converter { } @Override - public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Byte convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { return NumberUtils.parseByte(cellData.getStringValue(), contentProperty); } @Override - public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Byte value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellDataString(value, contentProperty); } diff --git a/src/main/java/com/alibaba/excel/converters/date/DateDateConverter.java b/src/main/java/com/alibaba/excel/converters/date/DateDateConverter.java index 73b071af..68daee84 100644 --- a/src/main/java/com/alibaba/excel/converters/date/DateDateConverter.java +++ b/src/main/java/com/alibaba/excel/converters/date/DateDateConverter.java @@ -3,12 +3,10 @@ package com.alibaba.excel.converters.date; import java.util.Date; import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.WorkBookUtil; -import com.alibaba.excel.write.metadata.holder.WriteHolder; /** * Date and date converter @@ -22,26 +20,14 @@ public class DateDateConverter implements Converter { } @Override - public CellDataTypeEnum supportExcelTypeKey() { - return CellDataTypeEnum.DATE; - } - - @Override - public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, - GlobalConfiguration globalConfiguration) { - return cellData.getDateValue(); - } - - @Override - public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty, - WriteHolder currentWriteHolder) throws Exception { - CellData cellData = new CellData<>(value); + public WriteCellData convertToExcelData(Date value, ExcelContentProperty contentProperty, + GlobalConfiguration globalConfiguration) throws Exception { + WriteCellData cellData = new WriteCellData<>(value); if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null || contentProperty.getDateTimeFormatProperty().getFormat() == null) { return cellData; } - WorkBookUtil.fillDataFormat(cellData, currentWriteHolder, - contentProperty.getDateTimeFormatProperty().getFormat()); + WorkBookUtil.fillDataFormat(cellData, contentProperty.getDateTimeFormatProperty().getFormat()); return cellData; } } diff --git a/src/main/java/com/alibaba/excel/converters/date/DateNumberConverter.java b/src/main/java/com/alibaba/excel/converters/date/DateNumberConverter.java index 6eee4de0..34bb7536 100644 --- a/src/main/java/com/alibaba/excel/converters/date/DateNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/date/DateNumberConverter.java @@ -3,14 +3,15 @@ package com.alibaba.excel.converters.date; import java.math.BigDecimal; import java.util.Date; -import org.apache.poi.ss.usermodel.DateUtil; - import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; +import org.apache.poi.ss.usermodel.DateUtil; + /** * Date and number converter * @@ -29,7 +30,7 @@ public class DateNumberConverter implements Converter { } @Override - public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Date convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { return DateUtil.getJavaDate(cellData.getNumberValue().doubleValue(), @@ -41,13 +42,13 @@ public class DateNumberConverter implements Converter { } @Override - public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { - return new CellData<>( + return new WriteCellData<>( BigDecimal.valueOf(DateUtil.getExcelDate(value, globalConfiguration.getUse1904windowing()))); } else { - return new CellData<>(BigDecimal.valueOf( + return new WriteCellData<>(BigDecimal.valueOf( DateUtil.getExcelDate(value, contentProperty.getDateTimeFormatProperty().getUse1904windowing()))); } } diff --git a/src/main/java/com/alibaba/excel/converters/date/DateStringConverter.java b/src/main/java/com/alibaba/excel/converters/date/DateStringConverter.java index 687d84d7..9941c70e 100644 --- a/src/main/java/com/alibaba/excel/converters/date/DateStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/date/DateStringConverter.java @@ -5,8 +5,9 @@ import java.util.Date; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.DateUtils; @@ -27,7 +28,7 @@ public class DateStringConverter implements Converter { } @Override - public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Date convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { return DateUtils.parseDate(cellData.getStringValue(), null); @@ -38,12 +39,12 @@ public class DateStringConverter implements Converter { } @Override - public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { - return new CellData<>(DateUtils.format(value, null)); + return new WriteCellData<>(DateUtils.format(value, null)); } else { - return new CellData<>(DateUtils.format(value, contentProperty.getDateTimeFormatProperty().getFormat())); + return new WriteCellData<>(DateUtils.format(value, contentProperty.getDateTimeFormatProperty().getFormat())); } } } diff --git a/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleBooleanConverter.java b/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleBooleanConverter.java index 6aa509e1..3da808e1 100644 --- a/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleBooleanConverter.java +++ b/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleBooleanConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.doubleconverter; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -26,7 +27,7 @@ public class DoubleBooleanConverter implements Converter { } @Override - public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Double convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; @@ -35,12 +36,12 @@ public class DoubleBooleanConverter implements Converter { } @Override - public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Double value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { - return new CellData<>(Boolean.TRUE); + return new WriteCellData<>(Boolean.TRUE); } - return new CellData<>(Boolean.FALSE); + return new WriteCellData<>(Boolean.FALSE); } } diff --git a/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleNumberConverter.java b/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleNumberConverter.java index c3db3d3b..70bdffb6 100644 --- a/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleNumberConverter.java @@ -1,14 +1,12 @@ package com.alibaba.excel.converters.doubleconverter; -import java.math.BigDecimal; - import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; -import com.alibaba.excel.write.metadata.holder.WriteHolder; /** * Double and number converter @@ -28,14 +26,14 @@ public class DoubleNumberConverter implements Converter { } @Override - public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Double convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getNumberValue().doubleValue(); } @Override - public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty, - WriteHolder currentWriteHolder) { - return NumberUtils.formatToCellData(value, contentProperty, currentWriteHolder); + public WriteCellData convertToExcelData(Double value, ExcelContentProperty contentProperty, + GlobalConfiguration globalConfiguration) { + return NumberUtils.formatToCellData(value, contentProperty); } } diff --git a/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleStringConverter.java b/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleStringConverter.java index 351d0b8a..e1951130 100644 --- a/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleStringConverter.java @@ -4,8 +4,9 @@ import java.text.ParseException; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; @@ -27,13 +28,13 @@ public class DoubleStringConverter implements Converter { } @Override - public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Double convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { return NumberUtils.parseDouble(cellData.getStringValue(), contentProperty); } @Override - public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Double value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellDataString(value, contentProperty); } diff --git a/src/main/java/com/alibaba/excel/converters/file/FileImageConverter.java b/src/main/java/com/alibaba/excel/converters/file/FileImageConverter.java index a94f7c08..c8fd6e8b 100644 --- a/src/main/java/com/alibaba/excel/converters/file/FileImageConverter.java +++ b/src/main/java/com/alibaba/excel/converters/file/FileImageConverter.java @@ -2,11 +2,10 @@ package com.alibaba.excel.converters.file; import java.io.File; import java.io.IOException; -import com.alibaba.excel.annotation.write.style.ImagePosition; + import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.FileUtils; @@ -22,24 +21,8 @@ public class FileImageConverter implements Converter { } @Override - public CellDataTypeEnum supportExcelTypeKey() { - return CellDataTypeEnum.IMAGE; - } - - @Override - public File convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, - GlobalConfiguration globalConfiguration) { - throw new UnsupportedOperationException("Cannot convert images to file"); - } - - @Override - public CellData convertToExcelData(File value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(File value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws IOException { - ImagePosition imagePosition = contentProperty.getField().getAnnotation(ImagePosition.class); - if (imagePosition != null) { - return new CellData(FileUtils.readFileToByteArray(value), imagePosition); - } else { - return new CellData(FileUtils.readFileToByteArray(value)); - } + return new WriteCellData<>(FileUtils.readFileToByteArray(value)); } } diff --git a/src/main/java/com/alibaba/excel/converters/floatconverter/FloatBooleanConverter.java b/src/main/java/com/alibaba/excel/converters/floatconverter/FloatBooleanConverter.java index c2f674f2..1ec6168c 100644 --- a/src/main/java/com/alibaba/excel/converters/floatconverter/FloatBooleanConverter.java +++ b/src/main/java/com/alibaba/excel/converters/floatconverter/FloatBooleanConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.floatconverter; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -26,7 +27,7 @@ public class FloatBooleanConverter implements Converter { } @Override - public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Float convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; @@ -35,12 +36,12 @@ public class FloatBooleanConverter implements Converter { } @Override - public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Float value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { - return new CellData<>(Boolean.TRUE); + return new WriteCellData<>(Boolean.TRUE); } - return new CellData<>(Boolean.FALSE); + return new WriteCellData<>(Boolean.FALSE); } } diff --git a/src/main/java/com/alibaba/excel/converters/floatconverter/FloatNumberConverter.java b/src/main/java/com/alibaba/excel/converters/floatconverter/FloatNumberConverter.java index 1a401dff..478086e3 100644 --- a/src/main/java/com/alibaba/excel/converters/floatconverter/FloatNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/floatconverter/FloatNumberConverter.java @@ -1,12 +1,13 @@ package com.alibaba.excel.converters.floatconverter; import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.converters.WriteConverterContext; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; -import com.alibaba.excel.write.metadata.holder.WriteHolder; /** * Float and number converter @@ -26,14 +27,13 @@ public class FloatNumberConverter implements Converter { } @Override - public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Float convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getNumberValue().floatValue(); } @Override - public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty, - WriteHolder currentWriteHolder) { - return NumberUtils.formatToCellData(value, contentProperty, currentWriteHolder); + public WriteCellData convertToExcelData(WriteConverterContext context) { + return NumberUtils.formatToCellData(context.getValue(), context.getContentProperty()); } } diff --git a/src/main/java/com/alibaba/excel/converters/floatconverter/FloatStringConverter.java b/src/main/java/com/alibaba/excel/converters/floatconverter/FloatStringConverter.java index 29c819b1..bd5e9762 100644 --- a/src/main/java/com/alibaba/excel/converters/floatconverter/FloatStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/floatconverter/FloatStringConverter.java @@ -4,8 +4,9 @@ import java.text.ParseException; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; @@ -27,13 +28,13 @@ public class FloatStringConverter implements Converter { } @Override - public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Float convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { return NumberUtils.parseFloat(cellData.getStringValue(), contentProperty); } @Override - public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Float value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellDataString(value, contentProperty); } diff --git a/src/main/java/com/alibaba/excel/converters/inputstream/InputStreamImageConverter.java b/src/main/java/com/alibaba/excel/converters/inputstream/InputStreamImageConverter.java index 15043074..ff8492f0 100644 --- a/src/main/java/com/alibaba/excel/converters/inputstream/InputStreamImageConverter.java +++ b/src/main/java/com/alibaba/excel/converters/inputstream/InputStreamImageConverter.java @@ -2,15 +2,11 @@ package com.alibaba.excel.converters.inputstream; import java.io.IOException; import java.io.InputStream; -import java.lang.annotation.Annotation; -import com.alibaba.excel.annotation.write.style.ImagePosition; import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; -import com.alibaba.excel.util.FileUtils; import com.alibaba.excel.util.IoUtils; /** @@ -25,25 +21,9 @@ public class InputStreamImageConverter implements Converter { } @Override - public CellDataTypeEnum supportExcelTypeKey() { - return CellDataTypeEnum.IMAGE; - } - - @Override - public InputStream convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, - GlobalConfiguration globalConfiguration) { - throw new UnsupportedOperationException("Cannot convert images to input stream"); - } - - @Override - public CellData convertToExcelData(InputStream value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(InputStream value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws IOException { - ImagePosition imagePosition = contentProperty.getField().getAnnotation(ImagePosition.class); - if (imagePosition != null) { - return new CellData(IoUtils.toByteArray(value), imagePosition); - } else { - return new CellData(IoUtils.toByteArray(value)); - } + return new WriteCellData<>(IoUtils.toByteArray(value)); } } diff --git a/src/main/java/com/alibaba/excel/converters/integer/IntegerBooleanConverter.java b/src/main/java/com/alibaba/excel/converters/integer/IntegerBooleanConverter.java index 37b5d913..e3f13068 100644 --- a/src/main/java/com/alibaba/excel/converters/integer/IntegerBooleanConverter.java +++ b/src/main/java/com/alibaba/excel/converters/integer/IntegerBooleanConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.integer; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -26,7 +27,7 @@ public class IntegerBooleanConverter implements Converter { } @Override - public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; @@ -35,12 +36,12 @@ public class IntegerBooleanConverter implements Converter { } @Override - public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { - return new CellData<>(Boolean.TRUE); + return new WriteCellData<>(Boolean.TRUE); } - return new CellData<>(Boolean.FALSE); + return new WriteCellData<>(Boolean.FALSE); } } diff --git a/src/main/java/com/alibaba/excel/converters/integer/IntegerNumberConverter.java b/src/main/java/com/alibaba/excel/converters/integer/IntegerNumberConverter.java index 95a796b5..203aa1ac 100644 --- a/src/main/java/com/alibaba/excel/converters/integer/IntegerNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/integer/IntegerNumberConverter.java @@ -1,12 +1,13 @@ package com.alibaba.excel.converters.integer; import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.converters.WriteConverterContext; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; -import com.alibaba.excel.write.metadata.holder.WriteHolder; /** * Integer and number converter @@ -26,15 +27,14 @@ public class IntegerNumberConverter implements Converter { } @Override - public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getNumberValue().intValue(); } @Override - public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, - WriteHolder currentWriteHolder) { - return NumberUtils.formatToCellData(value, contentProperty, currentWriteHolder); + public WriteCellData convertToExcelData(WriteConverterContext context) { + return NumberUtils.formatToCellData(context.getValue(), context.getContentProperty()); } } diff --git a/src/main/java/com/alibaba/excel/converters/integer/IntegerStringConverter.java b/src/main/java/com/alibaba/excel/converters/integer/IntegerStringConverter.java index e6d91d34..62dce6e6 100644 --- a/src/main/java/com/alibaba/excel/converters/integer/IntegerStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/integer/IntegerStringConverter.java @@ -4,8 +4,9 @@ import java.text.ParseException; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; @@ -27,13 +28,13 @@ public class IntegerStringConverter implements Converter { } @Override - public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { return NumberUtils.parseInteger(cellData.getStringValue(), contentProperty); } @Override - public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellDataString(value, contentProperty); } diff --git a/src/main/java/com/alibaba/excel/converters/longconverter/LongBooleanConverter.java b/src/main/java/com/alibaba/excel/converters/longconverter/LongBooleanConverter.java index 298fed5e..d123ed66 100644 --- a/src/main/java/com/alibaba/excel/converters/longconverter/LongBooleanConverter.java +++ b/src/main/java/com/alibaba/excel/converters/longconverter/LongBooleanConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.longconverter; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -26,7 +27,7 @@ public class LongBooleanConverter implements Converter { } @Override - public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Long convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; @@ -35,12 +36,12 @@ public class LongBooleanConverter implements Converter { } @Override - public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Long value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { - return new CellData<>(Boolean.TRUE); + return new WriteCellData<>(Boolean.TRUE); } - return new CellData<>(Boolean.FALSE); + return new WriteCellData<>(Boolean.FALSE); } } diff --git a/src/main/java/com/alibaba/excel/converters/longconverter/LongNumberConverter.java b/src/main/java/com/alibaba/excel/converters/longconverter/LongNumberConverter.java index 7e4aa235..aee15b5b 100644 --- a/src/main/java/com/alibaba/excel/converters/longconverter/LongNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/longconverter/LongNumberConverter.java @@ -1,12 +1,13 @@ package com.alibaba.excel.converters.longconverter; import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.converters.WriteConverterContext; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; -import com.alibaba.excel.write.metadata.holder.WriteHolder; /** * Long and number converter @@ -26,15 +27,14 @@ public class LongNumberConverter implements Converter { } @Override - public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Long convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getNumberValue().longValue(); } @Override - public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty, - WriteHolder currentWriteHolder) { - return NumberUtils.formatToCellData(value, contentProperty, currentWriteHolder); + public WriteCellData convertToExcelData(WriteConverterContext context) { + return NumberUtils.formatToCellData(context.getValue(), context.getContentProperty()); } } diff --git a/src/main/java/com/alibaba/excel/converters/longconverter/LongStringConverter.java b/src/main/java/com/alibaba/excel/converters/longconverter/LongStringConverter.java index 873fb113..26ffcc81 100644 --- a/src/main/java/com/alibaba/excel/converters/longconverter/LongStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/longconverter/LongStringConverter.java @@ -4,8 +4,9 @@ import java.text.ParseException; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; @@ -27,13 +28,13 @@ public class LongStringConverter implements Converter { } @Override - public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Long convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { return NumberUtils.parseLong(cellData.getStringValue(), contentProperty); } @Override - public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Long value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellDataString(value, contentProperty); } diff --git a/src/main/java/com/alibaba/excel/converters/shortconverter/ShortBooleanConverter.java b/src/main/java/com/alibaba/excel/converters/shortconverter/ShortBooleanConverter.java index eb39b7de..1f0517ee 100644 --- a/src/main/java/com/alibaba/excel/converters/shortconverter/ShortBooleanConverter.java +++ b/src/main/java/com/alibaba/excel/converters/shortconverter/ShortBooleanConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.shortconverter; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -26,7 +27,7 @@ public class ShortBooleanConverter implements Converter { } @Override - public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Short convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; @@ -35,12 +36,12 @@ public class ShortBooleanConverter implements Converter { } @Override - public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Short value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { - return new CellData<>(Boolean.TRUE); + return new WriteCellData<>(Boolean.TRUE); } - return new CellData<>(Boolean.FALSE); + return new WriteCellData<>(Boolean.FALSE); } } diff --git a/src/main/java/com/alibaba/excel/converters/shortconverter/ShortNumberConverter.java b/src/main/java/com/alibaba/excel/converters/shortconverter/ShortNumberConverter.java index eedfca4f..d0568606 100644 --- a/src/main/java/com/alibaba/excel/converters/shortconverter/ShortNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/shortconverter/ShortNumberConverter.java @@ -1,14 +1,13 @@ package com.alibaba.excel.converters.shortconverter; -import java.math.BigDecimal; - import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.converters.WriteConverterContext; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; -import com.alibaba.excel.write.metadata.holder.WriteHolder; /** * Short and number converter @@ -28,14 +27,13 @@ public class ShortNumberConverter implements Converter { } @Override - public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public Short convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getNumberValue().shortValue(); } @Override - public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty, - WriteHolder currentWriteHolder) { - return NumberUtils.formatToCellData(value, contentProperty, currentWriteHolder); + public WriteCellData convertToExcelData(WriteConverterContext context) { + return NumberUtils.formatToCellData(context.getValue(), context.getContentProperty()); } } diff --git a/src/main/java/com/alibaba/excel/converters/shortconverter/ShortStringConverter.java b/src/main/java/com/alibaba/excel/converters/shortconverter/ShortStringConverter.java index 85c56067..497fdee9 100644 --- a/src/main/java/com/alibaba/excel/converters/shortconverter/ShortStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/shortconverter/ShortStringConverter.java @@ -4,8 +4,9 @@ import java.text.ParseException; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; @@ -27,13 +28,13 @@ public class ShortStringConverter implements Converter { } @Override - public Short convertToJavaData(CellDatacellData, ExcelContentProperty contentProperty, + public Short convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { return NumberUtils.parseShort(cellData.getStringValue(), contentProperty); } @Override - public CellDataconvertToExcelData(Short value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(Short value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellDataString(value, contentProperty); } diff --git a/src/main/java/com/alibaba/excel/converters/string/StringBooleanConverter.java b/src/main/java/com/alibaba/excel/converters/string/StringBooleanConverter.java index f2aafb4d..704a18b4 100644 --- a/src/main/java/com/alibaba/excel/converters/string/StringBooleanConverter.java +++ b/src/main/java/com/alibaba/excel/converters/string/StringBooleanConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.string; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -24,15 +25,15 @@ public class StringBooleanConverter implements Converter { } @Override - public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public String convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getBooleanValue().toString(); } @Override - public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - return new CellData<>(Boolean.valueOf(value)); + return new WriteCellData<>(Boolean.valueOf(value)); } } diff --git a/src/main/java/com/alibaba/excel/converters/string/StringErrorConverter.java b/src/main/java/com/alibaba/excel/converters/string/StringErrorConverter.java index f0a71a46..1456d80f 100644 --- a/src/main/java/com/alibaba/excel/converters/string/StringErrorConverter.java +++ b/src/main/java/com/alibaba/excel/converters/string/StringErrorConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.string; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -23,15 +24,15 @@ public class StringErrorConverter implements Converter { } @Override - public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public String convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getStringValue(); } @Override - public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - return new CellData<>(CellDataTypeEnum.ERROR, value); + return new WriteCellData<>(CellDataTypeEnum.ERROR, value); } } diff --git a/src/main/java/com/alibaba/excel/converters/string/StringImageConverter.java b/src/main/java/com/alibaba/excel/converters/string/StringImageConverter.java index 940d0065..fb262e19 100644 --- a/src/main/java/com/alibaba/excel/converters/string/StringImageConverter.java +++ b/src/main/java/com/alibaba/excel/converters/string/StringImageConverter.java @@ -2,16 +2,12 @@ package com.alibaba.excel.converters.string; import java.io.File; import java.io.IOException; -import java.lang.annotation.Annotation; -import com.alibaba.excel.annotation.write.style.ImagePosition; import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.FileUtils; -import com.alibaba.excel.util.IoUtils; /** * String and image converter @@ -25,25 +21,9 @@ public class StringImageConverter implements Converter { } @Override - public CellDataTypeEnum supportExcelTypeKey() { - return CellDataTypeEnum.IMAGE; - } - - @Override - public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, - GlobalConfiguration globalConfiguration) { - throw new UnsupportedOperationException("Cannot convert images to string"); - } - - @Override - public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws IOException { - ImagePosition imagePosition = contentProperty.getField().getAnnotation(ImagePosition.class); - if (imagePosition != null) { - return new CellData(FileUtils.readFileToByteArray(new File(value)), imagePosition); - } else { - return new CellData(FileUtils.readFileToByteArray(new File(value))); - } + return new WriteCellData<>(FileUtils.readFileToByteArray(new File(value))); } } diff --git a/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java b/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java index e9b6fef6..4c3bbc59 100644 --- a/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java +++ b/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java @@ -2,18 +2,19 @@ package com.alibaba.excel.converters.string; import java.math.BigDecimal; -import org.apache.poi.ss.usermodel.DateUtil; - import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.NumberDataFormatterUtils; import com.alibaba.excel.util.NumberUtils; import com.alibaba.excel.util.StringUtils; +import org.apache.poi.ss.usermodel.DateUtil; + /** * String and number converter * @@ -32,7 +33,7 @@ public class StringNumberConverter implements Converter { } @Override - public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public String convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { // If there are "DateTimeFormat", read as date if (contentProperty != null && contentProperty.getDateTimeFormatProperty() != null) { @@ -46,17 +47,20 @@ public class StringNumberConverter implements Converter { return NumberUtils.format(cellData.getNumberValue(), contentProperty); } // Excel defines formatting - if (cellData.getDataFormat() != null && !StringUtils.isEmpty(cellData.getDataFormatString())) { - return NumberDataFormatterUtils.format(cellData.getNumberValue().doubleValue(), cellData.getDataFormat(), - cellData.getDataFormatString(), globalConfiguration); + boolean hasDataFormatData = cellData.getDataFormatData() != null + && cellData.getDataFormatData().getIndex() != null && !StringUtils.isEmpty( + cellData.getDataFormatData().getFormat()); + if (hasDataFormatData) { + return NumberDataFormatterUtils.format(cellData.getNumberValue().doubleValue(), + cellData.getDataFormatData().getIndex(), cellData.getDataFormatData().getFormat(), globalConfiguration); } // Default conversion number return NumberUtils.format(cellData.getNumberValue(), contentProperty); } @Override - public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - return new CellData<>(new BigDecimal(value)); + return new WriteCellData<>(new BigDecimal(value)); } } diff --git a/src/main/java/com/alibaba/excel/converters/string/StringStringConverter.java b/src/main/java/com/alibaba/excel/converters/string/StringStringConverter.java index 3b1ce3df..5edc6b16 100644 --- a/src/main/java/com/alibaba/excel/converters/string/StringStringConverter.java +++ b/src/main/java/com/alibaba/excel/converters/string/StringStringConverter.java @@ -2,8 +2,9 @@ package com.alibaba.excel.converters.string; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; /** @@ -23,15 +24,15 @@ public class StringStringConverter implements Converter { } @Override - public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + public String convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getStringValue(); } @Override - public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - return new CellData<>(value); + return new WriteCellData<>(value); } } diff --git a/src/main/java/com/alibaba/excel/converters/url/UrlImageConverter.java b/src/main/java/com/alibaba/excel/converters/url/UrlImageConverter.java index a9e60df9..2aea00bf 100644 --- a/src/main/java/com/alibaba/excel/converters/url/UrlImageConverter.java +++ b/src/main/java/com/alibaba/excel/converters/url/UrlImageConverter.java @@ -5,17 +5,16 @@ import java.io.InputStream; import java.net.URL; import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.IoUtils; /** * Url and image converter * - * @since 2.1.1 * @author Jiaju Zhuang + * @since 2.1.1 */ public class UrlImageConverter implements Converter { @Override @@ -24,24 +23,13 @@ public class UrlImageConverter implements Converter { } @Override - public CellDataTypeEnum supportExcelTypeKey() { - return CellDataTypeEnum.IMAGE; - } - - @Override - public URL convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, - GlobalConfiguration globalConfiguration) { - throw new UnsupportedOperationException("Cannot convert images to url."); - } - - @Override - public CellData convertToExcelData(URL value, ExcelContentProperty contentProperty, + public WriteCellData convertToExcelData(URL value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws IOException { InputStream inputStream = null; try { inputStream = value.openStream(); byte[] bytes = IoUtils.toByteArray(inputStream); - return new CellData<>(bytes); + return new WriteCellData<>(bytes); } finally { if (inputStream != null) { inputStream.close(); diff --git a/src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java b/src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java index a7a667f0..12f53d05 100644 --- a/src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java +++ b/src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java @@ -37,11 +37,7 @@ public enum CellDataTypeEnum { */ ERROR, /** - * image. Support only when writing. - */ - IMAGE, - /** - * date.Support only when writing. + * date. Support only when writing. */ DATE, /** diff --git a/src/main/java/com/alibaba/excel/event/AbstractIgnoreExceptionReadListener.java b/src/main/java/com/alibaba/excel/event/AbstractIgnoreExceptionReadListener.java index 1e93397e..365336b7 100644 --- a/src/main/java/com/alibaba/excel/event/AbstractIgnoreExceptionReadListener.java +++ b/src/main/java/com/alibaba/excel/event/AbstractIgnoreExceptionReadListener.java @@ -8,7 +8,9 @@ import com.alibaba.excel.read.listener.ReadListener; * Receives the return of each piece of data parsed * * @author jipengfei + * @deprecated Use directly {@link ReadListener} */ +@Deprecated public abstract class AbstractIgnoreExceptionReadListener implements ReadListener { /** @@ -24,10 +26,8 @@ public abstract class AbstractIgnoreExceptionReadListener implements ReadList /** * The current method is called when extra information is returned * - * @param extra - * extra information - * @param context - * analysis context + * @param extra extra information + * @param context analysis context */ @Override public void extra(CellExtra extra, AnalysisContext context) {} diff --git a/src/main/java/com/alibaba/excel/event/AnalysisEventListener.java b/src/main/java/com/alibaba/excel/event/AnalysisEventListener.java index a0cd5078..bc94d75e 100644 --- a/src/main/java/com/alibaba/excel/event/AnalysisEventListener.java +++ b/src/main/java/com/alibaba/excel/event/AnalysisEventListener.java @@ -3,8 +3,8 @@ package com.alibaba.excel.event; import java.util.Map; import com.alibaba.excel.context.AnalysisContext; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.CellExtra; +import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.read.listener.ReadListener; import com.alibaba.excel.util.ConverterUtils; @@ -16,7 +16,7 @@ import com.alibaba.excel.util.ConverterUtils; public abstract class AnalysisEventListener implements ReadListener { @Override - public void invokeHead(Map> headMap, AnalysisContext context) { + public void invokeHead(Map> headMap, AnalysisContext context) { invokeHeadMap(ConverterUtils.convertToStringMap(headMap, context), context); } diff --git a/src/main/java/com/alibaba/excel/event/WriteHandler.java b/src/main/java/com/alibaba/excel/event/WriteHandler.java deleted file mode 100644 index 8c981ffc..00000000 --- a/src/main/java/com/alibaba/excel/event/WriteHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.alibaba.excel.event; - -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; - -/** - * - * @author jipengfei - * @deprecated please use {@link com.alibaba.excel.write.handler.WriteHandler} - */ -@Deprecated -public interface WriteHandler { - - /** - * Custom operation after creating each sheet - * - * @param sheetNo - * @param sheet - */ - void sheet(int sheetNo, Sheet sheet); - - /** - * Custom operation after creating each row - * - * @param rowNum - * @param row - */ - void row(int rowNum, Row row); - - /** - * Custom operation after creating each cell - * - * @param cellNum - * @param cell - */ - void cell(int cellNum, Cell cell); -} diff --git a/src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java b/src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java index 3cd9077b..1cb9c934 100644 --- a/src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java +++ b/src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java @@ -1,12 +1,10 @@ package com.alibaba.excel.exception; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.write.builder.ExcelWriterBuilder; import lombok.Data; -import lombok.Getter; -import lombok.Setter; /** * Data convert exception diff --git a/src/main/java/com/alibaba/excel/metadata/BaseRowModel.java b/src/main/java/com/alibaba/excel/metadata/BaseRowModel.java deleted file mode 100644 index 7df131e4..00000000 --- a/src/main/java/com/alibaba/excel/metadata/BaseRowModel.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.alibaba.excel.metadata; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.poi.ss.usermodel.CellStyle; - -import com.alibaba.excel.annotation.ExcelIgnore; - -/** - * Excel基础模型 - * - * @author jipengfei - * @deprecated Now you don't need to extend any classes - */ -@Deprecated -public class BaseRowModel { - - /** - * 每列样式 - */ - @ExcelIgnore - private Map cellStyleMap = new HashMap(); - - public void addStyle(Integer row, CellStyle cellStyle) { - cellStyleMap.put(row, cellStyle); - } - - public CellStyle getStyle(Integer row) { - return cellStyleMap.get(row); - } - - public Map getCellStyleMap() { - return cellStyleMap; - } - - public void setCellStyleMap(Map cellStyleMap) { - this.cellStyleMap = cellStyleMap; - } -} diff --git a/src/main/java/com/alibaba/excel/metadata/BasicParameter.java b/src/main/java/com/alibaba/excel/metadata/BasicParameter.java index 5baf5cf5..f574f10e 100644 --- a/src/main/java/com/alibaba/excel/metadata/BasicParameter.java +++ b/src/main/java/com/alibaba/excel/metadata/BasicParameter.java @@ -5,11 +5,14 @@ import java.util.Locale; import com.alibaba.excel.converters.Converter; +import lombok.Data; + /** * Basic parameter * * @author Jiaju Zhuang **/ +@Data public class BasicParameter { /** * You can only choose one of the {@link BasicParameter#head} and {@link BasicParameter#clazz} @@ -18,11 +21,11 @@ public class BasicParameter { /** * You can only choose one of the {@link BasicParameter#head} and {@link BasicParameter#clazz} */ - private Class clazz; + private Class clazz; /** * Custom type conversions override the default */ - private List customConverterList; + private List> customConverterList; /** * Automatic trim includes sheet name and content */ @@ -47,60 +50,4 @@ public class BasicParameter { * default is false */ private Boolean useScientificFormat; - - public List> getHead() { - return head; - } - - public void setHead(List> head) { - this.head = head; - } - - public Class getClazz() { - return clazz; - } - - public void setClazz(Class clazz) { - this.clazz = clazz; - } - - public List getCustomConverterList() { - return customConverterList; - } - - public void setCustomConverterList(List customConverterList) { - this.customConverterList = customConverterList; - } - - public Boolean getAutoTrim() { - return autoTrim; - } - - public void setAutoTrim(Boolean autoTrim) { - this.autoTrim = autoTrim; - } - - public Boolean getUse1904windowing() { - return use1904windowing; - } - - public void setUse1904windowing(Boolean use1904windowing) { - this.use1904windowing = use1904windowing; - } - - public Locale getLocale() { - return locale; - } - - public void setLocale(Locale locale) { - this.locale = locale; - } - - public Boolean getUseScientificFormat() { - return useScientificFormat; - } - - public void setUseScientificFormat(Boolean useScientificFormat) { - this.useScientificFormat = useScientificFormat; - } } diff --git a/src/main/java/com/alibaba/excel/metadata/CellData.java b/src/main/java/com/alibaba/excel/metadata/CellData.java deleted file mode 100644 index 604df146..00000000 --- a/src/main/java/com/alibaba/excel/metadata/CellData.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.alibaba.excel.metadata; - -import java.math.BigDecimal; -import java.util.Date; - -import com.alibaba.excel.annotation.write.style.ImagePosition; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.property.ImagePositionProperty; -import com.alibaba.excel.util.StringUtils; -import com.alibaba.excel.write.metadata.style.WriteCellStyle; - -import lombok.Data; -import org.apache.poi.ss.usermodel.Comment; -import org.apache.poi.ss.usermodel.Hyperlink; -import org.apache.poi.ss.usermodel.RichTextString; - -/** - * Excel internal cell data. - * - *

- * - * @author Jiaju Zhuang - */ -@Data -public class CellData extends AbstractCell { - private CellDataTypeEnum type; - /** - * {@link CellDataTypeEnum#NUMBER} - */ - private BigDecimal numberValue; - /** - * {@link CellDataTypeEnum#STRING} and{@link CellDataTypeEnum#ERROR} - */ - private String stringValue; - /** - * {@link CellDataTypeEnum#BOOLEAN} - */ - private Boolean booleanValue; - - /** - * The resulting converted data. - */ - private T data; - - /** - * formula - */ - private FormulaData formulaData; - /** - * data format - */ - private DataFormat dataFormat; - - public CellData() {} - - public CellData(T data) { - this.data = data; - } - - public CellData(String stringValue) { - this(CellDataTypeEnum.STRING, stringValue); - } - - public CellData(CellDataTypeEnum type, String stringValue) { - if (type != CellDataTypeEnum.STRING && type != CellDataTypeEnum.ERROR) { - throw new IllegalArgumentException("Only support CellDataTypeEnum.STRING and CellDataTypeEnum.ERROR"); - } - if (stringValue == null) { - throw new IllegalArgumentException("StringValue can not be null"); - } - this.type = type; - this.stringValue = stringValue; - } - - public CellData(BigDecimal numberValue) { - if (numberValue == null) { - throw new IllegalArgumentException("DoubleValue can not be null"); - } - this.type = CellDataTypeEnum.NUMBER; - this.numberValue = numberValue; - } - - public CellData(byte[] imageValue) { - if (imageValue == null) { - throw new IllegalArgumentException("ImageValue can not be null"); - } - this.type = CellDataTypeEnum.IMAGE; - this.imageValue = imageValue; - } - - public CellData(byte[] imageValue, ImagePosition imagePosition) { - if (imageValue == null) { - throw new IllegalArgumentException("ImageValue can not be null"); - } - if (imagePosition == null) { - throw new IllegalArgumentException("ImagePosition can not be null"); - } - this.type = CellDataTypeEnum.IMAGE; - this.imageValue = imageValue; - this.imagePositionProperty = ImagePositionProperty.build(imagePosition); - this.useImagePositionProperty = true; - this.formula = Boolean.FALSE; - } - - public CellData(Boolean booleanValue) { - if (booleanValue == null) { - throw new IllegalArgumentException("BooleanValue can not be null"); - } - this.type = CellDataTypeEnum.BOOLEAN; - this.booleanValue = booleanValue; - } - - public CellData(Date dateValue) { - if (dateValue == null) { - throw new IllegalArgumentException("DateValue can not be null"); - } - this.type = CellDataTypeEnum.DATE; - this.dateValue = dateValue; - this.formula = Boolean.FALSE; - } - - public CellData(CellDataTypeEnum type) { - if (type == null) { - throw new IllegalArgumentException("Type can not be null"); - } - this.type = type; - } - - /** - * Ensure that the object does not appear null - */ - public void checkEmpty() { - if (type == null) { - type = CellDataTypeEnum.EMPTY; - } - switch (type) { - case STRING: - case ERROR: - if (StringUtils.isEmpty(stringValue)) { - type = CellDataTypeEnum.EMPTY; - } - return; - case NUMBER: - if (numberValue == null) { - type = CellDataTypeEnum.EMPTY; - } - return; - case BOOLEAN: - if (booleanValue == null) { - type = CellDataTypeEnum.EMPTY; - } - return; - default: - } - } - - public static CellData newEmptyInstance() { - return newEmptyInstance(null, null); - } - - public static CellData newEmptyInstance(Integer rowIndex, Integer columnIndex) { - CellData cellData = new CellData<>(CellDataTypeEnum.EMPTY); - cellData.setRowIndex(rowIndex); - cellData.setColumnIndex(columnIndex); - return cellData; - } - - public static CellData newInstance(Boolean booleanValue) { - return newInstance(booleanValue, null, null); - } - - public static CellData newInstance(Boolean booleanValue, Integer rowIndex, Integer columnIndex) { - CellData cellData = new CellData<>(booleanValue); - cellData.setRowIndex(rowIndex); - cellData.setColumnIndex(columnIndex); - return cellData; - } - - public static CellData newInstance(String stringValue, Integer rowIndex, Integer columnIndex) { - CellData cellData = new CellData<>(stringValue); - cellData.setRowIndex(rowIndex); - cellData.setColumnIndex(columnIndex); - return cellData; - } - - public static CellData newInstance(BigDecimal numberValue, Integer rowIndex, Integer columnIndex) { - CellData cellData = new CellData<>(numberValue); - cellData.setRowIndex(rowIndex); - cellData.setColumnIndex(columnIndex); - return cellData; - } - -} diff --git a/src/main/java/com/alibaba/excel/metadata/HyperlinkData.java b/src/main/java/com/alibaba/excel/metadata/HyperlinkData.java deleted file mode 100644 index f3453c64..00000000 --- a/src/main/java/com/alibaba/excel/metadata/HyperlinkData.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.alibaba.excel.metadata; - -/** - * TODO - * - * @author Jiaju Zhuang - */ -public class HyperlinkData { - -} diff --git a/src/main/java/com/alibaba/excel/metadata/ReadCellData.java b/src/main/java/com/alibaba/excel/metadata/ReadCellData.java deleted file mode 100644 index cf9ad233..00000000 --- a/src/main/java/com/alibaba/excel/metadata/ReadCellData.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.alibaba.excel.metadata; - -import lombok.Data; - -/** - * TODO - * - * @author Jiaju Zhuang - */ -@Data -public class ReadCellData extends CellData{ - -} diff --git a/src/main/java/com/alibaba/excel/metadata/Sheet.java b/src/main/java/com/alibaba/excel/metadata/Sheet.java deleted file mode 100644 index 38bd30af..00000000 --- a/src/main/java/com/alibaba/excel/metadata/Sheet.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.alibaba.excel.metadata; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * - * @author jipengfei - * @deprecated pleas use {@link com.alibaba.excel.write.metadata.WriteSheet} or - * {@link com.alibaba.excel.read.metadata.ReadSheet} - */ -@Deprecated -public class Sheet { - - /** - */ - private int headLineMun; - - /** - * Starting from 1 - */ - private int sheetNo; - - /** - */ - private String sheetName; - - /** - */ - private Class clazz; - - /** - */ - private List> head; - - /** - * - */ - private TableStyle tableStyle; - - /** - * column with - */ - private Map columnWidthMap = new HashMap(); - - /** - * - */ - private Boolean autoWidth = Boolean.FALSE; - - /** - * - */ - private int startRow = 0; - - public Sheet(int sheetNo) { - this.sheetNo = sheetNo; - } - - public Sheet(int sheetNo, int headLineMun) { - this.sheetNo = sheetNo; - this.headLineMun = headLineMun; - } - - public Sheet(int sheetNo, int headLineMun, Class clazz) { - this.sheetNo = sheetNo; - this.headLineMun = headLineMun; - this.clazz = clazz; - } - - public Sheet(int sheetNo, int headLineMun, Class clazz, String sheetName, - List> head) { - this.sheetNo = sheetNo; - this.clazz = clazz; - this.headLineMun = headLineMun; - this.sheetName = sheetName; - this.head = head; - } - - public List> getHead() { - return head; - } - - public void setHead(List> head) { - this.head = head; - } - - public Class getClazz() { - return clazz; - } - - public void setClazz(Class clazz) { - this.clazz = clazz; - if (headLineMun == 0) { - this.headLineMun = 1; - } - } - - public int getHeadLineMun() { - return headLineMun; - } - - public void setHeadLineMun(int headLineMun) { - this.headLineMun = headLineMun; - } - - public int getSheetNo() { - return sheetNo; - } - - public void setSheetNo(int sheetNo) { - this.sheetNo = sheetNo; - } - - public String getSheetName() { - return sheetName; - } - - public void setSheetName(String sheetName) { - this.sheetName = sheetName; - } - - public TableStyle getTableStyle() { - return tableStyle; - } - - public void setTableStyle(TableStyle tableStyle) { - this.tableStyle = tableStyle; - } - - public Map getColumnWidthMap() { - return columnWidthMap; - } - - public void setColumnWidthMap(Map columnWidthMap) { - this.columnWidthMap = columnWidthMap; - } - - @Override - public String toString() { - return "Sheet{" + "headLineMun=" + headLineMun + ", sheetNo=" + sheetNo + ", sheetName='" + sheetName + '\'' - + ", clazz=" + clazz + ", head=" + head + ", tableStyle=" + tableStyle + ", columnWidthMap=" - + columnWidthMap + '}'; - } - - public Boolean getAutoWidth() { - return autoWidth; - } - - public void setAutoWidth(Boolean autoWidth) { - this.autoWidth = autoWidth; - } - - public int getStartRow() { - return startRow; - } - - public void setStartRow(int startRow) { - this.startRow = startRow; - } -} diff --git a/src/main/java/com/alibaba/excel/metadata/Table.java b/src/main/java/com/alibaba/excel/metadata/Table.java deleted file mode 100644 index d4c63aba..00000000 --- a/src/main/java/com/alibaba/excel/metadata/Table.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.alibaba.excel.metadata; - -import java.util.List; - -/** - * @author jipengfei - * @deprecated please use {@link com.alibaba.excel.write.metadata.WriteTable} - */ -@Deprecated -public class Table { - /** - */ - private Class clazz; - - /** - */ - private List> head; - - /** - */ - private int tableNo; - - /** - */ - private TableStyle tableStyle; - - public Table(Integer tableNo) { - this.tableNo = tableNo; - } - - public TableStyle getTableStyle() { - return tableStyle; - } - - public void setTableStyle(TableStyle tableStyle) { - this.tableStyle = tableStyle; - } - - public Class getClazz() { - return clazz; - } - - public void setClazz(Class clazz) { - this.clazz = clazz; - } - - public List> getHead() { - return head; - } - - public void setHead(List> head) { - this.head = head; - } - - public int getTableNo() { - return tableNo; - } - - public void setTableNo(int tableNo) { - this.tableNo = tableNo; - } -} diff --git a/src/main/java/com/alibaba/excel/metadata/TableStyle.java b/src/main/java/com/alibaba/excel/metadata/TableStyle.java deleted file mode 100644 index fa8905c5..00000000 --- a/src/main/java/com/alibaba/excel/metadata/TableStyle.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.alibaba.excel.metadata; - -import org.apache.poi.ss.usermodel.IndexedColors; - -import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; - -/** - * @author jipengfei - * @deprecated please use {@link HorizontalCellStyleStrategy} - */ -@Deprecated -public class TableStyle { - - /** - * 表头背景颜色 - */ - private IndexedColors tableHeadBackGroundColor; - - /** - * 表头字体样式 - */ - private Font tableHeadFont; - - /** - * 表格内容字体样式 - */ - private Font tableContentFont; - - /** - * 表格内容背景颜色 - */ - private IndexedColors tableContentBackGroundColor; - - public IndexedColors getTableHeadBackGroundColor() { - return tableHeadBackGroundColor; - } - - public void setTableHeadBackGroundColor(IndexedColors tableHeadBackGroundColor) { - this.tableHeadBackGroundColor = tableHeadBackGroundColor; - } - - public Font getTableHeadFont() { - return tableHeadFont; - } - - public void setTableHeadFont(Font tableHeadFont) { - this.tableHeadFont = tableHeadFont; - } - - public Font getTableContentFont() { - return tableContentFont; - } - - public void setTableContentFont(Font tableContentFont) { - this.tableContentFont = tableContentFont; - } - - public IndexedColors getTableContentBackGroundColor() { - return tableContentBackGroundColor; - } - - public void setTableContentBackGroundColor(IndexedColors tableContentBackGroundColor) { - this.tableContentBackGroundColor = tableContentBackGroundColor; - } -} diff --git a/src/main/java/com/alibaba/excel/metadata/WriteCellData.java b/src/main/java/com/alibaba/excel/metadata/WriteCellData.java deleted file mode 100644 index 901aa916..00000000 --- a/src/main/java/com/alibaba/excel/metadata/WriteCellData.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.alibaba.excel.metadata; - -import java.util.Date; - -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.write.metadata.style.WriteCellStyle; - -import lombok.Data; - -/** - * TODO - * - * @author Jiaju Zhuang - */ -@Data -public class WriteCellData extends CellData { - /** - * Support only when writing.{@link CellDataTypeEnum#DATE} - */ - private Date dateValue; - /** - * {@link CellDataTypeEnum#IMAGE} - */ - private ImageData imageDataValue; - /** - * rich text.{@link CellDataTypeEnum#RICH_TEXT_STRING} - */ - private RichTextStringData richTextStringDataValue; - - /** - * comment - */ - private CommentData commentData; - /** - * hyper link - */ - private HyperlinkData hyperlinkData; - /** - * sytle - */ - private WriteCellStyle writeCellStyle; -} diff --git a/src/main/java/com/alibaba/excel/metadata/data/CellData.java b/src/main/java/com/alibaba/excel/metadata/data/CellData.java new file mode 100644 index 00000000..ed6085f9 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/data/CellData.java @@ -0,0 +1,76 @@ +package com.alibaba.excel.metadata.data; + +import java.math.BigDecimal; + +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.AbstractCell; +import com.alibaba.excel.util.StringUtils; + +import lombok.Data; + +/** + * Excel internal cell data. + * + *

+ * + * @author Jiaju Zhuang + */ +@Data +public class CellData extends AbstractCell { + /** + * cell type + */ + private CellDataTypeEnum type; + /** + * {@link CellDataTypeEnum#NUMBER} + */ + private BigDecimal numberValue; + /** + * {@link CellDataTypeEnum#STRING} and{@link CellDataTypeEnum#ERROR} + */ + private String stringValue; + /** + * {@link CellDataTypeEnum#BOOLEAN} + */ + private Boolean booleanValue; + + /** + * The resulting converted data. + */ + private T data; + + /** + * formula + */ + private FormulaData formulaData; + + /** + * Ensure that the object does not appear null + */ + public void checkEmpty() { + if (type == null) { + type = CellDataTypeEnum.EMPTY; + } + switch (type) { + case STRING: + case ERROR: + if (StringUtils.isEmpty(stringValue)) { + type = CellDataTypeEnum.EMPTY; + } + return; + case NUMBER: + if (numberValue == null) { + type = CellDataTypeEnum.EMPTY; + } + return; + case BOOLEAN: + if (booleanValue == null) { + type = CellDataTypeEnum.EMPTY; + } + return; + default: + } + } + + +} diff --git a/src/main/java/com/alibaba/excel/metadata/ClientAnchorData.java b/src/main/java/com/alibaba/excel/metadata/data/ClientAnchorData.java similarity index 84% rename from src/main/java/com/alibaba/excel/metadata/ClientAnchorData.java rename to src/main/java/com/alibaba/excel/metadata/data/ClientAnchorData.java index cf215e6f..b240eb97 100644 --- a/src/main/java/com/alibaba/excel/metadata/ClientAnchorData.java +++ b/src/main/java/com/alibaba/excel/metadata/data/ClientAnchorData.java @@ -1,4 +1,4 @@ -package com.alibaba.excel.metadata; +package com.alibaba.excel.metadata.data; import lombok.Data; import org.apache.poi.ss.usermodel.ClientAnchor; @@ -21,47 +21,27 @@ import org.apache.poi.util.Internal; * @author Jiaju Zhuang */ @Data -public class ClientAnchorData { - - /** - * The x coordinate within the first cell. - */ - private int dx1; - - /** - * The y coordinate within the first cell. - */ - private int dy1; - - /** - * The x coordinate within the second cell. - */ - private int dx2; - +public class ClientAnchorData extends CoordinateData { /** - * The y coordinate within the second cell + * top */ - private int dy2; + private Integer top; /** - * 0-based column of the first cell. + * right */ - private short col1; + private Integer right; /** - * 0-based row of the first cell. + * bottom */ - private int row1; + private Integer bottom; /** - * 0-based column of the second cell. + * left */ - private short col2; + private Integer left; - /** - * 0-based row of the second cell. - */ - private int row2; /** * anchor type */ diff --git a/src/main/java/com/alibaba/excel/metadata/CommentData.java b/src/main/java/com/alibaba/excel/metadata/data/CommentData.java similarity index 88% rename from src/main/java/com/alibaba/excel/metadata/CommentData.java rename to src/main/java/com/alibaba/excel/metadata/data/CommentData.java index 94c1b675..6f86a3e3 100644 --- a/src/main/java/com/alibaba/excel/metadata/CommentData.java +++ b/src/main/java/com/alibaba/excel/metadata/data/CommentData.java @@ -1,9 +1,9 @@ -package com.alibaba.excel.metadata; +package com.alibaba.excel.metadata.data; import lombok.Data; /** - * TODO + * comment * * @author Jiaju Zhuang */ diff --git a/src/main/java/com/alibaba/excel/metadata/data/CoordinateData.java b/src/main/java/com/alibaba/excel/metadata/data/CoordinateData.java new file mode 100644 index 00000000..c9b73ffb --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/data/CoordinateData.java @@ -0,0 +1,28 @@ +package com.alibaba.excel.metadata.data; + +import lombok.Data; + +/** + * coordinate. + * + * @author Jiaju Zhuang + */ +@Data +public class CoordinateData { + /** + * first row index + */ + private Integer firstRowIndex; + /** + * first column index + */ + private Integer firstColumnIndex; + /** + * last row index + */ + private Integer lastRowIndex; + /** + * last column index + */ + private Integer lastColumnIndex; +} diff --git a/src/main/java/com/alibaba/excel/metadata/DataFormat.java b/src/main/java/com/alibaba/excel/metadata/data/DataFormatData.java similarity index 72% rename from src/main/java/com/alibaba/excel/metadata/DataFormat.java rename to src/main/java/com/alibaba/excel/metadata/data/DataFormatData.java index fdaa5236..3ac70781 100644 --- a/src/main/java/com/alibaba/excel/metadata/DataFormat.java +++ b/src/main/java/com/alibaba/excel/metadata/data/DataFormatData.java @@ -1,4 +1,4 @@ -package com.alibaba.excel.metadata; +package com.alibaba.excel.metadata.data; import lombok.Data; @@ -8,11 +8,12 @@ import lombok.Data; * @author Jiaju Zhuang */ @Data -public class DataFormat { +public class DataFormatData { /** * index */ private Short index; + /** * format */ diff --git a/src/main/java/com/alibaba/excel/metadata/FormulaData.java b/src/main/java/com/alibaba/excel/metadata/data/FormulaData.java similarity index 80% rename from src/main/java/com/alibaba/excel/metadata/FormulaData.java rename to src/main/java/com/alibaba/excel/metadata/data/FormulaData.java index 8f3c4f15..cdf91055 100644 --- a/src/main/java/com/alibaba/excel/metadata/FormulaData.java +++ b/src/main/java/com/alibaba/excel/metadata/data/FormulaData.java @@ -1,4 +1,4 @@ -package com.alibaba.excel.metadata; +package com.alibaba.excel.metadata.data; import lombok.Data; diff --git a/src/main/java/com/alibaba/excel/metadata/data/HyperlinkData.java b/src/main/java/com/alibaba/excel/metadata/data/HyperlinkData.java new file mode 100644 index 00000000..c38d7dd6 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/data/HyperlinkData.java @@ -0,0 +1,53 @@ +package com.alibaba.excel.metadata.data; + +import lombok.Data; + +/** + * hyperlink + * + * @author Jiaju Zhuang + */ +@Data +public class HyperlinkData extends CoordinateData { + /** + * Depending on the hyperlink type it can be URL, e-mail, path to a file, etc + */ + private String address; + /** + * hyperlink type + */ + private HyperlinkType hyperlinkType; + + public enum HyperlinkType { + /** + * Not a hyperlink + */ + NONE(-1), + + /** + * Link to an existing file or web page + */ + URL(1), + + /** + * Link to a place in this document + */ + DOCUMENT(2), + + /** + * Link to an E-mail address + */ + EMAIL(3), + + /** + * Link to a file + */ + FILE(4); + + public final int value; + + HyperlinkType(int value) { + this.value = value; + } + } +} diff --git a/src/main/java/com/alibaba/excel/metadata/ImageData.java b/src/main/java/com/alibaba/excel/metadata/data/ImageData.java similarity index 95% rename from src/main/java/com/alibaba/excel/metadata/ImageData.java rename to src/main/java/com/alibaba/excel/metadata/data/ImageData.java index e1bb30fa..48276db3 100644 --- a/src/main/java/com/alibaba/excel/metadata/ImageData.java +++ b/src/main/java/com/alibaba/excel/metadata/data/ImageData.java @@ -1,4 +1,4 @@ -package com.alibaba.excel.metadata; +package com.alibaba.excel.metadata.data; import lombok.Data; diff --git a/src/main/java/com/alibaba/excel/metadata/data/ReadCellData.java b/src/main/java/com/alibaba/excel/metadata/data/ReadCellData.java new file mode 100644 index 00000000..462cbac7 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/data/ReadCellData.java @@ -0,0 +1,111 @@ +package com.alibaba.excel.metadata.data; + +import java.math.BigDecimal; + +import com.alibaba.excel.enums.CellDataTypeEnum; + +import lombok.Data; + +/** + * read cell data + * + * @author Jiaju Zhuang + */ +@Data +public class ReadCellData extends CellData { + /** + * data format. + */ + private DataFormatData dataFormatData; + + + public ReadCellData(CellDataTypeEnum type) { + super(); + if (type == null) { + throw new IllegalArgumentException("Type can not be null"); + } + setType(type); + } + + public ReadCellData(T data) { + super(); + setData(data); + } + + public ReadCellData(String stringValue) { + this(CellDataTypeEnum.STRING, stringValue); + } + + public ReadCellData(CellDataTypeEnum type, String stringValue) { + super(); + if (type != CellDataTypeEnum.STRING && type != CellDataTypeEnum.ERROR) { + throw new IllegalArgumentException("Only support CellDataTypeEnum.STRING and CellDataTypeEnum.ERROR"); + } + if (stringValue == null) { + throw new IllegalArgumentException("StringValue can not be null"); + } + setType(type); + setStringValue(stringValue); + } + + public ReadCellData(BigDecimal numberValue) { + super(); + if (numberValue == null) { + throw new IllegalArgumentException("DoubleValue can not be null"); + } + setType(CellDataTypeEnum.NUMBER); + setNumberValue(numberValue); + } + + public ReadCellData(Boolean booleanValue) { + super(); + if (booleanValue == null) { + throw new IllegalArgumentException("BooleanValue can not be null"); + } + setType(CellDataTypeEnum.BOOLEAN); + setBooleanValue(booleanValue); + } + + public static ReadCellData newEmptyInstance() { + return newEmptyInstance(null, null); + } + + public static ReadCellData newEmptyInstance(Integer rowIndex, Integer columnIndex) { + ReadCellData cellData = new ReadCellData<>(CellDataTypeEnum.EMPTY); + cellData.setRowIndex(rowIndex); + cellData.setColumnIndex(columnIndex); + return cellData; + } + + public static ReadCellData newInstance(Boolean booleanValue) { + return newInstance(booleanValue, null, null); + } + + public static ReadCellData newInstance(Boolean booleanValue, Integer rowIndex, Integer columnIndex) { + ReadCellData cellData = new ReadCellData<>(booleanValue); + cellData.setRowIndex(rowIndex); + cellData.setColumnIndex(columnIndex); + return cellData; + } + + public static ReadCellData newInstance(String stringValue, Integer rowIndex, Integer columnIndex) { + ReadCellData cellData = new ReadCellData<>(stringValue); + cellData.setRowIndex(rowIndex); + cellData.setColumnIndex(columnIndex); + return cellData; + } + + public static ReadCellData newInstance(BigDecimal numberValue, Integer rowIndex, Integer columnIndex) { + ReadCellData cellData = new ReadCellData<>(numberValue); + cellData.setRowIndex(rowIndex); + cellData.setColumnIndex(columnIndex); + return cellData; + } + + + @Override + public ReadCellData clone(){ + return new ReadCellData<>(""); + } + +} diff --git a/src/main/java/com/alibaba/excel/metadata/RichTextStringData.java b/src/main/java/com/alibaba/excel/metadata/data/RichTextStringData.java similarity index 97% rename from src/main/java/com/alibaba/excel/metadata/RichTextStringData.java rename to src/main/java/com/alibaba/excel/metadata/data/RichTextStringData.java index eabb85c3..4b8a0420 100644 --- a/src/main/java/com/alibaba/excel/metadata/RichTextStringData.java +++ b/src/main/java/com/alibaba/excel/metadata/data/RichTextStringData.java @@ -1,4 +1,4 @@ -package com.alibaba.excel.metadata; +package com.alibaba.excel.metadata.data; import java.util.List; diff --git a/src/main/java/com/alibaba/excel/metadata/data/WriteCellData.java b/src/main/java/com/alibaba/excel/metadata/data/WriteCellData.java new file mode 100644 index 00000000..3f1de9be --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/data/WriteCellData.java @@ -0,0 +1,101 @@ +package com.alibaba.excel.metadata.data; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.util.ListUtils; +import com.alibaba.excel.write.metadata.style.WriteCellStyle; + +import lombok.Data; + +/** + * wirte cell data + * + * @author Jiaju Zhuang + */ +@Data +public class WriteCellData extends CellData { + /** + * Support only when writing.{@link CellDataTypeEnum#DATE} + */ + private Date dateValue; + /** + * rich text.{@link CellDataTypeEnum#RICH_TEXT_STRING} + */ + private RichTextStringData richTextStringDataValue; + /** + * image + */ + private List imageDataList; + /** + * comment + */ + private CommentData commentData; + /** + * hyper link + */ + private HyperlinkData hyperlinkData; + /** + * sytle + */ + private WriteCellStyle writeCellStyle; + + + public WriteCellData(String stringValue) { + this(CellDataTypeEnum.STRING, stringValue); + } + + public WriteCellData(CellDataTypeEnum type, String stringValue) { + super(); + if (type != CellDataTypeEnum.STRING && type != CellDataTypeEnum.ERROR) { + throw new IllegalArgumentException("Only support CellDataTypeEnum.STRING and CellDataTypeEnum.ERROR"); + } + if (stringValue == null) { + throw new IllegalArgumentException("StringValue can not be null"); + } + setType(type); + setStringValue(stringValue); + } + + public WriteCellData(BigDecimal numberValue) { + super(); + if (numberValue == null) { + throw new IllegalArgumentException("DoubleValue can not be null"); + } + setType(CellDataTypeEnum.NUMBER); + setNumberValue(numberValue); + } + + public WriteCellData(Boolean booleanValue) { + super(); + if (booleanValue == null) { + throw new IllegalArgumentException("BooleanValue can not be null"); + } + setType(CellDataTypeEnum.BOOLEAN); + setBooleanValue(booleanValue); + } + + public WriteCellData(Date dateValue) { + super(); + if (dateValue == null) { + throw new IllegalArgumentException("DateValue can not be null"); + } + setType(CellDataTypeEnum.DATE); + this.dateValue = dateValue; + } + + public WriteCellData(byte[] image) { + super(); + if (image == null) { + throw new IllegalArgumentException("Image can not be null"); + } + setType(CellDataTypeEnum.EMPTY); + this.imageDataList= ListUtils.newArrayList(); + ImageData imageData = new ImageData(); + imageData.setImage(image); + imageDataList.add(imageData); + } + +} diff --git a/src/main/java/com/alibaba/excel/parameter/AnalysisParam.java b/src/main/java/com/alibaba/excel/parameter/AnalysisParam.java deleted file mode 100644 index f8679ac0..00000000 --- a/src/main/java/com/alibaba/excel/parameter/AnalysisParam.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.alibaba.excel.parameter; - -import com.alibaba.excel.support.ExcelTypeEnum; - -import java.io.InputStream; - -/** - * - * @author jipengfei - */ -@Deprecated -public class AnalysisParam { - - /** - * @see ExcelTypeEnum - */ - private ExcelTypeEnum excelTypeEnum; - - /** - * the POI filesystem that contains the Workbook stream - */ - private InputStream in; - - /** - * user defined param to listener use - */ - private Object customContent; - - public AnalysisParam(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent) { - this.in = in; - this.excelTypeEnum = excelTypeEnum; - this.customContent = customContent; - } - - public ExcelTypeEnum getExcelTypeEnum() { - return excelTypeEnum; - } - - public void setExcelTypeEnum(ExcelTypeEnum excelTypeEnum) { - this.excelTypeEnum = excelTypeEnum; - } - - public Object getCustomContent() { - return customContent; - } - - public void setCustomContent(Object customContent) { - this.customContent = customContent; - } - - public InputStream getIn() { - return in; - } - - public void setIn(InputStream in) { - this.in = in; - } -} diff --git a/src/main/java/com/alibaba/excel/parameter/GenerateParam.java b/src/main/java/com/alibaba/excel/parameter/GenerateParam.java deleted file mode 100644 index acbcfbde..00000000 --- a/src/main/java/com/alibaba/excel/parameter/GenerateParam.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.alibaba.excel.parameter; - -import java.io.OutputStream; - -import com.alibaba.excel.support.ExcelTypeEnum; - -/** - * Created by jipengfei on 17/2/19. - * - * @author jipengfei - * @deprecated please use {@link com.alibaba.excel.write.builder.ExcelWriterBuilder} build ExcelWriter - */ -@Deprecated -public class GenerateParam { - - private OutputStream outputStream; - - private String sheetName; - - private Class clazz; - - private ExcelTypeEnum type; - - private boolean needHead = true; - - public GenerateParam(String sheetName, Class clazz, OutputStream outputStream) { - this.outputStream = outputStream; - this.sheetName = sheetName; - this.clazz = clazz; - } - - public OutputStream getOutputStream() { - return outputStream; - } - - public void setOutputStream(OutputStream outputStream) { - this.outputStream = outputStream; - } - - public String getSheetName() { - return sheetName; - } - - public void setSheetName(String sheetName) { - this.sheetName = sheetName; - } - - public Class getClazz() { - return clazz; - } - - public void setClazz(Class clazz) { - this.clazz = clazz; - } - - public ExcelTypeEnum getType() { - return type; - } - - public void setType(ExcelTypeEnum type) { - this.type = type; - } - - public boolean isNeedHead() { - return needHead; - } - - public void setNeedHead(boolean needHead) { - this.needHead = needHead; - } -} diff --git a/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java b/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java index 13e3d45b..9feb1515 100644 --- a/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java +++ b/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java @@ -1,23 +1,21 @@ package com.alibaba.excel.read.listener; import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.enums.HeadKindEnum; -import com.alibaba.excel.event.AbstractIgnoreExceptionReadListener; import com.alibaba.excel.exception.ExcelDataConvertException; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.Head; +import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.read.metadata.holder.ReadSheetHolder; import com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty; import com.alibaba.excel.util.ConverterUtils; import com.alibaba.excel.util.FieldUtils; +import com.alibaba.excel.util.MapUtils; import net.sf.cglib.beans.BeanMap; @@ -26,13 +24,13 @@ import net.sf.cglib.beans.BeanMap; * * @author jipengfei */ -public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener>> { +public class ModelBuildEventListener implements ReadListener>> { @Override - public void invokeHead(Map> cellDataMap, AnalysisContext context) {} + public void invokeHead(Map> cellDataMap, AnalysisContext context) {} @Override - public void invoke(Map> cellDataMap, AnalysisContext context) { + public void invoke(Map> cellDataMap, AnalysisContext context) { ReadSheetHolder readSheetHolder = context.readSheetHolder(); if (HeadKindEnum.CLASS.equals(readSheetHolder.excelReadHeadProperty().getHeadKind())) { context.readRowHolder() @@ -42,14 +40,14 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener context.readRowHolder().setCurrentRowAnalysisResult(buildStringList(cellDataMap, readSheetHolder, context)); } - private Object buildStringList(Map> cellDataMap, ReadSheetHolder readSheetHolder, + private Object buildStringList(Map> cellDataMap, ReadSheetHolder readSheetHolder, AnalysisContext context) { int index = 0; if (context.readWorkbookHolder().getDefaultReturnMap()) { - Map map = new LinkedHashMap(cellDataMap.size() * 4 / 3 + 1); - for (Map.Entry> entry : cellDataMap.entrySet()) { + Map map = MapUtils.newLinkedHashMapWithExpectedSize(cellDataMap.size()); + for (Map.Entry> entry : cellDataMap.entrySet()) { Integer key = entry.getKey(); - CellData cellData = entry.getValue(); + ReadCellData cellData = entry.getValue(); while (index < key) { map.put(index, null); index++; @@ -61,7 +59,7 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener } map.put(key, (String)ConverterUtils.convertToJavaObject(cellData, null, null, readSheetHolder.converterMap(), - readSheetHolder, context.readRowHolder().getRowIndex(), key)); + context, context.readRowHolder().getRowIndex(), key)); } int headSize = readSheetHolder.excelReadHeadProperty().getHeadMap().size(); while (index < headSize) { @@ -72,9 +70,9 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener } else { // Compatible with the old code the old code returns a list List list = new ArrayList<>(); - for (Map.Entry> entry : cellDataMap.entrySet()) { + for (Map.Entry> entry : cellDataMap.entrySet()) { Integer key = entry.getKey(); - CellData cellData = entry.getValue(); + ReadCellData cellData = entry.getValue(); while (index < key) { list.add(null); index++; @@ -86,7 +84,7 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener } list.add( (String)ConverterUtils.convertToJavaObject(cellData, null, null, readSheetHolder.converterMap(), - readSheetHolder, context.readRowHolder().getRowIndex(), key)); + context, context.readRowHolder().getRowIndex(), key)); } int headSize = readSheetHolder.excelReadHeadProperty().getHeadMap().size(); while (index < headSize) { @@ -97,7 +95,7 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener } } - private Object buildUserModel(Map> cellDataMap, ReadSheetHolder readSheetHolder, + private Object buildUserModel(Map> cellDataMap, ReadSheetHolder readSheetHolder, AnalysisContext context) { ExcelReadHeadProperty excelReadHeadProperty = readSheetHolder.excelReadHeadProperty(); Object resultModel; @@ -105,24 +103,24 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener resultModel = excelReadHeadProperty.getHeadClazz().newInstance(); } catch (Exception e) { throw new ExcelDataConvertException(context.readRowHolder().getRowIndex(), 0, - new CellData<>(CellDataTypeEnum.EMPTY), null, + new ReadCellData<>(CellDataTypeEnum.EMPTY), null, "Can not instance class: " + excelReadHeadProperty.getHeadClazz().getName(), e); } Map headMap = excelReadHeadProperty.getHeadMap(); - Map map = new HashMap(headMap.size() * 4 / 3 + 1); + Map map = MapUtils.newHashMapWithExpectedSize(headMap.size()); Map contentPropertyMap = excelReadHeadProperty.getContentPropertyMap(); for (Map.Entry entry : headMap.entrySet()) { Integer index = entry.getKey(); if (!cellDataMap.containsKey(index)) { continue; } - CellData cellData = cellDataMap.get(index); + ReadCellData cellData = cellDataMap.get(index); if (cellData.getType() == CellDataTypeEnum.EMPTY) { continue; } ExcelContentProperty excelContentProperty = contentPropertyMap.get(index); Object value = ConverterUtils.convertToJavaObject(cellData, excelContentProperty.getField(), - excelContentProperty, readSheetHolder.converterMap(), readSheetHolder, + excelContentProperty, readSheetHolder.converterMap(), context, context.readRowHolder().getRowIndex(), index); if (value != null) { map.put(FieldUtils.resolveCglibFieldName(excelContentProperty.getField()), value); diff --git a/src/main/java/com/alibaba/excel/read/listener/ReadListener.java b/src/main/java/com/alibaba/excel/read/listener/ReadListener.java index b3a2e970..d951d1a6 100644 --- a/src/main/java/com/alibaba/excel/read/listener/ReadListener.java +++ b/src/main/java/com/alibaba/excel/read/listener/ReadListener.java @@ -4,8 +4,8 @@ import java.util.Map; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.Listener; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.CellExtra; +import com.alibaba.excel.metadata.data.ReadCellData; /** * Interface to listen for read results @@ -21,7 +21,7 @@ public interface ReadListener extends Listener { * @param context * @throws Exception */ - void onException(Exception exception, AnalysisContext context) throws Exception; + default void onException(Exception exception, AnalysisContext context) throws Exception {} /** * When analysis one head row trigger invoke function. @@ -29,27 +29,23 @@ public interface ReadListener extends Listener { * @param headMap * @param context */ - void invokeHead(Map> headMap, AnalysisContext context); + default void invokeHead(Map> headMap, AnalysisContext context) {} /** * When analysis one row trigger invoke function. * - * @param data - * one row value. Is is same as {@link AnalysisContext#readRowHolder()} - * @param context - * analysis context + * @param data one row value. Is is same as {@link AnalysisContext#readRowHolder()} + * @param context analysis context */ void invoke(T data, AnalysisContext context); /** * The current method is called when extra information is returned * - * @param extra - * extra information - * @param context - * analysis context + * @param extra extra information + * @param context analysis context */ - void extra(CellExtra extra, AnalysisContext context); + default void extra(CellExtra extra, AnalysisContext context) {} /** * if have something to do after all analysis @@ -64,5 +60,7 @@ public interface ReadListener extends Listener { * @param context * @return */ - boolean hasNext(AnalysisContext context); + default boolean hasNext(AnalysisContext context) { + return true; + } } diff --git a/src/main/java/com/alibaba/excel/read/metadata/ReadBasicParameter.java b/src/main/java/com/alibaba/excel/read/metadata/ReadBasicParameter.java index d4035873..b5d17cbe 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/ReadBasicParameter.java +++ b/src/main/java/com/alibaba/excel/read/metadata/ReadBasicParameter.java @@ -6,11 +6,14 @@ import java.util.List; import com.alibaba.excel.metadata.BasicParameter; import com.alibaba.excel.read.listener.ReadListener; +import lombok.Data; + /** * Read basic parameter * * @author Jiaju Zhuang **/ +@Data public class ReadBasicParameter extends BasicParameter { /** * Count the number of added heads when read sheet. @@ -26,21 +29,9 @@ public class ReadBasicParameter extends BasicParameter { /** * Custom type listener run after default */ - private List customReadListenerList = new ArrayList(); - - public Integer getHeadRowNumber() { - return headRowNumber; - } - - public void setHeadRowNumber(Integer headRowNumber) { - this.headRowNumber = headRowNumber; - } - - public List getCustomReadListenerList() { - return customReadListenerList; - } + private List> customReadListenerList; - public void setCustomReadListenerList(List customReadListenerList) { - this.customReadListenerList = customReadListenerList; + public ReadBasicParameter() { + customReadListenerList = new ArrayList<>(); } } diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java index 396fa55a..641b489f 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java +++ b/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java @@ -42,7 +42,7 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH /** * Read listener */ - private List readListenerList; + private List> readListenerList; public AbstractReadHolder(ReadBasicParameter readBasicParameter, AbstractReadHolder parentAbstractReadHolder, Boolean convertAllFiled) { @@ -114,7 +114,7 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH @Override - public List readListenerList() { + public List> readListenerList() { return getReadListenerList(); } diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadHolder.java index 43e13013..32ac6ee9 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadHolder.java +++ b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadHolder.java @@ -18,7 +18,7 @@ public interface ReadHolder extends ConfigurationHolder { * * @return Current {@link ReadListener} */ - List readListenerList(); + List> readListenerList(); /** * What {@link ExcelReadHeadProperty} does the currently operated cell need to execute diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java index ddb5ca27..12cd7233 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java +++ b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java @@ -5,15 +5,18 @@ import java.util.Map; import com.alibaba.excel.enums.HolderEnum; import com.alibaba.excel.metadata.Cell; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.CellExtra; +import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.read.metadata.ReadSheet; +import lombok.Data; + /** * sheet holder * * @author Jiaju Zhuang */ +@Data public class ReadSheetHolder extends AbstractReadHolder { /** @@ -51,7 +54,7 @@ public class ReadSheetHolder extends AbstractReadHolder { /** * Current CellData */ - private CellData tempCellData; + private ReadCellData tempCellData; public ReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) { super(readSheet, readWorkbookHolder, readWorkbookHolder.getReadWorkbook().getConvertAllFiled()); @@ -59,42 +62,10 @@ public class ReadSheetHolder extends AbstractReadHolder { this.parentReadWorkbookHolder = readWorkbookHolder; this.sheetNo = readSheet.getSheetNo(); this.sheetName = readSheet.getSheetName(); - this.cellMap = new LinkedHashMap(); + this.cellMap = new LinkedHashMap<>(); this.rowIndex = -1; } - public ReadSheet getReadSheet() { - return readSheet; - } - - public void setReadSheet(ReadSheet readSheet) { - this.readSheet = readSheet; - } - - public ReadWorkbookHolder getParentReadWorkbookHolder() { - return parentReadWorkbookHolder; - } - - public void setParentReadWorkbookHolder(ReadWorkbookHolder parentReadWorkbookHolder) { - this.parentReadWorkbookHolder = parentReadWorkbookHolder; - } - - public Integer getSheetNo() { - return sheetNo; - } - - public void setSheetNo(Integer sheetNo) { - this.sheetNo = sheetNo; - } - - public String getSheetName() { - return sheetName; - } - - public void setSheetName(String sheetName) { - this.sheetName = sheetName; - } - /** * Approximate total number of rows * @@ -106,58 +77,9 @@ public class ReadSheetHolder extends AbstractReadHolder { return approximateTotalRowNumber; } - /** - * Approximate total number of rows - * - * @return - */ - public Integer getApproximateTotalRowNumber() { - return approximateTotalRowNumber; - } - - public void setApproximateTotalRowNumber(Integer approximateTotalRowNumber) { - this.approximateTotalRowNumber = approximateTotalRowNumber; - } - - public Map getCellMap() { - return cellMap; - } - - public void setCellMap(Map cellMap) { - this.cellMap = cellMap; - } - - public Integer getRowIndex() { - return rowIndex; - } - - public void setRowIndex(Integer rowIndex) { - this.rowIndex = rowIndex; - } - - public CellData getTempCellData() { - return tempCellData; - } - - public void setTempCellData(CellData tempCellData) { - this.tempCellData = tempCellData; - } - - public CellExtra getCellExtra() { - return cellExtra; - } - - public void setCellExtra(CellExtra cellExtra) { - this.cellExtra = cellExtra; - } - @Override public HolderEnum holderType() { return HolderEnum.SHEET; } - @Override - public String toString() { - return "ReadSheetHolder{" + "sheetNo=" + sheetNo + ", sheetName='" + sheetName + '\'' + "} " + super.toString(); - } } diff --git a/src/main/java/com/alibaba/excel/read/processor/DefaultAnalysisEventProcessor.java b/src/main/java/com/alibaba/excel/read/processor/DefaultAnalysisEventProcessor.java index f23f58c9..ab2e69de 100644 --- a/src/main/java/com/alibaba/excel/read/processor/DefaultAnalysisEventProcessor.java +++ b/src/main/java/com/alibaba/excel/read/processor/DefaultAnalysisEventProcessor.java @@ -12,7 +12,7 @@ import com.alibaba.excel.enums.HeadKindEnum; import com.alibaba.excel.enums.RowTypeEnum; import com.alibaba.excel.exception.ExcelAnalysisException; import com.alibaba.excel.exception.ExcelAnalysisStopException; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.read.listener.ReadListener; diff --git a/src/main/java/com/alibaba/excel/util/ClassUtils.java b/src/main/java/com/alibaba/excel/util/ClassUtils.java index 16643de4..45df3846 100644 --- a/src/main/java/com/alibaba/excel/util/ClassUtils.java +++ b/src/main/java/com/alibaba/excel/util/ClassUtils.java @@ -16,11 +16,8 @@ import java.util.concurrent.ConcurrentHashMap; import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; -import com.alibaba.excel.event.Handler; import com.alibaba.excel.exception.ExcelCommonException; -import com.alibaba.excel.metadata.BaseRowModel; import com.alibaba.excel.metadata.Holder; -import com.alibaba.excel.write.handler.WriteHandler; import com.alibaba.excel.write.metadata.holder.WriteHolder; /** diff --git a/src/main/java/com/alibaba/excel/util/ConverterUtils.java b/src/main/java/com/alibaba/excel/util/ConverterUtils.java index 61f69ac4..029c8196 100644 --- a/src/main/java/com/alibaba/excel/util/ConverterUtils.java +++ b/src/main/java/com/alibaba/excel/util/ConverterUtils.java @@ -8,11 +8,12 @@ import java.util.Map; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.converters.ConverterKeyBuild; +import com.alibaba.excel.converters.ReadConverterContext; import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.exception.ExcelDataConvertException; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; +import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; -import com.alibaba.excel.read.metadata.holder.ReadHolder; import com.alibaba.excel.read.metadata.holder.ReadSheetHolder; /** @@ -31,13 +32,14 @@ public class ConverterUtils { * @param context * @return */ - public static Map convertToStringMap(Map> cellDataMap, AnalysisContext context) { + public static Map convertToStringMap(Map> cellDataMap, + AnalysisContext context) { Map stringMap = MapUtils.newHashMapWithExpectedSize(cellDataMap.size()); ReadSheetHolder readSheetHolder = context.readSheetHolder(); int index = 0; - for (Map.Entry> entry : cellDataMap.entrySet()) { + for (Map.Entry> entry : cellDataMap.entrySet()) { Integer key = entry.getKey(); - CellData cellData = entry.getValue(); + ReadCellData cellData = entry.getValue(); while (index < key) { stringMap.put(index, null); index++; @@ -55,7 +57,7 @@ public class ConverterUtils { } try { stringMap.put(key, - (String)(converter.convertToJavaData(cellData, null, readSheetHolder))); + (String)(converter.convertToJavaData(new ReadConverterContext<>(cellData, null, context)))); } catch (Exception e) { throw new ExcelDataConvertException(context.readRowHolder().getRowIndex(), key, cellData, null, "Convert data " + cellData + " to String error ", e); @@ -71,14 +73,14 @@ public class ConverterUtils { * @param field * @param contentProperty * @param converterMap - * @param readSheetHolder + * @param context * @param rowIndex * @param columnIndex * @return */ - public static Object convertToJavaObject(CellData cellData, Field field, ExcelContentProperty contentProperty, - Map> converterMap, ReadSheetHolder readSheetHolder, Integer rowIndex, - Integer columnIndex) { + public static Object convertToJavaObject(ReadCellData cellData, Field field, + ExcelContentProperty contentProperty, Map> converterMap, AnalysisContext context, + Integer rowIndex, Integer columnIndex) { Class clazz; if (field == null) { clazz = String.class; @@ -94,12 +96,13 @@ public class ConverterUtils { } else { classGeneric = String.class; } - CellData cellDataReturn = new CellData(cellData); + + ReadCellData cellDataReturn = cellData.clone(); cellDataReturn.setData(doConvertToJavaObject(cellData, classGeneric, contentProperty, converterMap, - readSheetHolder, rowIndex, columnIndex)); + context, rowIndex, columnIndex)); return cellDataReturn; } - return doConvertToJavaObject(cellData, clazz, contentProperty, converterMap, readSheetHolder, rowIndex, + return doConvertToJavaObject(cellData, clazz, contentProperty, converterMap, context, rowIndex, columnIndex); } @@ -108,15 +111,14 @@ public class ConverterUtils { * @param clazz * @param contentProperty * @param converterMap - * @param readSheetHolder + * @param context * @param rowIndex * @param columnIndex * @return */ - private static Object doConvertToJavaObject(CellData cellData, Class clazz, - ExcelContentProperty contentProperty, - Map> converterMap, ReadSheetHolder readSheetHolder, Integer rowIndex, - Integer columnIndex) { + private static Object doConvertToJavaObject(ReadCellData cellData, Class clazz, + ExcelContentProperty contentProperty, Map> converterMap, AnalysisContext context, + Integer rowIndex, Integer columnIndex) { Converter converter = null; if (contentProperty != null) { converter = contentProperty.getConverter(); @@ -129,7 +131,7 @@ public class ConverterUtils { "Converter not found, convert " + cellData.getType() + " to " + clazz.getName()); } try { - return converter.convertToJavaData(cellData, contentProperty, readSheetHolder); + return converter.convertToJavaData(new ReadConverterContext<>(cellData, contentProperty, context)); } catch (Exception e) { throw new ExcelDataConvertException(rowIndex, columnIndex, cellData, contentProperty, "Convert data " + cellData + " to " + clazz + " error ", e); diff --git a/src/main/java/com/alibaba/excel/util/FileTypeUtils.java b/src/main/java/com/alibaba/excel/util/FileTypeUtils.java new file mode 100644 index 00000000..6469da18 --- /dev/null +++ b/src/main/java/com/alibaba/excel/util/FileTypeUtils.java @@ -0,0 +1,46 @@ +package com.alibaba.excel.util; + +import java.util.HashMap; +import java.util.Map; + +import com.alibaba.excel.metadata.data.ImageData.ImageType; + +/** + * file type utils + * + * @author Jiaju Zhuang + */ +public class FileTypeUtils { + + private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', + 'f'}; + private static final int IMAGE_TYPE_MARK_LENGTH = 28; + + private static final Map FILE_TYPE_MAP; + + static { + FILE_TYPE_MAP = new HashMap<>(); + FILE_TYPE_MAP.put("ffd8ff", ImageType.PICTURE_TYPE_JPEG); + FILE_TYPE_MAP.put("89504e47", ImageType.PICTURE_TYPE_PNG); + } + + public static ImageType getImageType(byte[] image) { + if (image == null || image.length <= IMAGE_TYPE_MARK_LENGTH) { + return null; + } + byte[] typeMarkByte = new byte[IMAGE_TYPE_MARK_LENGTH]; + System.arraycopy(image, 0, typeMarkByte, 0, IMAGE_TYPE_MARK_LENGTH); + return FILE_TYPE_MAP.get(encodeHexStr(typeMarkByte)); + } + + private static String encodeHexStr(byte[] data) { + final int len = data.length; + final char[] out = new char[len << 1]; + // two characters from the hex value. + for (int i = 0, j = 0; i < len; i++) { + out[j++] = DIGITS[(0xF0 & data[i]) >>> 4]; + out[j++] = DIGITS[0x0F & data[i]]; + } + return new String(out); + } +} diff --git a/src/main/java/com/alibaba/excel/util/MapUtils.java b/src/main/java/com/alibaba/excel/util/MapUtils.java index 6af4129e..2ecee78a 100644 --- a/src/main/java/com/alibaba/excel/util/MapUtils.java +++ b/src/main/java/com/alibaba/excel/util/MapUtils.java @@ -1,9 +1,7 @@ package com.alibaba.excel.util; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.LinkedHashMap; /** * Map utils @@ -12,6 +10,7 @@ import java.util.Map; **/ public class MapUtils { private MapUtils() {} + /** * Creates a mutable, empty {@code HashMap} instance. * @@ -37,13 +36,44 @@ public class MapUtils { * * @param expectedSize the number of entries you expect to add to the returned map * @return a new, empty {@code HashMap} with enough capacity to hold {@code expectedSize} entries - * without resizing + * without resizing * @throws IllegalArgumentException if {@code expectedSize} is negative */ public static HashMap newHashMapWithExpectedSize(int expectedSize) { return new HashMap<>(capacity(expectedSize)); } + /** + * Creates a mutable, empty, insertion-ordered {@code LinkedHashMap} instance. + * + *

Note: if mutability is not required, use {@link ImmutableMap#of()} instead. + * + *

Note for Java 7 and later: this method is now unnecessary and should be treated as + * deprecated. Instead, use the {@code LinkedHashMap} constructor directly, taking advantage of + * the new "diamond" syntax. + * + * @return a new, empty {@code LinkedHashMap} + */ + public static LinkedHashMap newLinkedHashMap() { + return new LinkedHashMap<>(); + } + + /** + * Creates a {@code LinkedHashMap} instance, with a high enough "initial capacity" that it + * should hold {@code expectedSize} elements without growth. This behavior cannot be + * broadly guaranteed, but it is observed to be true for OpenJDK 1.7. It also can't be guaranteed + * that the method isn't inadvertently oversizing the returned map. + * + * @param expectedSize the number of entries you expect to add to the returned map + * @return a new, empty {@code LinkedHashMap} with enough capacity to hold {@code expectedSize} + * entries without resizing + * @throws IllegalArgumentException if {@code expectedSize} is negative + * @since 19.0 + */ + public static LinkedHashMap newLinkedHashMapWithExpectedSize(int expectedSize) { + return new LinkedHashMap<>(capacity(expectedSize)); + } + /** * Returns a capacity that is sufficient to keep the map from being resized as long as it grows no * larger than expectedSize and the load factor is ≥ its default (0.75). @@ -56,7 +86,7 @@ public class MapUtils { // This is the calculation used in JDK8 to resize when a putAll // happens; it seems to be the most conservative calculation we // can make. 0.75 is the default load factor. - return (int) ((float) expectedSize / 0.75F + 1.0F); + return (int)((float)expectedSize / 0.75F + 1.0F); } return Integer.MAX_VALUE; } diff --git a/src/main/java/com/alibaba/excel/util/NumberUtils.java b/src/main/java/com/alibaba/excel/util/NumberUtils.java index 09a15bea..4bb6c91b 100644 --- a/src/main/java/com/alibaba/excel/util/NumberUtils.java +++ b/src/main/java/com/alibaba/excel/util/NumberUtils.java @@ -5,9 +5,8 @@ import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.ParseException; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; -import com.alibaba.excel.write.metadata.holder.WriteHolder; /** * Number utils @@ -47,8 +46,8 @@ public class NumberUtils { * @param contentProperty * @return */ - public static CellData formatToCellDataString(Number num, ExcelContentProperty contentProperty) { - return new CellData<>(format(num, contentProperty)); + public static WriteCellData formatToCellDataString(Number num, ExcelContentProperty contentProperty) { + return new WriteCellData<>(format(num, contentProperty)); } /** @@ -56,16 +55,13 @@ public class NumberUtils { * * @param num * @param contentProperty - * @param currentWriteHolder * @return */ - public static CellData formatToCellData(Number num, ExcelContentProperty contentProperty, - WriteHolder currentWriteHolder) { - CellData cellData = new CellData<>(BigDecimal.valueOf(num.doubleValue())); + public static WriteCellData formatToCellData(Number num, ExcelContentProperty contentProperty) { + WriteCellData cellData = new WriteCellData<>(BigDecimal.valueOf(num.doubleValue())); if (contentProperty != null && contentProperty.getNumberFormatProperty() != null && StringUtils.isNotBlank(contentProperty.getNumberFormatProperty().getFormat())) { - WorkBookUtil.fillDataFormat(cellData, currentWriteHolder, - contentProperty.getNumberFormatProperty().getFormat()); + WorkBookUtil.fillDataFormat(cellData, contentProperty.getNumberFormatProperty().getFormat()); } return cellData; } diff --git a/src/main/java/com/alibaba/excel/util/WorkBookUtil.java b/src/main/java/com/alibaba/excel/util/WorkBookUtil.java index 0ee92209..fb8a428b 100644 --- a/src/main/java/com/alibaba/excel/util/WorkBookUtil.java +++ b/src/main/java/com/alibaba/excel/util/WorkBookUtil.java @@ -2,12 +2,11 @@ package com.alibaba.excel.util; import java.io.IOException; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.DataFormatData; +import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.support.ExcelTypeEnum; -import com.alibaba.excel.write.metadata.holder.WriteHolder; -import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; -import com.alibaba.excel.write.metadata.holder.WriteTableHolder; import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; +import com.alibaba.excel.write.metadata.style.WriteCellStyle; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -95,15 +94,15 @@ public class WorkBookUtil { return cell; } - public static void fillDataFormat(CellData cellData, WriteHolder currentWriteHolder, String format) { - WriteWorkbookHolder writeWorkbookHolder; - if (currentWriteHolder instanceof WriteSheetHolder) { - writeWorkbookHolder = ((WriteSheetHolder)currentWriteHolder).getParentWriteWorkbookHolder(); - } else { - writeWorkbookHolder = ((WriteTableHolder)currentWriteHolder).getParentWriteSheetHolder() - .getParentWriteWorkbookHolder(); + public static void fillDataFormat(WriteCellData cellData, String format) { + if (cellData.getWriteCellStyle() == null) { + cellData.setWriteCellStyle(new WriteCellStyle()); + } + if (cellData.getWriteCellStyle().getDataFormatData() == null) { + cellData.getWriteCellStyle().setDataFormatData(new DataFormatData()); + } + if (cellData.getWriteCellStyle().getDataFormatData().getFormat() == null) { + cellData.getWriteCellStyle().getDataFormatData().setFormat(format); } - cellData.setDataFormat(writeWorkbookHolder.getDataFormat(format)); - cellData.setDataFormatString(format); } } diff --git a/src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java b/src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java index 0bd0a068..aa613a1e 100644 --- a/src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java +++ b/src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java @@ -5,7 +5,7 @@ import java.util.List; import java.util.Map; import com.alibaba.excel.context.WriteContext; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.handler.RowWriteHandler; diff --git a/src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java b/src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java index 51463e69..e96df6f8 100644 --- a/src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java @@ -6,7 +6,7 @@ import com.alibaba.excel.converters.ConverterKeyBuild; import com.alibaba.excel.converters.NullableObjectConverter; import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.exception.ExcelDataConvertException; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.WriteHandlerUtils; diff --git a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java index c4b3e45e..ebc3516f 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -10,7 +10,7 @@ import java.util.TreeMap; import com.alibaba.excel.context.WriteContext; import com.alibaba.excel.enums.HeadKindEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.ClassUtils; diff --git a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java index 9a144534..fbae327a 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java @@ -14,7 +14,7 @@ import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.enums.WriteDirectionEnum; import com.alibaba.excel.enums.WriteTemplateAnalysisCellTypeEnum; import com.alibaba.excel.exception.ExcelGenerateException; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.util.WriteHandlerUtils; diff --git a/src/main/java/com/alibaba/excel/write/handler/AbstractCellWriteHandler.java b/src/main/java/com/alibaba/excel/write/handler/AbstractCellWriteHandler.java index 6b663ce9..642fdffd 100644 --- a/src/main/java/com/alibaba/excel/write/handler/AbstractCellWriteHandler.java +++ b/src/main/java/com/alibaba/excel/write/handler/AbstractCellWriteHandler.java @@ -5,7 +5,7 @@ import java.util.List; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder; diff --git a/src/main/java/com/alibaba/excel/write/handler/CellWriteHandler.java b/src/main/java/com/alibaba/excel/write/handler/CellWriteHandler.java index 4c9e39ed..5cf16c1b 100644 --- a/src/main/java/com/alibaba/excel/write/handler/CellWriteHandler.java +++ b/src/main/java/com/alibaba/excel/write/handler/CellWriteHandler.java @@ -2,7 +2,7 @@ package com.alibaba.excel.write.handler; import java.util.List; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder; diff --git a/src/main/java/com/alibaba/excel/write/handler/impl/FillDataFormatCellWriteHandler.java b/src/main/java/com/alibaba/excel/write/handler/impl/FillDataFormatCellWriteHandler.java index a465546b..2186f381 100644 --- a/src/main/java/com/alibaba/excel/write/handler/impl/FillDataFormatCellWriteHandler.java +++ b/src/main/java/com/alibaba/excel/write/handler/impl/FillDataFormatCellWriteHandler.java @@ -7,7 +7,7 @@ import java.util.Set; import com.alibaba.excel.constant.OrderConstant; import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.event.Order; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.StyleUtil; diff --git a/src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java b/src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java index 7b3d4b2b..21e80716 100644 --- a/src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java +++ b/src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java @@ -2,7 +2,7 @@ package com.alibaba.excel.write.merge; import java.util.List; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; diff --git a/src/main/java/com/alibaba/excel/write/metadata/WriteBasicParameter.java b/src/main/java/com/alibaba/excel/write/metadata/WriteBasicParameter.java index e6d2b9f0..91527cc1 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/WriteBasicParameter.java +++ b/src/main/java/com/alibaba/excel/write/metadata/WriteBasicParameter.java @@ -7,11 +7,14 @@ import java.util.List; import com.alibaba.excel.metadata.BasicParameter; import com.alibaba.excel.write.handler.WriteHandler; +import lombok.Data; + /** * Write basic parameter * * @author Jiaju Zhuang **/ +@Data public class WriteBasicParameter extends BasicParameter { /** * Writes the head relative to the existing contents of the sheet. Indexes are zero-based. @@ -49,77 +52,4 @@ public class WriteBasicParameter extends BasicParameter { * Only output the custom columns. */ private Collection includeColumnFieldNames; - - public Integer getRelativeHeadRowIndex() { - return relativeHeadRowIndex; - } - - public void setRelativeHeadRowIndex(Integer relativeHeadRowIndex) { - this.relativeHeadRowIndex = relativeHeadRowIndex; - } - - public Boolean getNeedHead() { - return needHead; - } - - public void setNeedHead(Boolean needHead) { - this.needHead = needHead; - } - - public List getCustomWriteHandlerList() { - return customWriteHandlerList; - } - - public void setCustomWriteHandlerList(List customWriteHandlerList) { - this.customWriteHandlerList = customWriteHandlerList; - } - - public Boolean getUseDefaultStyle() { - return useDefaultStyle; - } - - public void setUseDefaultStyle(Boolean useDefaultStyle) { - this.useDefaultStyle = useDefaultStyle; - } - - public Boolean getAutomaticMergeHead() { - return automaticMergeHead; - } - - public void setAutomaticMergeHead(Boolean automaticMergeHead) { - this.automaticMergeHead = automaticMergeHead; - } - - public Collection getExcludeColumnIndexes() { - return excludeColumnIndexes; - } - - public void setExcludeColumnIndexes(Collection excludeColumnIndexes) { - this.excludeColumnIndexes = excludeColumnIndexes; - } - - public Collection getExcludeColumnFieldNames() { - return excludeColumnFieldNames; - } - - public void setExcludeColumnFieldNames(Collection excludeColumnFieldNames) { - this.excludeColumnFieldNames = excludeColumnFieldNames; - } - - public Collection getIncludeColumnIndexes() { - return includeColumnIndexes; - } - - public void setIncludeColumnIndexes(Collection includeColumnIndexes) { - this.includeColumnIndexes = includeColumnIndexes; - } - - public Collection getIncludeColumnFieldNames() { - return includeColumnFieldNames; - } - - public void setIncludeColumnFieldNames(Collection includeColumnFieldNames) { - this.includeColumnFieldNames = includeColumnFieldNames; - } - } diff --git a/src/main/java/com/alibaba/excel/write/metadata/WriteSheet.java b/src/main/java/com/alibaba/excel/write/metadata/WriteSheet.java index 62fac752..96e88c2e 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/WriteSheet.java +++ b/src/main/java/com/alibaba/excel/write/metadata/WriteSheet.java @@ -3,10 +3,11 @@ package com.alibaba.excel.write.metadata; import java.util.HashMap; import java.util.Map; -import com.alibaba.excel.metadata.TableStyle; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; +import org.apache.poi.ss.usermodel.TableStyle; + /** * Write sheet * diff --git a/src/main/java/com/alibaba/excel/write/metadata/WriteTable.java b/src/main/java/com/alibaba/excel/write/metadata/WriteTable.java index ec7933c0..a7bcc814 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/WriteTable.java +++ b/src/main/java/com/alibaba/excel/write/metadata/WriteTable.java @@ -1,6 +1,5 @@ package com.alibaba.excel.write.metadata; -import com.alibaba.excel.metadata.TableStyle; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; /** diff --git a/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java b/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java index c28e0412..899e4ca1 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java +++ b/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java @@ -5,13 +5,15 @@ import java.io.InputStream; import java.io.OutputStream; import com.alibaba.excel.support.ExcelTypeEnum; -import com.alibaba.excel.write.handler.WriteHandler; + +import lombok.Data; /** * Workbook * * @author Jiaju Zhuang **/ +@Data public class WriteWorkbook extends WriteBasicParameter { /** * Excel type.The default is xlsx @@ -78,107 +80,4 @@ public class WriteWorkbook extends WriteBasicParameter { */ @Deprecated private Boolean convertAllFiled; - /** - * Write handler - * - * @deprecated please use {@link WriteHandler} - */ - @Deprecated - private com.alibaba.excel.event.WriteHandler writeHandler; - - public ExcelTypeEnum getExcelType() { - return excelType; - } - - public void setExcelType(ExcelTypeEnum excelType) { - this.excelType = excelType; - } - - public File getFile() { - return file; - } - - public void setFile(File file) { - this.file = file; - } - - public OutputStream getOutputStream() { - return outputStream; - } - - public void setOutputStream(OutputStream outputStream) { - this.outputStream = outputStream; - } - - public InputStream getTemplateInputStream() { - return templateInputStream; - } - - public void setTemplateInputStream(InputStream templateInputStream) { - this.templateInputStream = templateInputStream; - } - - public File getTemplateFile() { - return templateFile; - } - - public void setTemplateFile(File templateFile) { - this.templateFile = templateFile; - } - - public Boolean getAutoCloseStream() { - return autoCloseStream; - } - - public void setAutoCloseStream(Boolean autoCloseStream) { - this.autoCloseStream = autoCloseStream; - } - - public Boolean getMandatoryUseInputStream() { - return mandatoryUseInputStream; - } - - public void setMandatoryUseInputStream(Boolean mandatoryUseInputStream) { - this.mandatoryUseInputStream = mandatoryUseInputStream; - } - - public Boolean getConvertAllFiled() { - return convertAllFiled; - } - - public void setConvertAllFiled(Boolean convertAllFiled) { - this.convertAllFiled = convertAllFiled; - } - - public com.alibaba.excel.event.WriteHandler getWriteHandler() { - return writeHandler; - } - - public void setWriteHandler(com.alibaba.excel.event.WriteHandler writeHandler) { - this.writeHandler = writeHandler; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public Boolean getInMemory() { - return inMemory; - } - - public void setInMemory(Boolean inMemory) { - this.inMemory = inMemory; - } - - public Boolean getWriteExcelOnException() { - return writeExcelOnException; - } - - public void setWriteExcelOnException(Boolean writeExcelOnException) { - this.writeExcelOnException = writeExcelOnException; - } } diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java index 54c31245..80f858e7 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java @@ -24,7 +24,6 @@ import com.alibaba.excel.event.Order; import com.alibaba.excel.metadata.AbstractHolder; import com.alibaba.excel.metadata.Font; import com.alibaba.excel.metadata.Head; -import com.alibaba.excel.metadata.TableStyle; import com.alibaba.excel.metadata.property.LoopMergeProperty; import com.alibaba.excel.metadata.property.OnceAbsoluteMergeProperty; import com.alibaba.excel.metadata.property.RowHeightProperty; diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java index 671b96f7..a48e39e8 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java @@ -13,6 +13,7 @@ import java.util.Map; import com.alibaba.excel.constant.BuiltinFormats; import com.alibaba.excel.enums.HolderEnum; import com.alibaba.excel.exception.ExcelGenerateException; +import com.alibaba.excel.metadata.data.DataFormatData; import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.util.FileUtils; import com.alibaba.excel.util.IoUtils; @@ -122,7 +123,7 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { /** * Used to cache data Format. */ - private Map dataFormatCache; + private Map dataFormatCache; public WriteWorkbookHolder(WriteWorkbook writeWorkbook) { super(writeWorkbook, null, writeWorkbook.getConvertAllFiled()); @@ -210,11 +211,11 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { * @param format * @return */ - public Short getDataFormat(String format) { + public DataFormatData getDataFormat(String format) { if (StringUtils.isEmpty(format)) { return BuiltinFormats.GENERAL; } - Short dataFormat = dataFormatCache.get(format); + DataFormatData dataFormat = dataFormatCache.get(format); if (dataFormat != null) { return dataFormat; } diff --git a/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java b/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java index 330aa51a..8661897b 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java +++ b/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java @@ -1,12 +1,14 @@ package com.alibaba.excel.write.metadata.style; +import com.alibaba.excel.constant.BuiltinFormats; +import com.alibaba.excel.metadata.DataFormat; +import com.alibaba.excel.metadata.data.DataFormatData; import com.alibaba.excel.metadata.property.FontProperty; import com.alibaba.excel.metadata.property.StyleProperty; import com.alibaba.excel.util.StringUtils; import lombok.Data; import org.apache.poi.ss.usermodel.BorderStyle; -import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.IgnoredErrorType; @@ -23,7 +25,8 @@ public class WriteCellStyle { /** * Set the data format (must be a valid format). Built in formats are defined at {@link BuiltinFormats}. */ - private Short dataFormat; + private DataFormatData dataFormatData; + /** * Set the font for this style */ diff --git a/src/main/java/com/alibaba/excel/write/style/AbstractCellStyleStrategy.java b/src/main/java/com/alibaba/excel/write/style/AbstractCellStyleStrategy.java index f131c456..9442e4e2 100644 --- a/src/main/java/com/alibaba/excel/write/style/AbstractCellStyleStrategy.java +++ b/src/main/java/com/alibaba/excel/write/style/AbstractCellStyleStrategy.java @@ -3,7 +3,7 @@ package com.alibaba.excel.write.style; import java.util.List; import com.alibaba.excel.event.NotRepeatExecutor; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.handler.WorkbookWriteHandler; diff --git a/src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java b/src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java index 277f96b9..3037fbc9 100644 --- a/src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java +++ b/src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java @@ -2,16 +2,15 @@ package com.alibaba.excel.write.style.column; import java.util.List; -import org.apache.poi.ss.usermodel.Cell; - import com.alibaba.excel.event.NotRepeatExecutor; -import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.Head; -import com.alibaba.excel.write.handler.AbstractCellWriteHandler; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder; +import org.apache.poi.ss.usermodel.Cell; + /** * Column width style strategy * diff --git a/src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java b/src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java index d306d2e4..b388bc44 100644 --- a/src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java +++ b/src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java @@ -4,7 +4,7 @@ import java.util.List; import org.apache.poi.ss.usermodel.Cell; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; diff --git a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java index c6cc9df1..1010163e 100644 --- a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java +++ b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java @@ -8,7 +8,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.poi.ss.usermodel.Cell; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; diff --git a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataData.java b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataData.java index ac928ec1..bed0685d 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataData.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataData.java @@ -2,9 +2,8 @@ package com.alibaba.easyexcel.test.core.celldata; import java.util.Date; -import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.format.DateTimeFormat; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import lombok.Data; diff --git a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java index ad8cbf13..fdedb1ef 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java @@ -3,22 +3,17 @@ package com.alibaba.easyexcel.test.core.celldata; import java.io.File; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import com.alibaba.easyexcel.test.core.simple.SimpleData; -import com.alibaba.easyexcel.test.core.simple.SimpleDataListener; -import com.alibaba.easyexcel.test.core.simple.SimpleDataSheetNameListener; import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.util.DateUtils; /** diff --git a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityData.java b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityData.java index 45b7f63a..c0d9d89f 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityData.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityData.java @@ -1,7 +1,6 @@ package com.alibaba.easyexcel.test.core.compatibility; import com.alibaba.excel.annotation.ExcelProperty; -import com.alibaba.excel.metadata.BaseRowModel; import lombok.Data; diff --git a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataTest.java index 258f055c..87edf636 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataTest.java @@ -20,9 +20,6 @@ import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.metadata.Font; -import com.alibaba.excel.metadata.Sheet; -import com.alibaba.excel.metadata.Table; -import com.alibaba.excel.metadata.TableStyle; import com.alibaba.excel.parameter.AnalysisParam; import com.alibaba.excel.parameter.GenerateParam; diff --git a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityParameterDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityParameterDataTest.java index 2e3b7355..9890f894 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityParameterDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityParameterDataTest.java @@ -15,7 +15,6 @@ import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; import com.alibaba.excel.ExcelWriter; -import com.alibaba.excel.metadata.Sheet; /** * diff --git a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityReadData.java b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityReadData.java index ba062a5f..6ff7bbfb 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityReadData.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityReadData.java @@ -1,7 +1,5 @@ package com.alibaba.easyexcel.test.core.compatibility; -import com.alibaba.excel.metadata.BaseRowModel; - import lombok.Data; /** diff --git a/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterData.java b/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterData.java index fdff30e3..619415c6 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterData.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterData.java @@ -4,7 +4,7 @@ import java.math.BigDecimal; import java.util.Date; import com.alibaba.excel.annotation.ExcelProperty; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import lombok.Data; diff --git a/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java index a339e9ef..3b3b8d1a 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java @@ -13,7 +13,7 @@ import org.junit.runners.MethodSorters; import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.FileUtils; diff --git a/src/test/java/com/alibaba/easyexcel/test/core/handler/WriteHandler.java b/src/test/java/com/alibaba/easyexcel/test/core/handler/WriteHandler.java index cf9c5d26..0a852c0f 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/handler/WriteHandler.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/handler/WriteHandler.java @@ -6,7 +6,7 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.junit.Assert; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.handler.RowWriteHandler; diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/read/CellDataDemoHeadDataListener.java b/src/test/java/com/alibaba/easyexcel/test/demo/read/CellDataDemoHeadDataListener.java index 896cea62..53e0bf68 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/read/CellDataDemoHeadDataListener.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/read/CellDataDemoHeadDataListener.java @@ -2,14 +2,12 @@ package com.alibaba.easyexcel.test.demo.read; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; -import com.alibaba.excel.metadata.CellData; import com.alibaba.fastjson.JSON; /** diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/read/CellDataReadDemoData.java b/src/test/java/com/alibaba/easyexcel/test/demo/read/CellDataReadDemoData.java index f5d01e0c..357dbfe9 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/read/CellDataReadDemoData.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/read/CellDataReadDemoData.java @@ -2,7 +2,7 @@ package com.alibaba.easyexcel.test.demo.read; import java.util.Date; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import lombok.Data; diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/read/CustomStringStringConverter.java b/src/test/java/com/alibaba/easyexcel/test/demo/read/CustomStringStringConverter.java index 5201e750..6116c852 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/read/CustomStringStringConverter.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/read/CustomStringStringConverter.java @@ -2,7 +2,7 @@ package com.alibaba.easyexcel.test.demo.read; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; import com.alibaba.excel.metadata.property.ExcelContentProperty; diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomCellWriteHandler.java b/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomCellWriteHandler.java index b4ade88f..e9567a27 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomCellWriteHandler.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomCellWriteHandler.java @@ -9,9 +9,8 @@ import org.apache.poi.ss.usermodel.Hyperlink; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; -import com.alibaba.excel.write.handler.AbstractCellWriteHandler; import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder; diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomStringStringConverter.java b/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomStringStringConverter.java index 45ebc8c1..53aec631 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomStringStringConverter.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomStringStringConverter.java @@ -2,7 +2,7 @@ package com.alibaba.easyexcel.test.demo.write; import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; import com.alibaba.excel.metadata.property.ExcelContentProperty; diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/LockDataListener.java b/src/test/java/com/alibaba/easyexcel/test/temp/LockDataListener.java index 64cce8db..bda277c6 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/LockDataListener.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/LockDataListener.java @@ -2,7 +2,6 @@ package com.alibaba.easyexcel.test.temp; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,7 +9,6 @@ import org.slf4j.LoggerFactory; import com.alibaba.easyexcel.test.demo.read.DemoDataListener; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; -import com.alibaba.excel.metadata.CellData; import com.alibaba.fastjson.JSON; /** diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatData.java b/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatData.java index d057d8e7..ae663254 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatData.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatData.java @@ -1,6 +1,6 @@ package com.alibaba.easyexcel.test.temp.dataformat; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import lombok.Data; diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/poi/TestCell.java b/src/test/java/com/alibaba/easyexcel/test/temp/poi/TestCell.java index bb12c220..0edc995d 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/poi/TestCell.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/poi/TestCell.java @@ -2,7 +2,7 @@ package com.alibaba.easyexcel.test.temp.poi; import java.util.List; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import lombok.Data; diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/read/CommentTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/read/CommentTest.java index 22de3956..48512b6c 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/read/CommentTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/read/CommentTest.java @@ -10,7 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.alibaba.excel.EasyExcel; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.fastjson.JSON; /** diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/read/HDListener.java b/src/test/java/com/alibaba/easyexcel/test/temp/read/HDListener.java index e52dc51a..1c58e798 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/read/HDListener.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/read/HDListener.java @@ -7,7 +7,6 @@ import org.slf4j.LoggerFactory; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; -import com.alibaba.excel.metadata.CellData; import com.alibaba.fastjson.JSON; /** diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/simple/WriteCellHandler.java b/src/test/java/com/alibaba/easyexcel/test/temp/simple/WriteCellHandler.java index 375cf636..d8825f0c 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/simple/WriteCellHandler.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/simple/WriteCellHandler.java @@ -1,8 +1,7 @@ package com.alibaba.easyexcel.test.temp.simple; -import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.Head; -import com.alibaba.excel.write.handler.AbstractCellWriteHandler; import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder;