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

@ContentStyle注解设置不生效 #3667

Open
alohacai opened this issue Jan 22, 2024 · 0 comments
Open

@ContentStyle注解设置不生效 #3667

alohacai opened this issue Jan 22, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@alohacai
Copy link

触发场景描述

通过@ContentStyle注解设置导出单元格的样式,实测无法生效

触发Bug的代码

设置dataFormat的值为49,指定单元格为文本样式,以防止csv注入问题

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TestVO {
    @ContentStyle(dataFormat = 49)
    @ExcelProperty(value = "列1", index = 0)
    private String user;
    @ContentStyle(dataFormat = 49)
    @ExcelProperty(value = "列2", index = 1)
    private String name;
    @ContentStyle(dataFormat = 49)
    @ExcelProperty(value = "列3", index = 2)
    private String value;
}

实测导出文件无法生效

public static void main(String[] args) {
    String fileName = "test.xlsx";
    List<TestVO> testList = new ArrayList<>();
    TestVO vo = new TestVO();
    vo.setName("@ABS(cmd|'/c calc'!A1)");
    vo.setValue("@ABS(cmd|'/c calc'!A1)");
    vo.setUser("@ABS(cmd|'/c calc'!A1)");
    testList.add(vo);
    EasyExcel.write(fileName)
        .head(HEAD)
        .excelType(ExcelTypeEnum.XLSX)
        .sheet(1, "测试")
        .doWrite(testList);
}

image

问题跟踪

发现在AbstractExcelWriteExecutor类的313行,converter被实例化为StringStringConverter
image

当执行到327行时:
image

StringStringConverter会丢弃之前设置好的ExcelContentProperty属性,也就是我在@ContentStyle中设置的属性:
image

可以看到此时的cellData对象的writeCellStyle和originCellStyle对象都是null:
image

期待回复

不晓得这是设计如此还是一个被疏忽的bug呢?

@alohacai alohacai added the bug Something isn't working label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants