apache / apache/fesod

导出可以提供instance类型的支持吗

Open
#366 4 comments 0 reactions 0 assignees View on GitHub
help wanted question
Dominant language
Java
Stars
6.2k
Forks
532
Avg merge
1d 3h
Merged PRs (30d)
42

Description

### Search before asking

- [x] I searched in the [issues](https://github.com/fast-excel/fastexcel/issues) and found nothing similar.

### Motivation

# 原因
我习惯使用Jpa, 在jpa中使用projections时,用情况使用instance作为返回来,有些特性在低版本中不支持class方式,我在使用过程中发现查询的数据在导出的时候出现converter失败问题
```java
Specification beanWhere = EnhanceSpecification.beanWhere(page);

List all = userManageLogService.getJpaBasicsDao().findBy(beanWhere, query ->
query.project( "operator",
"operatorTime",
"dataType",
"event",
"eventDescription")
.as(LogExport.class)
.all());

HttpServletResponse responseHeader = ResponseFile.xlsxResponse(response
, "日志-" + DateTime.now().toString("yyyyMMddHHmmss"));
ExcelWriterBuilder excelWriterBuilder = write(responseHeader.getOutputStream())
.head(LogExport.class);
excelWriterBuilder.registerConverter(new LongStringConverter())
.sheet("日志")
.doWrite(all);
```
```java
public interface LogExport {
String getOperator();

String getOperatorTime();

String getDataType();

String getEvent();

String getEventDescription();

}
````
# 我的观测
我debug发现 `ExcelWriteAddExecutor#addOneRowOfDataToExcel` 方法中判断类型非map和List就使用`addJavaObjectToExcel`,在`addJavaObjectToExcel`的` BeanMap beanMap = BeanMapUtils.create(oneRowData);` 时导致的失败

# 我的临时办法
重新构建了一个返回class类的查询(这样写这没有直接使用projections方便

### Solution

_No response_

### Alternatives

_No response_

### Anything else?

_No response_

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.