Skip to content

Conversation

@waterisblue
Copy link
Contributor

测试代码如下:

@Setter
@Getter
static class FillData {
    private String name;
    private double number;
    private Date date;
    private LocalDate date2;
}
@Test
public void templateWriteFix() {
    String templateFileName = TestFileUtil.getPath() + "demo" + File.separator + "annotation.xlsx";
    String fileName = TestFileUtil.getPath() + "templateWrite" + System.currentTimeMillis() + ".xlsx";
    
    List<FillData> list = ListUtils.newArrayList();
    for (int i = 0; i < 10; i++) {
        FillData fillData = new FillData();
        list.add(fillData);
        fillData.setName("张三");
        fillData.setNumber(5.21111);
        fillData.setDate(new Date());
        fillData.setDate2(LocalDate.now());
    }

    EasyExcel.write(fileName, FillData.class).withTemplate(templateFileName).sheet().doFill(list);
}

#228

Copy link
Member

@psxjoy psxjoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit-test code cases in test module.

@waterisblue
Copy link
Contributor Author

When the date cell format is set:
image
Output:
image
When the date cell format is default:
image
Output:
image

@waterisblue waterisblue requested a review from psxjoy March 19, 2025 09:15
@721806280
Copy link
Contributor

Please make a reasonable assessment as to whether the location of the correction is more appropriate here.
#228 (comment)

@psxjoy
Copy link
Member

psxjoy commented Mar 19, 2025

Please make a reasonable assessment as to whether the location of the correction is more appropriate here. #228 (comment)

Yes. IMO, the changes you suggested are more impactful. Maybe @waterisblue can clarify whether they plan to implement these corrections or if there are advantages to sticking with the original changes.

@waterisblue
Copy link
Contributor Author

Yes, this solution has minor impact on the project and can address #228 , but IMO:

  1. Modifying the format of a specific type in the doFill method may be somewhat inconsistent with the programming standard. I believe it is more appropriate to modify the styles in the createCellStyle method.
  2. Discarding type checks and directly calling DateUtils.isADateFormat may affect performance, maybe no fast, of course, this requires more testing.
    @721806280 @psxjoy

@psxjoy
Copy link
Member

psxjoy commented Mar 20, 2025

Both changes work fine. I’ll merge them into master temporarily, and I’ll check the performance details when I have time.
我觉得两个改动都可以。暂时合并到master,性能方面我找时间看下。

@psxjoy psxjoy merged commit 057d178 into apache:main Mar 20, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants