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

IfCommand issue in jxls library #313

Open
meltiserProjects opened this issue May 10, 2024 · 0 comments
Open

IfCommand issue in jxls library #313

meltiserProjects opened this issue May 10, 2024 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@meltiserProjects
Copy link

Dear all,

First of all, I would like to thank you and your team for jxls library, it really helps the community to work with excel files easier and faster.

I'm using version 3.0.0. I have a concern regarding one test:

@Test
public void noNotes() {
// Test
InputStream template = getClass().getResourceAsStream("IfTest_noNotes.xlsx");
File out = new File("target/IfTest_noNotes_output.xlsx");
out.getParentFile().mkdirs();
JxlsTemplateFiller builder = JxlsPoiTemplateFillerBuilder.newInstance().withAreaBuilder((transformer, ctc) -> {
List<Area> areas = new ArrayList<>();
XlsArea area = new XlsArea("Employees!A1:C2", transformer);
areas.add(area);
XlsArea eachArea = new XlsArea("Employees!A2:C2", transformer);
area.addCommand("A2:C2", new EachCommand("e", "employees", eachArea));
eachArea.addCommand("A2:C2", new IfCommand("e.payment<2000", new XlsArea("Employees!A2:C2", transformer), new XlsArea("Employees!A3:C3", transformer)));
return areas;
}).withTemplate(template).build();
builder.fill(data(), new JxlsOutputFile(out));
// Verify
try (TestWorkbook w = new TestWorkbook(out)) {
w.selectSheet("Employees");
assertEquals("Elsa", w.getCellValueAsString(2, 1));
assertEquals("Oleg", w.getCellValueAsString(3, 1));
assertEquals("Neil", w.getCellValueAsString(4, 1));
assertEquals("Maria", w.getCellValueAsString(5, 1));
assertEquals("John", w.getCellValueAsString(6, 1));
}
}

while reviewing the jxls repository, I have noticed that if I change the data method here:
builder.fill(data(), new JxlsOutputFile(out));
by returning only one employee (like this):

public static List<Employee> generateSampleEmployeeData() {
    try {
        List<Employee> employees = new ArrayList<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd", Locale.US);
        employees.add( new Employee("Elsa", dateFormat.parse("1970-Jul-10"), 1500, 0.15) );
        return employees;
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
})

I'm getting this excel result:
image

Is it some known behavior or is it a bug? Is there any workaround for this? I'm experiencing the same behavior in my application right now, and I don't know how to fix it. I mean how to return only one row without template data, if I have "if" statement.

Thanks for your help!

@meltiserProjects meltiserProjects added the bug Something isn't working label May 10, 2024
@SoltauFintel SoltauFintel self-assigned this May 12, 2024
@SoltauFintel SoltauFintel added this to the 3.1.0 milestone May 12, 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