From c589b43998a1e698425a82658554a830b827c8b7 Mon Sep 17 00:00:00 2001 From: jueyue Date: Thu, 17 Oct 2019 17:29:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8lombok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- easypoi-base/pom.xml | 6 + .../easypoi/excel/entity/ExcelBaseParams.java | 26 +-- .../excel/entity/ExcelToHtmlParams.java | 50 +----- .../easypoi/excel/entity/ExportExcelItem.java | 18 +- .../easypoi/excel/entity/ExportParams.java | 169 +----------------- .../easypoi/excel/entity/ImportParams.java | 155 +--------------- .../excel/entity/TemplateExportParams.java | 105 +---------- .../excel/entity/TemplateSumEntity.java | 44 +---- .../excel/entity/params/ExcelBaseEntity.java | 102 +---------- .../entity/params/ExcelCollectionParams.java | 34 +--- .../entity/params/ExcelExportEntity.java | 123 +------------ .../entity/params/ExcelForEachParams.java | 73 +------- .../entity/params/ExcelImportEntity.java | 66 +------ .../excel/entity/params/MergeEntity.java | 34 +--- .../entity/result/ExcelImportResult.java | 49 +---- .../result/ExcelVerifyHandlerResult.java | 19 +- .../easypoi/excel/entity/sax/SaxConstant.java | 4 + .../excel/entity/sax/SaxReadCellEntity.java | 18 +- .../excel/export/ExcelExportService.java | 4 +- .../excel/export/base/BaseExportService.java | 30 +++- .../export/base/ExportCommonService.java | 56 +++--- .../excel/imports/CellValueService.java | 6 +- .../excel/imports/sax/SheetHandler.java | 60 ++++++- pom.xml | 7 + 24 files changed, 173 insertions(+), 1085 deletions(-) diff --git a/easypoi-base/pom.xml b/easypoi-base/pom.xml index e14d7e0..5b39d88 100644 --- a/easypoi-base/pom.xml +++ b/easypoi-base/pom.xml @@ -97,6 +97,12 @@ validation-api + + org.projectlombok + lombok + provided + + cn.afterturn easypoi-annotation diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExcelBaseParams.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExcelBaseParams.java index 3d57283..0ce3762 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExcelBaseParams.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExcelBaseParams.java @@ -18,13 +18,14 @@ package cn.afterturn.easypoi.excel.entity; import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; import cn.afterturn.easypoi.handler.inter.IExcelDictHandler; import cn.afterturn.easypoi.handler.inter.IExcelI18nHandler; +import lombok.Data; /** * 基础参数 * @author JueYue * 2014年6月20日 下午1:56:52 */ -@SuppressWarnings("rawtypes") +@Data public class ExcelBaseParams { /** @@ -41,27 +42,4 @@ public class ExcelBaseParams { */ private IExcelI18nHandler i18nHandler; - public IExcelDataHandler getDataHandler() { - return dataHandler; - } - - public void setDataHandler(IExcelDataHandler dataHandler) { - this.dataHandler = dataHandler; - } - - public IExcelDictHandler getDictHandler() { - return dictHandler; - } - - public void setDictHandler(IExcelDictHandler dictHandler) { - this.dictHandler = dictHandler; - } - - public IExcelI18nHandler getI18nHandler() { - return i18nHandler; - } - - public void setI18nHandler(IExcelI18nHandler i18nHandler) { - this.i18nHandler = i18nHandler; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExcelToHtmlParams.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExcelToHtmlParams.java index e4a126e..b528a64 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExcelToHtmlParams.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExcelToHtmlParams.java @@ -1,5 +1,6 @@ package cn.afterturn.easypoi.excel.entity; +import lombok.Data; import org.apache.poi.ss.usermodel.Workbook; /** @@ -7,6 +8,7 @@ import org.apache.poi.ss.usermodel.Workbook; * @author JueYue * 2015年8月7日 下午1:45:46 */ +@Data public class ExcelToHtmlParams { /** * Excel @@ -69,54 +71,6 @@ public class ExcelToHtmlParams { this.path = path; } - public Workbook getWb() { - return wb; - } - - public void setWb(Workbook wb) { - this.wb = wb; - } - - public boolean isCompleteHTML() { - return completeHTML; - } - - public void setCompleteHTML(boolean completeHTML) { - this.completeHTML = completeHTML; - } - - public int getSheetNum() { - return sheetNum; - } - - public void setSheetNum(int sheetNum) { - this.sheetNum = sheetNum; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public boolean isShowRowNum() { - return showRowNum; - } - - public void setShowRowNum(boolean showRowNum) { - this.showRowNum = showRowNum; - } - - public boolean isShowColumnHead() { - return showColumnHead; - } - - public void setShowColumnHead(boolean showColumnHead) { - this.showColumnHead = showColumnHead; - } - @Override public boolean equals(Object obj) { if (obj instanceof ExcelToHtmlParams) { diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportExcelItem.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportExcelItem.java index 285666d..04cd3c7 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportExcelItem.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportExcelItem.java @@ -7,29 +7,15 @@ import java.util.List; import java.util.Map; import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; +import lombok.Data; /** * @author xfworld * @since 2016-5-26 * @version 1.0 */ +@Data public class ExportExcelItem { private List entityList; private List> resultList; - - public List getEntityList() { - return this.entityList; - } - - public void setEntityList(List entityList) { - this.entityList = entityList; - } - - public List> getResultList() { - return this.resultList; - } - - public void setResultList(List> resultList) { - this.resultList = resultList; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportParams.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportParams.java index a837276..5097a20 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportParams.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportParams.java @@ -17,6 +17,7 @@ package cn.afterturn.easypoi.excel.entity; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerDefaultImpl; +import lombok.Data; import org.apache.poi.hssf.util.HSSFColor; /** @@ -25,6 +26,7 @@ import org.apache.poi.hssf.util.HSSFColor; * @author JueYue * @version 1.0 2013年8月24日 */ +@Data public class ExportParams extends ExcelBaseParams { /** @@ -142,171 +144,4 @@ public class ExportParams extends ExcelBaseParams { this.sheetName = sheetName; } - public short getColor() { - return color; - } - - public String[] getExclusions() { - return exclusions; - } - - public short getHeaderColor() { - return headerColor; - } - - public String getSecondTitle() { - return secondTitle; - } - - public short getSecondTitleHeight() { - return (short) (secondTitleHeight * 50); - } - - public String getSheetName() { - return sheetName; - } - - public String getTitle() { - return title; - } - - public short getTitleHeight() { - return (short) (titleHeight * 50); - } - - public boolean isAddIndex() { - return addIndex; - } - - public void setAddIndex(boolean addIndex) { - this.addIndex = addIndex; - } - - public void setColor(short color) { - this.color = color; - } - - public void setExclusions(String[] exclusions) { - this.exclusions = exclusions; - } - - public void setHeaderColor(short headerColor) { - this.headerColor = headerColor; - } - - public void setSecondTitle(String secondTitle) { - this.secondTitle = secondTitle; - } - - public void setSecondTitleHeight(short secondTitleHeight) { - this.secondTitleHeight = secondTitleHeight; - } - - public void setSheetName(String sheetName) { - this.sheetName = sheetName; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setTitleHeight(short titleHeight) { - this.titleHeight = titleHeight; - } - - public ExcelType getType() { - return type; - } - - public void setType(ExcelType type) { - this.type = type; - } - - public String getIndexName() { - return indexName; - } - - public void setIndexName(String indexName) { - this.indexName = indexName; - } - - public Class getStyle() { - return style; - } - - public void setStyle(Class style) { - this.style = style; - } - - public int getFreezeCol() { - return freezeCol; - } - - public void setFreezeCol(int freezeCol) { - this.freezeCol = freezeCol; - } - - public boolean isCreateHeadRows() { - return isCreateHeadRows; - } - - public void setCreateHeadRows(boolean isCreateHeadRows) { - this.isCreateHeadRows = isCreateHeadRows; - } - - public boolean isDynamicData() { - return isDynamicData; - } - - public void setDynamicData(boolean isDynamicData) { - this.isDynamicData = isDynamicData; - } - - public boolean isAppendGraph() { - return isAppendGraph; - } - - public void setAppendGraph(boolean isAppendGraph) { - this.isAppendGraph = isAppendGraph; - } - - public int getMaxNum() { - return maxNum; - } - - public void setMaxNum(int maxNum) { - this.maxNum = maxNum; - } - - public short getHeight() { - return height == -1 ? -1 : (short) (height * 50); - } - - public void setHeight(short height) { - this.height = height; - } - - public short getHeaderHeight() { - return (short) (titleHeight * 50); - } - - public void setHeaderHeight(double headerHeight) { - this.headerHeight = headerHeight; - } - - public boolean isFixedTitle() { - return isFixedTitle; - } - - public void setFixedTitle(boolean fixedTitle) { - isFixedTitle = fixedTitle; - } - - public boolean isReadonly() { - return readonly; - } - - public void setReadonly(boolean readonly) { - this.readonly = readonly; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java index 3752975..14b8747 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java @@ -16,6 +16,7 @@ package cn.afterturn.easypoi.excel.entity; import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler; +import lombok.Data; /** * 导入参数设置 @@ -24,7 +25,7 @@ import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler; * 2013-9-24 * @version 1.0 */ -@SuppressWarnings("rawtypes") +@Data public class ImportParams extends ExcelBaseParams { public static final String SAVE_URL = "/excel/upload/excelUpload"; @@ -110,156 +111,4 @@ public class ImportParams extends ExcelBaseParams { * 最小截取大小 */ private Integer critical = 1000; - - public int getHeadRows() { - return headRows; - } - - public String getSaveUrl() { - return saveUrl; - } - - public int getSheetNum() { - return sheetNum; - } - - public int getStartRows() { - return startRows; - } - - public int getTitleRows() { - return titleRows; - } - - public IExcelVerifyHandler getVerifyHandler() { - return verifyHandler; - } - - public boolean isNeedSave() { - return needSave; - } - - public void setHeadRows(int headRows) { - this.headRows = headRows; - } - - public void setKeyIndex(Integer keyIndex) { - this.keyIndex = keyIndex; - } - - public void setNeedSave(boolean needSave) { - this.needSave = needSave; - } - - public void setSaveUrl(String saveUrl) { - this.saveUrl = saveUrl; - } - - public void setSheetNum(int sheetNum) { - this.sheetNum = sheetNum; - } - - public void setStartRows(int startRows) { - this.startRows = startRows; - } - - public void setTitleRows(int titleRows) { - this.titleRows = titleRows; - } - - public void setVerifyHandler(IExcelVerifyHandler verifyHandler) { - this.verifyHandler = verifyHandler; - } - - public int getLastOfInvalidRow() { - return lastOfInvalidRow; - } - - public void setLastOfInvalidRow(int lastOfInvalidRow) { - this.lastOfInvalidRow = lastOfInvalidRow; - } - - public int getStartSheetIndex() { - return startSheetIndex; - } - - public void setStartSheetIndex(int startSheetIndex) { - this.startSheetIndex = startSheetIndex; - } - - public boolean isNeedVerify() { - return needVerify; - } - - public void setNeedVerify(boolean needVerify) { - this.needVerify = needVerify; - } - - public String[] getImportFields() { - return importFields; - } - - public void setImportFields(String[] importFields) { - this.importFields = importFields; - } - - public int getReadRows() { - return readRows; - } - - public void setReadRows(int readRows) { - this.readRows = readRows; - } - - public Integer getKeyIndex() { - return keyIndex; - } - - public String getKeyMark() { - return keyMark; - } - - public void setKeyMark(String keyMark) { - this.keyMark = keyMark; - } - - public boolean isReadSingleCell() { - return readSingleCell; - } - - public void setReadSingleCell(boolean readSingleCell) { - this.readSingleCell = readSingleCell; - } - - public Class[] getVerifyGroup() { - return verifyGroup; - } - - public void setVerifyGroup(Class[] verifyGroup) { - this.verifyGroup = verifyGroup; - } - - public boolean isNeedCheckOrder() { - return needCheckOrder; - } - - public void setNeedCheckOrder(boolean needCheckOrder) { - this.needCheckOrder = needCheckOrder; - } - - public boolean isConcurrentTask() { - return concurrentTask; - } - - public void setConcurrentTask(boolean concurrentTask) { - this.concurrentTask = concurrentTask; - } - - public Integer getCritical() { - return critical; - } - - public void setCritical(Integer critical) { - this.critical = critical; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/TemplateExportParams.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/TemplateExportParams.java index b7cf527..ebe5391 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/TemplateExportParams.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/TemplateExportParams.java @@ -16,6 +16,7 @@ package cn.afterturn.easypoi.excel.entity; import cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerDefaultImpl; +import lombok.Data; import org.apache.poi.ss.usermodel.Workbook; import java.io.InputStream; @@ -27,6 +28,7 @@ import java.io.InputStream; * 2013-10-17 * @version 1.0 */ +@Data public class TemplateExportParams extends ExcelBaseParams { /** @@ -128,107 +130,4 @@ public class TemplateExportParams extends ExcelBaseParams { } } - public int getHeadingRows() { - return headingRows; - } - - public int getHeadingStartRow() { - return headingStartRow; - } - - public String[] getSheetName() { - return sheetName; - } - - public Integer[] getSheetNum() { - return sheetNum; - } - - public String getTemplateUrl() { - return templateUrl; - } - - public void setHeadingRows(int headingRows) { - this.headingRows = headingRows; - } - - public void setHeadingStartRow(int headingStartRow) { - this.headingStartRow = headingStartRow; - } - - public void setSheetName(String[] sheetName) { - this.sheetName = sheetName; - } - - public void setSheetName(String sheetName) { - this.sheetName = new String[] { sheetName }; - } - - public void setSheetNum(Integer[] sheetNum) { - this.sheetNum = sheetNum; - } - - public void setSheetNum(Integer sheetNum) { - this.sheetNum = new Integer[] { sheetNum }; - } - - public void setTemplateUrl(String templateUrl) { - this.templateUrl = templateUrl; - } - - public Class getStyle() { - return style; - } - - public void setStyle(Class style) { - this.style = style; - } - - public int getDataSheetNum() { - return dataSheetNum; - } - - public void setDataSheetNum(int dataSheetNum) { - this.dataSheetNum = dataSheetNum; - } - - public boolean isScanAllsheet() { - return scanAllsheet; - } - - public void setScanAllsheet(boolean scanAllsheet) { - this.scanAllsheet = scanAllsheet; - } - - public String getTempParams() { - return tempParams; - } - - public void setTempParams(String tempParams) { - this.tempParams = tempParams; - } - - public boolean isColForEach() { - return colForEach; - } - - public void setColForEach(boolean colForEach) { - this.colForEach = colForEach; - } - - public void setTemplateWb(Workbook templateWb) { - this.templateWb = templateWb; - } - - public Workbook getTemplateWb() { - return templateWb; - } - - public boolean isReadonly() { - return readonly; - } - - public void setReadonly(boolean readonly) { - this.readonly = readonly; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/TemplateSumEntity.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/TemplateSumEntity.java index f00e1dc..e823e90 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/TemplateSumEntity.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/TemplateSumEntity.java @@ -1,10 +1,13 @@ package cn.afterturn.easypoi.excel.entity; +import lombok.Data; + /** * 统计对象 * * @author JueYue */ +@Data public class TemplateSumEntity { /** @@ -28,45 +31,4 @@ public class TemplateSumEntity { */ private double value; - public String getCellValue() { - return cellValue; - } - - public void setCellValue(String cellValue) { - this.cellValue = cellValue; - } - - public String getSumKey() { - return sumKey; - } - - public void setSumKey(String sumKey) { - this.sumKey = sumKey; - } - - public int getCol() { - return col; - } - - public void setCol(int col) { - this.col = col; - } - - public int getRow() { - return row; - } - - public void setRow(int row) { - this.row = row; - } - - public double getValue() { - return value; - } - - public void setValue(double value) { - this.value = value; - } - - } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java index 834fc63..60902af 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java @@ -19,12 +19,14 @@ import java.lang.reflect.Method; import java.util.List; import cn.afterturn.easypoi.excel.entity.vo.BaseEntityTypeConstants; +import lombok.Data; /** * Excel 导入导出基础对象类 * @author JueYue * 2014年6月20日 下午2:26:09 */ +@Data public class ExcelBaseEntity { /** * 对应name @@ -73,104 +75,4 @@ public class ExcelBaseEntity { private List methods; - public String getDatabaseFormat() { - return databaseFormat; - } - - public String getFormat() { - return format; - } - - public Method getMethod() { - return method; - } - - public List getMethods() { - return methods; - } - - public String getName() { - return name; - } - - public String[] getReplace() { - return replace; - } - - public int getType() { - return type; - } - - public void setDatabaseFormat(String databaseFormat) { - this.databaseFormat = databaseFormat; - } - - public void setFormat(String format) { - this.format = format; - } - - public void setMethod(Method method) { - this.method = method; - } - - public void setMethods(List methods) { - this.methods = methods; - } - - public void setName(String name) { - this.name = name; - } - - public void setReplace(String[] replace) { - this.replace = replace; - } - - public void setType(int type) { - this.type = type; - } - - public boolean isHyperlink() { - return hyperlink; - } - - - public String getGroupName() { - return groupName; - } - - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public void setHyperlink(boolean hyperlink) { - this.hyperlink = hyperlink; - } - - public int getFixedIndex() { - return fixedIndex; - } - - public void setFixedIndex(int fixedIndex) { - this.fixedIndex = fixedIndex; - } - - public String getDict() { - return dict; - } - - public void setDict(String dict) { - this.dict = dict; - } - - public void setFixedIndex(Integer fixedIndex) { - this.fixedIndex = fixedIndex; - } - - public String getTimezone() { - return timezone; - } - - public void setTimezone(String timezone) { - this.timezone = timezone; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelCollectionParams.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelCollectionParams.java index f791e5d..8dd93a6 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelCollectionParams.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelCollectionParams.java @@ -15,6 +15,8 @@ */ package cn.afterturn.easypoi.excel.entity.params; +import lombok.Data; + import java.util.Map; /** @@ -24,6 +26,7 @@ import java.util.Map; * 2013-9-26 * @version 1.0 */ +@Data public class ExcelCollectionParams { /** @@ -43,35 +46,4 @@ public class ExcelCollectionParams { */ private Map excelParams; - public Map getExcelParams() { - return excelParams; - } - - public String getName() { - return name; - } - - public Class getType() { - return type; - } - - public void setExcelParams(Map excelParams) { - this.excelParams = excelParams; - } - - public void setName(String name) { - this.name = name; - } - - public void setType(Class type) { - this.type = type; - } - - public String getExcelName() { - return excelName; - } - - public void setExcelName(String excelName) { - this.excelName = excelName; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java index 0819ff3..f5db35e 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java @@ -15,6 +15,8 @@ */ package cn.afterturn.easypoi.excel.entity.params; +import lombok.Data; + import java.util.List; /** @@ -23,6 +25,7 @@ import java.util.List; * @author JueYue * @version 1.0 2013年8月24日 */ +@Data public class ExcelExportEntity extends ExcelBaseEntity implements Comparable { @@ -102,126 +105,6 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable list; - public int getExportImageType() { - return exportImageType; - } - - public double getHeight() { - return height; - } - - public Object getKey() { - return key; - } - - public List getList() { - return list; - } - - public int[] getMergeRely() { - return mergeRely == null ? new int[0] : mergeRely; - } - - public int getOrderNum() { - return orderNum; - } - - public double getWidth() { - return width; - } - - public boolean isMergeVertical() { - return mergeVertical; - } - - public boolean isNeedMerge() { - return needMerge; - } - - public boolean isWrap() { - return isWrap; - } - - public void setExportImageType(int exportImageType) { - this.exportImageType = exportImageType; - } - - public void setHeight(double height) { - this.height = height; - } - - public void setKey(Object key) { - this.key = key; - } - - public void setList(List list) { - this.list = list; - } - - public void setMergeRely(int[] mergeRely) { - this.mergeRely = mergeRely; - } - - public void setMergeVertical(boolean mergeVertical) { - this.mergeVertical = mergeVertical; - } - - public void setNeedMerge(boolean needMerge) { - this.needMerge = needMerge; - } - - public void setOrderNum(int orderNum) { - this.orderNum = orderNum; - } - - public void setWidth(double width) { - this.width = width; - } - - public void setWrap(boolean isWrap) { - this.isWrap = isWrap; - } - - public String getSuffix() { - return suffix; - } - - public void setSuffix(String suffix) { - this.suffix = suffix; - } - - public boolean isStatistics() { - return isStatistics; - } - - public void setStatistics(boolean isStatistics) { - this.isStatistics = isStatistics; - } - - public String getNumFormat() { - return numFormat; - } - - public void setNumFormat(String numFormat) { - this.numFormat = numFormat; - } - - public String getEnumExportField() { - return enumExportField; - } - - public void setEnumExportField(String enumExportField) { - this.enumExportField = enumExportField; - } - - public boolean isColumnHidden() { - return isColumnHidden; - } - - public void setColumnHidden(boolean columnHidden) { - isColumnHidden = columnHidden; - } - @Override public int compareTo(ExcelExportEntity prev) { return this.getOrderNum() - prev.getOrderNum(); diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelForEachParams.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelForEachParams.java index c948042..b47c9ef 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelForEachParams.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelForEachParams.java @@ -1,5 +1,6 @@ package cn.afterturn.easypoi.excel.entity.params; +import lombok.Data; import org.apache.poi.ss.usermodel.CellStyle; import java.io.Serializable; @@ -11,6 +12,7 @@ import java.util.Stack; * @author JueYue * 2015年4月29日 下午9:22:48 */ +@Data public class ExcelForEachParams implements Serializable { /** @@ -70,75 +72,4 @@ public class ExcelForEachParams implements Serializable { } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public CellStyle getCellStyle() { - return cellStyle; - } - - public void setCellStyle(CellStyle cellStyle) { - this.cellStyle = cellStyle; - } - - public short getHeight() { - return height; - } - - public void setHeight(short height) { - this.height = height; - } - - public String getConstValue() { - return constValue; - } - - public void setConstValue(String constValue) { - this.constValue = constValue; - } - - public int getColspan() { - return colspan; - } - - public void setColspan(int colspan) { - this.colspan = colspan; - } - - public int getRowspan() { - return rowspan; - } - - public void setRowspan(int rowspan) { - this.rowspan = rowspan; - } - - public boolean isNeedSum() { - return needSum; - } - - public void setNeedSum(boolean needSum) { - this.needSum = needSum; - } - - public Stack getTempName() { - return tempName; - } - - public void setTempName(Stack tempName) { - this.tempName = tempName; - } - - public boolean isCollectCell() { - return collectCell; - } - - public void setCollectCell(boolean collectCell) { - this.collectCell = collectCell; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelImportEntity.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelImportEntity.java index 57a10c8..4450069 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelImportEntity.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelImportEntity.java @@ -15,6 +15,8 @@ */ package cn.afterturn.easypoi.excel.entity.params; +import lombok.Data; + import java.util.List; /** @@ -22,6 +24,7 @@ import java.util.List; * @author JueYue * @version 1.0 2013年8月24日 */ +@Data public class ExcelImportEntity extends ExcelBaseEntity { public final static String IMG_SAVE_PATH = "/excel/upload/img"; @@ -57,67 +60,4 @@ public class ExcelImportEntity extends ExcelBaseEntity { private List list; - public String getClassType() { - return classType; - } - - public String getCollectionName() { - return collectionName; - } - - public List getList() { - return list; - } - - public int getSaveType() { - return saveType; - } - - public String getSaveUrl() { - return saveUrl; - } - - public void setClassType(String classType) { - this.classType = classType; - } - - public void setCollectionName(String collectionName) { - this.collectionName = collectionName; - } - - public void setList(List list) { - this.list = list; - } - - public void setSaveType(int saveType) { - this.saveType = saveType; - } - - public void setSaveUrl(String saveUrl) { - this.saveUrl = saveUrl; - } - - public String getSuffix() { - return suffix; - } - - public void setSuffix(String suffix) { - this.suffix = suffix; - } - - public boolean isImportField() { - return importField; - } - - public void setImportField(boolean importField) { - this.importField = importField; - } - - public String getEnumImportMethod() { - return enumImportMethod; - } - - public void setEnumImportMethod(String enumImportMethod) { - this.enumImportMethod = enumImportMethod; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/MergeEntity.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/MergeEntity.java index 2ae3216..f9cf3b0 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/MergeEntity.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/MergeEntity.java @@ -15,6 +15,8 @@ */ package cn.afterturn.easypoi.excel.entity.params; +import lombok.Data; + import java.util.List; /** @@ -22,6 +24,7 @@ import java.util.List; * * Created by jue on 14-6-11. */ +@Data public class MergeEntity { /** * 合并开始行 @@ -50,35 +53,4 @@ public class MergeEntity { this.startRow = startRow; } - public int getEndRow() { - return endRow; - } - - public List getRelyList() { - return relyList; - } - - public int getStartRow() { - return startRow; - } - - public String getText() { - return text; - } - - public void setEndRow(int endRow) { - this.endRow = endRow; - } - - public void setRelyList(List relyList) { - this.relyList = relyList; - } - - public void setStartRow(int startRow) { - this.startRow = startRow; - } - - public void setText(String text) { - this.text = text; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/result/ExcelImportResult.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/result/ExcelImportResult.java index 0eb4d80..f393388 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/result/ExcelImportResult.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/result/ExcelImportResult.java @@ -18,6 +18,7 @@ package cn.afterturn.easypoi.excel.entity.result; import java.util.List; import java.util.Map; +import lombok.Data; import org.apache.poi.ss.usermodel.Workbook; /** @@ -26,6 +27,7 @@ import org.apache.poi.ss.usermodel.Workbook; * @author JueYue * 2014年6月29日 下午5:12:10 */ +@Data public class ExcelImportResult { /** @@ -63,51 +65,4 @@ public class ExcelImportResult { this.workbook = workbook; } - public List getList() { - return list; - } - - public Workbook getWorkbook() { - return workbook; - } - - public boolean isVerfiyFail() { - return verfiyFail; - } - - public void setList(List list) { - this.list = list; - } - - public void setVerfiyFail(boolean verfiyFail) { - this.verfiyFail = verfiyFail; - } - - public void setWorkbook(Workbook workbook) { - this.workbook = workbook; - } - - public Map getMap() { - return map; - } - - public void setMap(Map map) { - this.map = map; - } - - public Workbook getFailWorkbook() { - return failWorkbook; - } - - public void setFailWorkbook(Workbook failWorkbook) { - this.failWorkbook = failWorkbook; - } - - public List getFailList() { - return failList; - } - - public void setFailList(List failList) { - this.failList = failList; - } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/result/ExcelVerifyHandlerResult.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/result/ExcelVerifyHandlerResult.java index ef67858..58599bb 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/result/ExcelVerifyHandlerResult.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/result/ExcelVerifyHandlerResult.java @@ -15,12 +15,15 @@ */ package cn.afterturn.easypoi.excel.entity.result; +import lombok.Data; + /** * Excel导入处理返回结果 * * @author JueYue * 2014年6月23日 下午11:03:29 */ +@Data public class ExcelVerifyHandlerResult { /** * 是否正确 @@ -44,20 +47,4 @@ public class ExcelVerifyHandlerResult { this.msg = msg; } - public String getMsg() { - return msg; - } - - public boolean isSuccess() { - return success; - } - - public void setMsg(String msg) { - this.msg = msg; - } - - public void setSuccess(boolean success) { - this.success = success; - } - } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/sax/SaxConstant.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/sax/SaxConstant.java index 5d2056b..fcec65b 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/sax/SaxConstant.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/sax/SaxConstant.java @@ -9,6 +9,10 @@ public interface SaxConstant { * Row 表达式 */ public static String ROW = "row"; + /** + * cell 的位置 + */ + public static String ROW_COL = "r"; /** * cell 表达式 */ diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/sax/SaxReadCellEntity.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/sax/SaxReadCellEntity.java index 87f8f88..3d81f0a 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/sax/SaxReadCellEntity.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/sax/SaxReadCellEntity.java @@ -16,12 +16,14 @@ package cn.afterturn.easypoi.excel.entity.sax; import cn.afterturn.easypoi.excel.entity.enmus.CellValueType; +import lombok.Data; /** * Cell 对象 * @author JueYue * 2014年12月29日 下午10:12:57 */ +@Data public class SaxReadCellEntity { /** * 值类型 @@ -37,22 +39,6 @@ public class SaxReadCellEntity { this.value = value; } - public CellValueType getCellType() { - return cellType; - } - - public void setCellType(CellValueType cellType) { - this.cellType = cellType; - } - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - this.value = value; - } - @Override public String toString() { return "[type=" + cellType.toString() + ",value=" + value + "]"; diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java index 2af12ea..2ff9a38 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java @@ -66,13 +66,13 @@ public class ExcelExportService extends BaseExportService { List excelParams, int cellIndex) { Row row = sheet.getRow(index) == null ? sheet.createRow(index) : sheet.getRow(index); int rows = getRowNums(excelParams, true); - row.setHeight(title.getHeaderHeight()); + row.setHeight((short)title.getHeaderHeight()); Row listRow = null; if (rows >= 2) { listRow = sheet.getRow(index + 1); if (listRow == null) { listRow = sheet.createRow(index + 1); - listRow.setHeight(title.getHeaderHeight()); + listRow.setHeight((short)(short)title.getHeaderHeight()); } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportService.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportService.java index 313ec44..64004cf 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportService.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportService.java @@ -21,7 +21,6 @@ import cn.afterturn.easypoi.excel.entity.vo.PoiBaseConstants; import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler; import cn.afterturn.easypoi.exception.excel.ExcelExportException; import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum; -import cn.afterturn.easypoi.handler.inter.IExcelExportServer; import cn.afterturn.easypoi.util.PoiExcelGraphDataUtil; import cn.afterturn.easypoi.util.PoiMergeCellUtil; import cn.afterturn.easypoi.util.PoiPublicUtil; @@ -69,15 +68,16 @@ public abstract class BaseExportService extends ExportCommonService { int maxHeight = 1, listMaxHeight = 1; // 合并需要合并的单元格 int margeCellNum = cellNum; - int indexKey = 0; - if (excelParams != null && !excelParams.isEmpty()){ + int indexKey = 0; + if (excelParams != null && !excelParams.isEmpty()) { indexKey = createIndexCell(row, index, excelParams.get(0)); } cellNum += indexKey; for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k); + //不论数据是否为空都应该把该列的数据跳过去 if (entity.getList() != null) { - Collection list = getListCellValue(entity, t); + Collection list = getListCellValue(entity, t); int tmpListHeight = 0; if (list != null && list.size() > 0) { int tempCellNum = 0; @@ -88,6 +88,8 @@ public abstract class BaseExportService extends ExportCommonService { } cellNum = tempCellNum; listMaxHeight = Math.max(listMaxHeight, tmpListHeight); + } else { + cellNum = cellNum + getListCellSize(entity.getList()); } } else { Object value = getCellValue(entity, t); @@ -123,7 +125,7 @@ public abstract class BaseExportService extends ExportCommonService { margeCellNum += entity.getList().size(); } else if (entity.isNeedMerge() && maxHeight > 1) { for (int i = index + 1; i < index + maxHeight; i++) { - if(sheet.getRow(i) == null ) { + if (sheet.getRow(i) == null) { sheet.createRow(i); } sheet.getRow(i).createCell(margeCellNum); @@ -142,6 +144,24 @@ public abstract class BaseExportService extends ExportCommonService { } + /** + * 获取集合的宽度 + * + * @param list + * @return + */ + protected int getListCellSize(List list) { + int cellSize = 0; + for (ExcelExportEntity ee : list) { + if (ee.getList() != null) { + cellSize += getListCellSize(ee.getList()); + } else { + cellSize++; + } + } + return cellSize; + } + /** * 图片类型的Cell */ diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java index 09014bd..9e507c0 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java @@ -26,7 +26,6 @@ import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum; import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; import cn.afterturn.easypoi.handler.inter.IExcelDictHandler; import cn.afterturn.easypoi.handler.inter.IExcelI18nHandler; -import cn.afterturn.easypoi.util.PoiElUtil; import cn.afterturn.easypoi.util.PoiPublicUtil; import cn.afterturn.easypoi.util.PoiReflectorUtil; import org.apache.commons.lang3.StringUtils; @@ -40,10 +39,7 @@ import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.text.DecimalFormat; import java.text.SimpleDateFormat; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; +import java.time.*; import java.util.*; /** @@ -68,7 +64,7 @@ public class ExportCommonService { private ExcelExportEntity createExcelExportEntity(Field field, String targetId, Class pojoClass, List getMethods, ExcelEntity excelGroup) throws Exception { - Excel excel = field.getAnnotation(Excel.class); + Excel excel = field.getAnnotation(Excel.class); ExcelExportEntity excelEntity = new ExcelExportEntity(); excelEntity.setType(excel.type()); getExcelField(targetId, field, excelEntity, excel, pojoClass, excelGroup); @@ -89,15 +85,21 @@ public class ExportCommonService { } else if (value instanceof Date) { temp = (Date) value; } else if (value instanceof Instant) { - Instant instant = (Instant)value; + Instant instant = (Instant) value; temp = Date.from(instant); - } else if (value instanceof LocalDate) { - LocalDate localDate = (LocalDate)value; + } else if (value instanceof LocalDate) { + LocalDate localDate = (LocalDate) value; temp = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } else if(value instanceof LocalDateTime){ - LocalDateTime localDateTime = (LocalDateTime)value; + } else if (value instanceof LocalDateTime) { + LocalDateTime localDateTime = (LocalDateTime) value; temp = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); - } else if(value instanceof java.sql.Date) { + } else if (value instanceof ZonedDateTime) { + ZonedDateTime zonedDateTime = (ZonedDateTime) value; + temp = Date.from(zonedDateTime.toInstant()); + } else if (value instanceof OffsetDateTime) { + OffsetDateTime offsetDateTime = (OffsetDateTime) value; + temp = Date.from(offsetDateTime.toInstant()); + } else if (value instanceof java.sql.Date) { temp = new Date(((java.sql.Date) value).getTime()); } else if (value instanceof java.sql.Time) { temp = new Date(((java.sql.Time) value).getTime()); @@ -106,7 +108,7 @@ public class ExportCommonService { } if (temp != null) { SimpleDateFormat format = new SimpleDateFormat(entity.getFormat()); - if(StringUtils.isNotEmpty(entity.getTimezone())){ + if (StringUtils.isNotEmpty(entity.getTimezone())) { format.setTimeZone(TimeZone.getTimeZone(entity.getTimezone())); } value = format.format(temp); @@ -123,7 +125,7 @@ public class ExportCommonService { LOGGER.error("data want num format ,but is not num, value is:" + value); return null; } - Double d = Double.parseDouble(value.toString()); + Double d = Double.parseDouble(value.toString()); DecimalFormat df = new DecimalFormat(entity.getNumFormat()); return df.format(d); } @@ -136,7 +138,7 @@ public class ExportCommonService { public void getAllExcelField(String[] exclusions, String targetId, Field[] fields, List excelParams, Class pojoClass, List getMethods, ExcelEntity excelGroup) throws Exception { - List exclusionsList = exclusions != null ? Arrays.asList(exclusions) : null; + List exclusionsList = exclusions != null ? Arrays.asList(exclusions) : null; ExcelExportEntity excelEntity; // 遍历整个filed for (int i = 0; i < fields.length; i++) { @@ -147,16 +149,16 @@ public class ExportCommonService { } // 首先判断Excel 可能一下特殊数据用户回自定义处理 if (field.getAnnotation(Excel.class) != null) { - Excel excel = field.getAnnotation(Excel.class); - String name = PoiPublicUtil.getValueByTargetId(excel.name(), targetId, null); + Excel excel = field.getAnnotation(Excel.class); + String name = PoiPublicUtil.getValueByTargetId(excel.name(), targetId, null); if (StringUtils.isNotBlank(name)) { excelParams.add(createExcelExportEntity(field, targetId, pojoClass, getMethods, excelGroup)); } } else if (PoiPublicUtil.isCollection(field.getType())) { - ExcelCollection excel = field.getAnnotation(ExcelCollection.class); - ParameterizedType pt = (ParameterizedType) field.getGenericType(); - Class clz = (Class) pt.getActualTypeArguments()[0]; - List list = new ArrayList(); + ExcelCollection excel = field.getAnnotation(ExcelCollection.class); + ParameterizedType pt = (ParameterizedType) field.getGenericType(); + Class clz = (Class) pt.getActualTypeArguments()[0]; + List list = new ArrayList(); getAllExcelField(exclusions, StringUtils.isNotEmpty(excel.id()) ? excel.id() : targetId, PoiPublicUtil.getClassFields(clz), list, clz, null, null); @@ -199,8 +201,8 @@ public class ExportCommonService { value = ((Map) obj).get(entity.getKey()); } else { // 考虑直接用对象导出只能每次获取值的办法 - if(entity.getMethods() == null && entity.getMethod() == null){ - value = PoiPublicUtil.getParamsValue(entity.getKey().toString(),obj); + if (entity.getMethods() == null && entity.getMethod() == null) { + value = PoiPublicUtil.getParamsValue(entity.getKey().toString(), obj); } else { value = entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj) : entity.getMethod().invoke(obj, new Object[]{}); @@ -353,8 +355,8 @@ public class ExportCommonService { Map.Entry> entry = (Map.Entry) it.next(); Collections.sort(entry.getValue()); // 插入到excelParams当中 - boolean isInsert = false; - String groupName = "START"; + boolean isInsert = false; + String groupName = "START"; for (int i = 0; i < excelParams.size(); i++) { // 跳过groupName 的元素,防止破会内部结构 if (excelParams.get(i).getOrderNum() > entry.getValue().get(0).getOrderNum() @@ -410,11 +412,11 @@ public class ExportCommonService { /** * 判断表头是只有一行还是多行 */ - public int getRowNums(List excelParams,boolean isDeep) { + public int getRowNums(List excelParams, boolean isDeep) { for (int i = 0; i < excelParams.size(); i++) { if (excelParams.get(i).getList() != null && StringUtils.isNotBlank(excelParams.get(i).getName())) { - return isDeep? 1 + getRowNums(excelParams.get(i).getList() , isDeep) : 2; + return isDeep ? 1 + getRowNums(excelParams.get(i).getList(), isDeep) : 2; } if (StringUtils.isNotEmpty(excelParams.get(i).getGroupName())) { return 2; diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/CellValueService.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/CellValueService.java index f989e8f..279445f 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/CellValueService.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/CellValueService.java @@ -99,7 +99,11 @@ public class CellValueService { result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); } else if (("class java.time.LocalDateTime").equals(classFullName)) { result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); - } else if (("class java.sql.Date").equals(classFullName)) { + } else if (("class java.time.OffsetDateTime").equals(classFullName)) { + result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime(); + } else if (("class java.time.ZonedDateTime").equals(classFullName)) { + result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()); + } else if (("class java.sql.Date").equals(classFullName)) { result = new java.sql.Date(((Date) result).getTime()); } else if (("class java.sql.Time").equals(classFullName)) { result = new Time(((Date) result).getTime()); diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/SheetHandler.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/SheetHandler.java index 57e4544..a9c48cd 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/SheetHandler.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/SheetHandler.java @@ -45,12 +45,17 @@ public class SheetHandler extends DefaultHandler { private StylesTable stylesTable; private String lastContents; - /** 当前行**/ + /** + * 当前行 + **/ private int curRow = 0; - /**当前列 **/ + /** + * 当前列 + **/ private int curCol = 0; private CellValueType type; + private String currentLocation, prevLocation; private ISaxRowRead read; @@ -69,6 +74,8 @@ public class SheetHandler extends DefaultHandler { lastContents = ""; if (COL.equals(name)) { String cellType = attributes.getValue(TYPE); + prevLocation = currentLocation; + currentLocation = attributes.getValue(ROW_COL); if (STRING.equals(cellType)) { type = CellValueType.String; return; @@ -128,7 +135,10 @@ public class SheetHandler extends DefaultHandler { } catch (Exception e) { } } - //t元素也包含字符串 + if (VALUE.equals(name) && StringUtils.isNotEmpty(prevLocation)) { + addNullCell(prevLocation, currentLocation); + } + //t元素也包含字符串 if (CellValueType.TElement.equals(type)) { String value = lastContents.trim(); rowList.add(curCol, new SaxReadCellEntity(CellValueType.String, value)); @@ -162,6 +172,50 @@ public class SheetHandler extends DefaultHandler { } + private void addNullCell(String prevLocation, String currentLocation) { + // 拆分行和列 + String[] prev = getRowCell(prevLocation); + String[] current = getRowCell(currentLocation); + if (prev[1].equalsIgnoreCase(current[1])) { + int prevCell = getCellNum(prev[0]) + 1; + int currentCell = getCellNum(current[0]); + for (int i = prevCell; i < currentCell; i++) { + rowList.add(curCol, new SaxReadCellEntity(CellValueType.String, "")); + curCol++; + } + } + } + + private int getCellNum(String cell) { + if (StringUtils.isEmpty(cell)) { + return 0; + } + char[] chars = cell.toUpperCase().toCharArray(); + int n = 0; + for (int i = cell.length() - 1, j = 1; i >= 0; i--, j *= 26) { + char c = (chars[i]); + if (c < 'A' || c > 'Z') { + return 0; + } + n += ((int) c - 64) * j; + } + return n; + } + + private String[] getRowCell(String prevLocation) { + StringBuilder row = new StringBuilder(); + StringBuilder cell = new StringBuilder(); + char[] chars = prevLocation.toCharArray(); + for (int i = 0; i < chars.length; i++) { + if (chars[i] >= '0' && chars[i] <= '9') { + cell.append(chars[i]); + } else { + row.append(chars[i]); + } + } + return new String[]{row.toString(), cell.toString()}; + } + @Override public void characters(char[] ch, int start, int length) throws SAXException { //得到单元格内容的值 diff --git a/pom.xml b/pom.xml index 49b4fda..90786f7 100644 --- a/pom.xml +++ b/pom.xml @@ -204,6 +204,13 @@ 3.2.6 + + org.projectlombok + lombok + 1.16.20 + provided + + cn.afterturn