mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix date read for sax bug
This commit is contained in:
@@ -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.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
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 org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
@@ -163,21 +160,21 @@ public class BigExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeBeanTest() {
|
||||
TestBean bean1 = new TestBean();
|
||||
cn.hutool.poi.excel.TestBean bean1 = new cn.hutool.poi.excel.TestBean();
|
||||
bean1.setName("张三");
|
||||
bean1.setAge(22);
|
||||
bean1.setPass(true);
|
||||
bean1.setScore(66.30);
|
||||
bean1.setExamDate(DateUtil.date());
|
||||
|
||||
TestBean bean2 = new TestBean();
|
||||
cn.hutool.poi.excel.TestBean bean2 = new cn.hutool.poi.excel.TestBean();
|
||||
bean2.setName("李四");
|
||||
bean2.setAge(28);
|
||||
bean2.setPass(false);
|
||||
bean2.setScore(38.50);
|
||||
bean2.setExamDate(DateUtil.date());
|
||||
|
||||
List<TestBean> rows = CollUtil.newArrayList(bean1, bean2);
|
||||
List<cn.hutool.poi.excel.TestBean> rows = CollUtil.newArrayList(bean1, bean2);
|
||||
// 通过工具类创建writer
|
||||
String file = "e:/bigWriteBeanTest.xlsx";
|
||||
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.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.lang.Console;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
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.convert.Convert;
|
||||
@@ -6,7 +6,6 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.cell.FormulaCellValue;
|
||||
import cn.hutool.poi.excel.sax.Excel03SaxReader;
|
||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||
@@ -138,15 +137,33 @@ public class ExcelSaxReadTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateReadTest() {
|
||||
public void dateReadXlsTest() {
|
||||
List<String> rows = new ArrayList<>();
|
||||
ExcelUtil.readBySax("data_for_sax_test.xls", 0, (i, i1, list) ->
|
||||
rows.add(StrUtil.toString(list.get(0))));
|
||||
ExcelUtil.readBySax("data_for_sax_test.xls", 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", 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
|
||||
|
@@ -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 org.junit.Assert;
|
||||
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.date.DateUtil;
|
||||
@@ -6,8 +6,6 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
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 org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
@@ -340,21 +338,21 @@ public class ExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeBeanTest() {
|
||||
TestBean bean1 = new TestBean();
|
||||
cn.hutool.poi.excel.TestBean bean1 = new cn.hutool.poi.excel.TestBean();
|
||||
bean1.setName("张三");
|
||||
bean1.setAge(22);
|
||||
bean1.setPass(true);
|
||||
bean1.setScore(66.30);
|
||||
bean1.setExamDate(DateUtil.date());
|
||||
|
||||
TestBean bean2 = new TestBean();
|
||||
cn.hutool.poi.excel.TestBean bean2 = new cn.hutool.poi.excel.TestBean();
|
||||
bean2.setName("李四");
|
||||
bean2.setAge(28);
|
||||
bean2.setPass(false);
|
||||
bean2.setScore(38.50);
|
||||
bean2.setExamDate(DateUtil.date());
|
||||
|
||||
List<TestBean> rows = CollUtil.newArrayList(bean1, bean2);
|
||||
List<cn.hutool.poi.excel.TestBean> rows = CollUtil.newArrayList(bean1, bean2);
|
||||
// 通过工具类创建writer
|
||||
String file = "e:/writeBeanTest.xlsx";
|
||||
FileUtil.del(file);
|
||||
@@ -376,17 +374,17 @@ public class ExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeBeanTest2() {
|
||||
OrderExcel order1 = new OrderExcel();
|
||||
cn.hutool.poi.excel.OrderExcel order1 = new cn.hutool.poi.excel.OrderExcel();
|
||||
order1.setId("1");
|
||||
order1.setNum("123");
|
||||
order1.setBody("body1");
|
||||
|
||||
OrderExcel order2 = new OrderExcel();
|
||||
cn.hutool.poi.excel.OrderExcel order2 = new cn.hutool.poi.excel.OrderExcel();
|
||||
order1.setId("2");
|
||||
order1.setNum("456");
|
||||
order1.setBody("body2");
|
||||
|
||||
List<OrderExcel> rows = CollUtil.newArrayList(order1, order2);
|
||||
List<cn.hutool.poi.excel.OrderExcel> rows = CollUtil.newArrayList(order1, order2);
|
||||
// 通过工具类创建writer
|
||||
String file = "f:/test/writeBeanTest2.xlsx";
|
||||
FileUtil.del(file);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package cn.hutool.poi.excel.test;
|
||||
package cn.hutool.poi.excel;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package cn.hutool.poi.excel.test;
|
||||
package cn.hutool.poi.excel;
|
||||
|
||||
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.io.FileUtil;
|
||||
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user