mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
Merge remote-tracking branch 'upstream/v5-dev' into v5-dev
This commit is contained in:
commit
f551585cb4
@ -3,14 +3,16 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.5.3 (2020-12-02)
|
# 5.5.3 (2020-12-05)
|
||||||
|
|
||||||
### 新特性
|
### 新特性
|
||||||
* 【core 】 IdcardUtil增加行政区划83(issue#1277@Github)
|
* 【core 】 IdcardUtil增加行政区划83(issue#1277@Github)
|
||||||
* 【core 】 multipart中int改为long,解决大文件上传越界问题(issue#I27WZ3@Gitee)
|
* 【core 】 multipart中int改为long,解决大文件上传越界问题(issue#I27WZ3@Gitee)
|
||||||
|
* 【core 】 ListUtil.page增加检查(pr#224@Gitee)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【cache 】 修复Cache中get重复misCount计数问题(issue#1281@Github)
|
* 【cache 】 修复Cache中get重复misCount计数问题(issue#1281@Github)
|
||||||
|
* 【poi 】 修复sax读取自定义格式单元格无法识别日期类型的问题(issue#1283@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ public class ListUtil {
|
|||||||
int resultSize = list.size();
|
int resultSize = list.size();
|
||||||
// 每页条目数大于总数直接返回所有
|
// 每页条目数大于总数直接返回所有
|
||||||
if (resultSize <= pageSize) {
|
if (resultSize <= pageSize) {
|
||||||
if (pageNo < (PageUtil.getFirstPageNo()+1)) {
|
if (pageNo < (PageUtil.getFirstPageNo() + 1)) {
|
||||||
return Collections.unmodifiableList(list);
|
return Collections.unmodifiableList(list);
|
||||||
} else {
|
} else {
|
||||||
// 越界直接返回空
|
// 越界直接返回空
|
||||||
@ -253,7 +253,7 @@ public class ListUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 相乘可能会导致越界 临时用long
|
// 相乘可能会导致越界 临时用long
|
||||||
if (((long) (pageNo-PageUtil.getFirstPageNo()) * pageSize) > resultSize) {
|
if (((long) (pageNo - PageUtil.getFirstPageNo()) * pageSize) > resultSize) {
|
||||||
// 越界直接返回空
|
// 越界直接返回空
|
||||||
return new ArrayList<>(0);
|
return new ArrayList<>(0);
|
||||||
}
|
}
|
||||||
@ -261,6 +261,9 @@ public class ListUtil {
|
|||||||
final int[] startEnd = PageUtil.transToStartEnd(pageNo, pageSize);
|
final int[] startEnd = PageUtil.transToStartEnd(pageNo, pageSize);
|
||||||
if (startEnd[1] > resultSize) {
|
if (startEnd[1] > resultSize) {
|
||||||
startEnd[1] = resultSize;
|
startEnd[1] = resultSize;
|
||||||
|
if (startEnd[0] > startEnd[1]) {
|
||||||
|
return empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list.subList(startEnd[0], startEnd[1]);
|
return list.subList(startEnd[0], startEnd[1]);
|
||||||
|
@ -1516,7 +1516,7 @@ public class NumberUtil {
|
|||||||
*/
|
*/
|
||||||
public static int processMultiple(int selectNum, int minNum) {
|
public static int processMultiple(int selectNum, int minNum) {
|
||||||
int result;
|
int result;
|
||||||
result = mathSubnode(selectNum, minNum) / mathNode(selectNum - minNum);
|
result = mathSubNode(selectNum, minNum) / mathNode(selectNum - minNum);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2494,11 +2494,11 @@ public class NumberUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------- Private method start
|
// ------------------------------------------------------------------------------------------- Private method start
|
||||||
private static int mathSubnode(int selectNum, int minNum) {
|
private static int mathSubNode(int selectNum, int minNum) {
|
||||||
if (selectNum == minNum) {
|
if (selectNum == minNum) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return selectNum * mathSubnode(selectNum - 1, minNum);
|
return selectNum * mathSubNode(selectNum - 1, minNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,4 +187,12 @@ public class ValidatorTest {
|
|||||||
zipCode = Validator.isZipCode("102629");
|
zipCode = Validator.isZipCode("102629");
|
||||||
Assert.assertTrue(zipCode);
|
Assert.assertTrue(zipCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isBetweenTest() {
|
||||||
|
Assert.assertTrue(Validator.isBetween(0, 0, 1));
|
||||||
|
Assert.assertTrue(Validator.isBetween(1L, 0L, 1L));
|
||||||
|
Assert.assertTrue(Validator.isBetween(0.19f, 0.1f, 0.2f));
|
||||||
|
Assert.assertTrue(Validator.isBetween(0.19, 0.1, 0.2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ public class Excel03SaxReader implements HSSFListener, ExcelSaxReader<Excel03Sax
|
|||||||
break;
|
break;
|
||||||
case FormulaRecord.sid:
|
case FormulaRecord.sid:
|
||||||
// 公式类型
|
// 公式类型
|
||||||
FormulaRecord formulaRec = (FormulaRecord) record;
|
final FormulaRecord formulaRec = (FormulaRecord) record;
|
||||||
if (isOutputFormulaValues) {
|
if (isOutputFormulaValues) {
|
||||||
if (Double.isNaN(formulaRec.getValue())) {
|
if (Double.isNaN(formulaRec.getValue())) {
|
||||||
// Formula result is a string
|
// Formula result is a string
|
||||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.io.IORuntimeException;
|
|||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.text.StrBuilder;
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.poi.excel.cell.FormulaCellValue;
|
import cn.hutool.poi.excel.cell.FormulaCellValue;
|
||||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||||
@ -410,21 +411,20 @@ public class Excel07SaxReader extends DefaultHandler implements ExcelSaxReader<E
|
|||||||
*/
|
*/
|
||||||
private void setCellType(Attributes attributes) {
|
private void setCellType(Attributes attributes) {
|
||||||
// numFmtString的值
|
// numFmtString的值
|
||||||
numFmtString = "";
|
numFmtString = StrUtil.EMPTY;
|
||||||
this.cellDataType = CellDataType.of(AttributeName.t.getValue(attributes));
|
this.cellDataType = CellDataType.of(AttributeName.t.getValue(attributes));
|
||||||
|
|
||||||
// 获取单元格的xf索引,对应style.xml中cellXfs的子元素xf
|
// 获取单元格的xf索引,对应style.xml中cellXfs的子元素xf
|
||||||
if (null != this.stylesTable) {
|
if (null != this.stylesTable) {
|
||||||
final String xfIndexStr = AttributeName.s.getValue(attributes);
|
final String xfIndexStr = AttributeName.s.getValue(attributes);
|
||||||
if (null != xfIndexStr) {
|
if (null != xfIndexStr) {
|
||||||
int xfIndex = Integer.parseInt(xfIndexStr);
|
this.xssfCellStyle = stylesTable.getStyleAt(Integer.parseInt(xfIndexStr));
|
||||||
this.xssfCellStyle = stylesTable.getStyleAt(xfIndex);
|
|
||||||
numFmtString = xssfCellStyle.getDataFormatString();
|
|
||||||
// 单元格存储格式的索引,对应style.xml中的numFmts元素的子元素索引
|
// 单元格存储格式的索引,对应style.xml中的numFmts元素的子元素索引
|
||||||
int numFmtIndex = xssfCellStyle.getDataFormat();
|
final int numFmtIndex = xssfCellStyle.getDataFormat();
|
||||||
if (numFmtString == null) {
|
this.numFmtString = ObjectUtil.defaultIfNull(
|
||||||
numFmtString = BuiltinFormats.getBuiltinFormat(numFmtIndex);
|
xssfCellStyle.getDataFormatString(),
|
||||||
} else if (CellDataType.NUMBER == this.cellDataType && org.apache.poi.ss.usermodel.DateUtil.isADateFormat(numFmtIndex, numFmtString)) {
|
BuiltinFormats.getBuiltinFormat(numFmtIndex));
|
||||||
|
if (CellDataType.NUMBER == this.cellDataType && ExcelSaxUtil.isDateFormat(numFmtIndex, numFmtString)) {
|
||||||
cellDataType = CellDataType.DATE;
|
cellDataType = CellDataType.DATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.exceptions.DependencyException;
|
import cn.hutool.core.exceptions.DependencyException;
|
||||||
import cn.hutool.core.io.IORuntimeException;
|
import cn.hutool.core.io.IORuntimeException;
|
||||||
|
import cn.hutool.core.util.CharUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||||
import cn.hutool.poi.exceptions.POIException;
|
import cn.hutool.poi.exceptions.POIException;
|
||||||
@ -34,6 +35,20 @@ public class ExcelSaxUtil {
|
|||||||
// 列的最大位数
|
// 列的最大位数
|
||||||
public static final int MAX_CELL_BIT = 3;
|
public static final int MAX_CELL_BIT = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 {@link ExcelSaxReader}
|
||||||
|
*
|
||||||
|
* @param isXlsx 是否为xlsx格式(07格式)
|
||||||
|
* @param rowHandler 行处理器
|
||||||
|
* @return {@link ExcelSaxReader}
|
||||||
|
* @since 5.4.4
|
||||||
|
*/
|
||||||
|
public static ExcelSaxReader<?> createSaxReader(boolean isXlsx, RowHandler rowHandler) {
|
||||||
|
return isXlsx
|
||||||
|
? new Excel07SaxReader(rowHandler)
|
||||||
|
: new Excel03SaxReader(rowHandler);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据数据类型获取数据
|
* 根据数据类型获取数据
|
||||||
*
|
*
|
||||||
@ -175,14 +190,34 @@ public class ExcelSaxUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断数字Record中是否为日期格式
|
* 判断数字Record中是否为日期格式
|
||||||
|
*
|
||||||
* @param cell 单元格记录
|
* @param cell 单元格记录
|
||||||
* @param formatListener {@link FormatTrackingHSSFListener}
|
* @param formatListener {@link FormatTrackingHSSFListener}
|
||||||
* @return 是否为日期格式
|
* @return 是否为日期格式
|
||||||
* @since 5.4.8
|
* @since 5.4.8
|
||||||
*/
|
*/
|
||||||
public static boolean isDateFormat(CellValueRecordInterface cell, FormatTrackingHSSFListener formatListener){
|
public static boolean isDateFormat(CellValueRecordInterface cell, FormatTrackingHSSFListener formatListener) {
|
||||||
final int formatIndex = formatListener.getFormatIndex(cell);
|
final int formatIndex = formatListener.getFormatIndex(cell);
|
||||||
final String formatString = formatListener.getFormatString(cell);
|
final String formatString = formatListener.getFormatString(cell);
|
||||||
|
return isDateFormat(formatIndex, formatString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断日期格式
|
||||||
|
*
|
||||||
|
* @param formatIndex 格式索引,一般用于内建格式
|
||||||
|
* @param formatString 格式字符串
|
||||||
|
* @return 是否为日期格式
|
||||||
|
* @since 5.5.3
|
||||||
|
*/
|
||||||
|
public static boolean isDateFormat(int formatIndex, String formatString) {
|
||||||
|
// https://blog.csdn.net/u014342130/article/details/50619503
|
||||||
|
// issue#1283@Github
|
||||||
|
if (formatIndex == 28 || formatIndex == 31) {
|
||||||
|
// 28 -> m月d日
|
||||||
|
// 31 -> yyyy年m月d日
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return org.apache.poi.ss.usermodel.DateUtil.isADateFormat(formatIndex, formatString);
|
return org.apache.poi.ss.usermodel.DateUtil.isADateFormat(formatIndex, formatString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,43 +243,22 @@ public class ExcelSaxUtil {
|
|||||||
return DateUtil.date(org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value, false));
|
return DateUtil.date(org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建 {@link ExcelSaxReader}
|
|
||||||
*
|
|
||||||
* @param isXlsx 是否为xlsx格式(07格式)
|
|
||||||
* @param rowHandler 行处理器
|
|
||||||
* @return {@link ExcelSaxReader}
|
|
||||||
* @since 5.4.4
|
|
||||||
*/
|
|
||||||
public static ExcelSaxReader<?> createSaxReader(boolean isXlsx, RowHandler rowHandler) {
|
|
||||||
return isXlsx
|
|
||||||
? new Excel07SaxReader(rowHandler)
|
|
||||||
: new Excel03SaxReader(rowHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在Excel03 sax读取中获取日期或数字类型的结果值
|
* 在Excel03 sax读取中获取日期或数字类型的结果值
|
||||||
|
*
|
||||||
* @param cell 记录单元格
|
* @param cell 记录单元格
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param formatListener {@link FormatTrackingHSSFListener}
|
* @param formatListener {@link FormatTrackingHSSFListener}
|
||||||
* @return 值,可能为Date或Double或Long
|
* @return 值,可能为Date或Double或Long
|
||||||
* @since 5.5.0
|
* @since 5.5.0
|
||||||
*/
|
*/
|
||||||
public static Object getNumberOrDateValue(CellValueRecordInterface cell, double value, FormatTrackingHSSFListener formatListener){
|
public static Object getNumberOrDateValue(CellValueRecordInterface cell, double value, FormatTrackingHSSFListener formatListener) {
|
||||||
Object result;
|
Object result;
|
||||||
if(ExcelSaxUtil.isDateFormat(cell, formatListener)){
|
if (isDateFormat(cell, formatListener)) {
|
||||||
// 可能为日期格式
|
// 可能为日期格式
|
||||||
result = ExcelSaxUtil.getDateValue(value);
|
return getDateValue(value);
|
||||||
} else {
|
|
||||||
final long longPart = (long) value;
|
|
||||||
// 对于无小数部分的数字类型,转为Long,否则保留原数字
|
|
||||||
if (((double) longPart) == value) {
|
|
||||||
result = longPart;
|
|
||||||
} else {
|
|
||||||
result = value;
|
|
||||||
}
|
}
|
||||||
}
|
return getNumberValue(value, formatListener.getFormatString(cell));
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -259,9 +273,20 @@ public class ExcelSaxUtil {
|
|||||||
if (StrUtil.isBlank(value)) {
|
if (StrUtil.isBlank(value)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
double numValue = Double.parseDouble(value);
|
return getNumberValue(Double.parseDouble(value), numFmtString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数字类型值,除非格式中明确数字保留小数,否则无小数情况下按照long返回
|
||||||
|
*
|
||||||
|
* @param numValue 值
|
||||||
|
* @param numFmtString 格式
|
||||||
|
* @return 数字,可以是Double、Long
|
||||||
|
* @since 5.5.3
|
||||||
|
*/
|
||||||
|
private static Number getNumberValue(double numValue, String numFmtString) {
|
||||||
// 普通数字
|
// 普通数字
|
||||||
if (null != numFmtString && numFmtString.indexOf(StrUtil.C_DOT) < 0) {
|
if (null != numFmtString && false == StrUtil.contains(numFmtString, CharUtil.DOT)) {
|
||||||
final long longPart = (long) numValue;
|
final long longPart = (long) numValue;
|
||||||
//noinspection RedundantIfStatement
|
//noinspection RedundantIfStatement
|
||||||
if (longPart == numValue) {
|
if (longPart == numValue) {
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
package cn.hutool.poi.excel.test;
|
package cn.hutool.poi.excel;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.poi.excel.BigExcelWriter;
|
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
|
||||||
import cn.hutool.poi.excel.ExcelWriter;
|
|
||||||
import cn.hutool.poi.excel.style.StyleUtil;
|
import cn.hutool.poi.excel.style.StyleUtil;
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||||
@ -163,21 +160,21 @@ public class BigExcelWriteTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void writeBeanTest() {
|
public void writeBeanTest() {
|
||||||
TestBean bean1 = new TestBean();
|
cn.hutool.poi.excel.TestBean bean1 = new cn.hutool.poi.excel.TestBean();
|
||||||
bean1.setName("张三");
|
bean1.setName("张三");
|
||||||
bean1.setAge(22);
|
bean1.setAge(22);
|
||||||
bean1.setPass(true);
|
bean1.setPass(true);
|
||||||
bean1.setScore(66.30);
|
bean1.setScore(66.30);
|
||||||
bean1.setExamDate(DateUtil.date());
|
bean1.setExamDate(DateUtil.date());
|
||||||
|
|
||||||
TestBean bean2 = new TestBean();
|
cn.hutool.poi.excel.TestBean bean2 = new cn.hutool.poi.excel.TestBean();
|
||||||
bean2.setName("李四");
|
bean2.setName("李四");
|
||||||
bean2.setAge(28);
|
bean2.setAge(28);
|
||||||
bean2.setPass(false);
|
bean2.setPass(false);
|
||||||
bean2.setScore(38.50);
|
bean2.setScore(38.50);
|
||||||
bean2.setExamDate(DateUtil.date());
|
bean2.setExamDate(DateUtil.date());
|
||||||
|
|
||||||
List<TestBean> rows = CollUtil.newArrayList(bean1, bean2);
|
List<cn.hutool.poi.excel.TestBean> rows = CollUtil.newArrayList(bean1, bean2);
|
||||||
// 通过工具类创建writer
|
// 通过工具类创建writer
|
||||||
String file = "e:/bigWriteBeanTest.xlsx";
|
String file = "e:/bigWriteBeanTest.xlsx";
|
||||||
FileUtil.del(file);
|
FileUtil.del(file);
|
@ -1,4 +1,4 @@
|
|||||||
package cn.hutool.poi.excel.test;
|
package cn.hutool.poi.excel;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
@ -1,11 +1,9 @@
|
|||||||
package cn.hutool.poi.excel.test;
|
package cn.hutool.poi.excel;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.ResourceUtil;
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
import cn.hutool.core.lang.Console;
|
import cn.hutool.core.lang.Console;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.poi.excel.ExcelReader;
|
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
@ -1,4 +1,4 @@
|
|||||||
package cn.hutool.poi.excel.test;
|
package cn.hutool.poi.excel;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
@ -6,7 +6,6 @@ import cn.hutool.core.io.FileUtil;
|
|||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.lang.Console;
|
import cn.hutool.core.lang.Console;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
|
||||||
import cn.hutool.poi.excel.cell.FormulaCellValue;
|
import cn.hutool.poi.excel.cell.FormulaCellValue;
|
||||||
import cn.hutool.poi.excel.sax.Excel03SaxReader;
|
import cn.hutool.poi.excel.sax.Excel03SaxReader;
|
||||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||||
@ -65,7 +64,7 @@ public class ExcelSaxReadTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void readBySaxTest2() {
|
public void readBySaxTest2() {
|
||||||
ExcelUtil.readBySax("e:/B23_20180404164901240.xlsx", 2, (sheetIndex, rowIndex, rowList) -> Console.log(rowList));
|
ExcelUtil.readBySax("d:/test/default.xlsx", -1, (sheetIndex, rowIndex, rowList) -> Console.log(rowList));
|
||||||
}
|
}
|
||||||
|
|
||||||
private RowHandler createRowHandler() {
|
private RowHandler createRowHandler() {
|
||||||
@ -138,15 +137,33 @@ public class ExcelSaxReadTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dateReadTest() {
|
public void dateReadXlsTest() {
|
||||||
List<String> rows = new ArrayList<>();
|
List<String> rows = new ArrayList<>();
|
||||||
ExcelUtil.readBySax("data_for_sax_test.xls", 0, (i, i1, list) ->
|
ExcelUtil.readBySax("data_for_sax_test.xls", 0,
|
||||||
rows.add(StrUtil.toString(list.get(0))));
|
(i, i1, list) ->{
|
||||||
|
rows.add(StrUtil.toString(list.get(0)));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
Assert.assertEquals("2020-10-09 00:00:00", rows.get(1));
|
Assert.assertEquals("2020-10-09 00:00:00", rows.get(1));
|
||||||
// 非日期格式不做转换
|
// 非日期格式不做转换
|
||||||
Assert.assertEquals("112233", rows.get(2));
|
Assert.assertEquals("112233", rows.get(2));
|
||||||
Assert.assertEquals("1000", rows.get(3));
|
Assert.assertEquals("1000.0", rows.get(3));
|
||||||
|
Assert.assertEquals("2012-12-21 00:00:00", rows.get(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dateReadXlsxTest() {
|
||||||
|
List<String> rows = new ArrayList<>();
|
||||||
|
ExcelUtil.readBySax("data_for_sax_test.xlsx", 0,
|
||||||
|
(i, i1, list) -> rows.add(StrUtil.toString(list.get(0)))
|
||||||
|
);
|
||||||
|
|
||||||
|
Assert.assertEquals("2020-10-09 00:00:00", rows.get(1));
|
||||||
|
// 非日期格式不做转换
|
||||||
|
Assert.assertEquals("112233", rows.get(2));
|
||||||
|
Assert.assertEquals("1000.0", rows.get(3));
|
||||||
|
Assert.assertEquals("2012-12-21 00:00:00", rows.get(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
@ -1,6 +1,5 @@
|
|||||||
package cn.hutool.poi.excel.test;
|
package cn.hutool.poi.excel;
|
||||||
|
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
|
||||||
import cn.hutool.poi.excel.cell.CellLocation;
|
import cn.hutool.poi.excel.cell.CellLocation;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
@ -1,4 +1,4 @@
|
|||||||
package cn.hutool.poi.excel.test;
|
package cn.hutool.poi.excel;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
@ -6,8 +6,6 @@ import cn.hutool.core.io.FileUtil;
|
|||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
|
||||||
import cn.hutool.poi.excel.ExcelWriter;
|
|
||||||
import cn.hutool.poi.excel.style.StyleUtil;
|
import cn.hutool.poi.excel.style.StyleUtil;
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||||
@ -340,21 +338,21 @@ public class ExcelWriteTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void writeBeanTest() {
|
public void writeBeanTest() {
|
||||||
TestBean bean1 = new TestBean();
|
cn.hutool.poi.excel.TestBean bean1 = new cn.hutool.poi.excel.TestBean();
|
||||||
bean1.setName("张三");
|
bean1.setName("张三");
|
||||||
bean1.setAge(22);
|
bean1.setAge(22);
|
||||||
bean1.setPass(true);
|
bean1.setPass(true);
|
||||||
bean1.setScore(66.30);
|
bean1.setScore(66.30);
|
||||||
bean1.setExamDate(DateUtil.date());
|
bean1.setExamDate(DateUtil.date());
|
||||||
|
|
||||||
TestBean bean2 = new TestBean();
|
cn.hutool.poi.excel.TestBean bean2 = new cn.hutool.poi.excel.TestBean();
|
||||||
bean2.setName("李四");
|
bean2.setName("李四");
|
||||||
bean2.setAge(28);
|
bean2.setAge(28);
|
||||||
bean2.setPass(false);
|
bean2.setPass(false);
|
||||||
bean2.setScore(38.50);
|
bean2.setScore(38.50);
|
||||||
bean2.setExamDate(DateUtil.date());
|
bean2.setExamDate(DateUtil.date());
|
||||||
|
|
||||||
List<TestBean> rows = CollUtil.newArrayList(bean1, bean2);
|
List<cn.hutool.poi.excel.TestBean> rows = CollUtil.newArrayList(bean1, bean2);
|
||||||
// 通过工具类创建writer
|
// 通过工具类创建writer
|
||||||
String file = "e:/writeBeanTest.xlsx";
|
String file = "e:/writeBeanTest.xlsx";
|
||||||
FileUtil.del(file);
|
FileUtil.del(file);
|
||||||
@ -376,17 +374,17 @@ public class ExcelWriteTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void writeBeanTest2() {
|
public void writeBeanTest2() {
|
||||||
OrderExcel order1 = new OrderExcel();
|
cn.hutool.poi.excel.OrderExcel order1 = new cn.hutool.poi.excel.OrderExcel();
|
||||||
order1.setId("1");
|
order1.setId("1");
|
||||||
order1.setNum("123");
|
order1.setNum("123");
|
||||||
order1.setBody("body1");
|
order1.setBody("body1");
|
||||||
|
|
||||||
OrderExcel order2 = new OrderExcel();
|
cn.hutool.poi.excel.OrderExcel order2 = new cn.hutool.poi.excel.OrderExcel();
|
||||||
order1.setId("2");
|
order1.setId("2");
|
||||||
order1.setNum("456");
|
order1.setNum("456");
|
||||||
order1.setBody("body2");
|
order1.setBody("body2");
|
||||||
|
|
||||||
List<OrderExcel> rows = CollUtil.newArrayList(order1, order2);
|
List<cn.hutool.poi.excel.OrderExcel> rows = CollUtil.newArrayList(order1, order2);
|
||||||
// 通过工具类创建writer
|
// 通过工具类创建writer
|
||||||
String file = "f:/test/writeBeanTest2.xlsx";
|
String file = "f:/test/writeBeanTest2.xlsx";
|
||||||
FileUtil.del(file);
|
FileUtil.del(file);
|
@ -1,4 +1,4 @@
|
|||||||
package cn.hutool.poi.excel.test;
|
package cn.hutool.poi.excel;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package cn.hutool.poi.excel.test;
|
package cn.hutool.poi.excel;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package cn.hutool.poi.word.test;
|
package cn.hutool.poi.word;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user