liaochong / myexcel

MyExcel, a new way to operate excel!
https://github.com/liaochong/myexcel/wiki
Apache License 2.0
1.66k stars 325 forks source link

多级表头使用模块有误 #392

Closed yzy-1995 closed 1 year ago

yzy-1995 commented 1 year ago

image 我使用了您说的方案,"项目付款总额->材料付款" 这个并没有生效,如果使用index的话,就没办法去校验标题了。希望能尽早解决这个问题。谢谢

liaochong commented 1 year ago

使用标题读取是可以的,可以把你相关的代码贴一下吗?

yzy-1995 commented 1 year ago

public class ProjectInitialAmountDto {

@ApiModelProperty("项目编号")
@ExcelColumn(index = 0)
@NotBlank(message = "项目编号不能为空")
@Length(max = 64, message = "所属项目编号最多64个字符")
private String projNo;

@ApiModelProperty("项目回款总额")
@ExcelColumn(index = 1)
@DecimalMin(value = "0", message = "项目回款总额必须大于等于0")
@Digits(integer = 11, fraction = 2, message = "项目回款总额整数位不能大于11位,小数位不能大于2位")
private BigDecimal receivableAmount;

@ApiModelProperty("材料付款")
@ExcelColumn(index = 2)
@DecimalMin(value = "0", message = "材料付款总额必须大于等于0")
@Digits(integer = 11, fraction = 2, message = "材料付款总额整数位不能大于11位,小数位不能大于2位")
private BigDecimal materialAmount;

@ApiModelProperty("劳务付款")
@ExcelColumn(index = 3)
@DecimalMin(value = "0", message = "劳务付款总额必须大于等于0")
@Digits(integer = 11, fraction = 2, message = "劳务付款总额整数位不能大于11位,小数位不能大于2位")
private BigDecimal laborAmount;

@ApiModelProperty("机械付款")
@ExcelColumn(index = 4)
@DecimalMin(value = "0", message = "机械付款总额必须大于等于0")
@Digits(integer = 11, fraction = 2, message = "机械付款总额整数位不能大于11位,小数位不能大于2位")
private BigDecimal leaseAmount;

@ApiModelProperty("费用付款")
@ExcelColumn(index = 5)
@DecimalMin(value = "0", message = "费用付款总额必须大于等于0")
@Digits(integer = 11, fraction = 2, message = "费用付款总额整数位不能大于11位,小数位不能大于2位")
private BigDecimal costAmount;

@ApiModelProperty("项目税费总额")
@ExcelColumn(index = 6)
@DecimalMin(value = "0", message = "项目税费总额必须大于等于0")
@Digits(integer = 11, fraction = 2, message = "项目税费总额整数位不能大于11位,小数位不能大于2位")
private BigDecimal totalProjectTax;

@ApiModelProperty("项目ID")
private String projId;

} 期初信息导入.xlsx

liaochong commented 1 year ago

ExcelColumn(title="项目付款总额->劳务付款"),再加上rowFilter不行?不要加index

yzy-1995 commented 1 year ago

readList= DefaultExcelReader.of(ProjectInitialAmountDto.class) .sheet(0) .rowFilter(row -> row.getRowNum() > 0) .read(file.getInputStream()); 这样获取不到数据 file是MultipartFile类型

liaochong commented 1 year ago

请使用SaxExcelReader,不要用DefaultExcelReader,DefaultExcelReader功能弱

yzy-1995 commented 1 year ago

好的,我测试了一下,3.11.5到3.11.7都能读到对应列但是没有获取到里面的数据,3.11.8及以上版本可以获取到excel里面的数据