Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决 TV360X-1953、TV360X-1292报错的小问题 #122

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions autopoi-web/src/test/java/ExcelToHtmlTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelToHtmlUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;

public class ExcelToHtmlTest {

private static final String basePath = "D:\\idea_project_2023\\autopoi_lsq\\autopoi-web\\src\\test\\resources\\templates\\";

public static void main(String[] args) throws Exception {
File file = new File(basePath + "专项支出用款申请书.xls");
Workbook wb = new HSSFWorkbook(new FileInputStream(file));
String html = ExcelToHtmlUtil.toTableHtml(wb);
FileWriter fw = new FileWriter("D:/home/excel/专项支出用款申请书.html");
fw.write(html);
fw.close();
}
}
33 changes: 33 additions & 0 deletions autopoi-web/src/test/java/ImportExcelTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @Description: TODO
* @author: scott
* @date: 2020年09月16日 11:46
*/
public class ImportExcelTest {
private static final String basePath = "D:\\idea_project_2023\\autopoi_lsq\\autopoi-web\\src\\test\\resources\\templates\\";

public static void main(String[] args) throws Exception {
ImportParams params = new ImportParams();
params.setTitleRows(1);
params.setHeadRows(1);
File importFile = new File(basePath+"ExcelImportDateTest.xlsx");
List<TestDateEntity> list = ExcelImportUtil.importExcel(importFile, TestDateEntity.class, params);
System.out.println(list.size());
System.out.println(ReflectionToStringBuilder.toString(list.get(1)));
}
}
34 changes: 34 additions & 0 deletions autopoi-web/src/test/java/TestDateEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import org.jeecgframework.poi.excel.annotation.Excel;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
* @Description: TODO
* @author: lsq
* @date: 2024年07月31日 10:31
*/
public class TestDateEntity {
@Excel(name = "localdate", format = "yyyy-MM-dd")
private LocalDate localDate;

@Excel(name = "localdatetime", format = "yyyy-MM-dd")
private LocalDateTime localDateTime;


public LocalDate getLocalDate() {
return localDate;
}

public void setLocalDate(LocalDate localDate) {
this.localDate = localDate;
}

public LocalDateTime getLocalDateTime() {
return localDateTime;
}

public void setLocalDateTime(LocalDateTime localDateTime) {
this.localDateTime = localDateTime;
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ public HSSFHtmlHelper(HSSFWorkbook wb) {

public void colorStyles(CellStyle style, Formatter out) {
HSSFCellStyle cs = (HSSFCellStyle) style;
out.format(" /* fill pattern = %d */%n", cs.getFillPattern());
if (cs.getFillPattern() != FillPatternType.NO_FILL) {
out.format(" /* fill pattern = %s */%n", cs.getFillPattern());
}
styleColor(out, "background-color", cs.getFillForegroundColor());
styleColor(out, "color", colors.getColor(cs.getFont(wb).getColor()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -66,7 +67,10 @@ private Object getCellValue(String xclass, Cell cell, ExcelImportEntity entity)
}
Object result = null;
// 日期格式比较特殊,和cell格式不一致
if ("class java.util.Date".equals(xclass) || ("class java.sql.Time").equals(xclass)) {
if ("class java.util.Date".equals(xclass)
|| ("class java.sql.Time").equals(xclass)
|| ("class java.time.LocalDate").equals(xclass)
|| ("class java.time.LocalDateTime").equals(xclass)) {
if ( CellType.NUMERIC == cell.getCellTypeEnum()) {
// 日期格式
result = cell.getDateCellValue();
Expand All @@ -76,6 +80,10 @@ private Object getCellValue(String xclass, Cell cell, ExcelImportEntity entity)
}
if (("class java.sql.Time").equals(xclass)) {
result = new Time(((Date) result).getTime());
}else if (("class java.time.LocalDate").equals(xclass)) {
result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
} else if (("class java.time.LocalDateTime").equals(xclass)) {
result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
}
} else if ( CellType.NUMERIC == cell.getCellTypeEnum()) {
result = cell.getNumericCellValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,13 @@ public static boolean isJavaClass(Field field) {
boolean isBaseClass = false;
if (fieldType.isArray()) {
isBaseClass = false;
} else if (fieldType.isPrimitive() || fieldType.getPackage() == null || fieldType.getPackage().getName().equals("java.lang") || fieldType.getPackage().getName().equals("java.math") || fieldType.getPackage().getName().equals("java.sql") || fieldType.getPackage().getName().equals("java.util")) {
} else if (fieldType.isPrimitive()
|| fieldType.getPackage() == null
|| fieldType.getPackage().getName().equals("java.lang")
|| fieldType.getPackage().getName().equals("java.math")
|| fieldType.getPackage().getName().equals("java.sql")
|| fieldType.getPackage().getName().equals("java.util")
|| fieldType.getPackage().getName().equals("java.time")) {
isBaseClass = true;
}
return isBaseClass;
Expand Down
16 changes: 15 additions & 1 deletion docs/修改日志.log
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,18 @@ autopoi/src/main/java/org/jeecgframework/poi/util/PoiPublicUtil.java

---author:chenrui---date:2024/4/24-----for:[QQYUN-9048]负数被识别成非数字---
src/main/java/org/jeecgframework/poi/util/ExcelUtil.java
---author:chenrui---date:2024/4/24-----for:[QQYUN-9048]负数被识别成非数字---
---author:chenrui---date:2024/4/24-----for:[QQYUN-9048]负数被识别成非数字---

---author:liusq---date:2024/7/30-----for:TV360X-1953 execl转html报错d != org.apache.poi.ss.usermodel.FillPatternType---
src\main\java\org\jeecgframework\poi\excel\html\helper\StylerHelper.java
src\test\resources\templates\专项支出用款申请书.xls
src\test\java\ExcelToHtmlTest.java
---author:liusq---date:2024/7/30-----for:TV360X-1953 execl转html报错d != org.apache.poi.ss.usermodel.FillPatternType---

---author:liusq---date:2024/7/30-----for:TV360X-1292 对象的属性为LocalDate、LocalDateTIme类型对象兼容---
autopoi\src\main\java\org\jeecgframework\poi\util\PoiPublicUtil.java
autopoi\src\main\java\org\jeecgframework\poi\excel\imports\CellValueServer.java
src\test\resources\templates\ExcelImportDateTest.xlsx
src\test\java\TestDateEntity.java
src\test\java\ImportExcelTest.java
---author:liusq---date:2024/7/30-----for:TV360X-1292 对象的属性为LocalDate、LocalDateTIme类型对象兼容---