Skip to content

[Bug] Blank cells and all-blank rows read differently in XLS and CSV than in XLSX #1105

Description

@nkuprins

Search before asking

  • I searched in the issues and found nothing similar.

Fesod version

main

JDK version

any

Operating system

Linux

Steps To Reproduce

List<List<Object>> data = Arrays.asList(
        Arrays.asList("x", "y"),
        Arrays.asList(" ", "\t"),  // whitespace only
        Arrays.asList("", ""),     // empty strings
        Arrays.asList(" ", "z"),   // one blank cell next to data
        Arrays.asList("p", "q"));

for (String ext : new String[] {".xlsx", ".xls", ".csv"}) {
    File file = new File("blank" + ext);
    FesodSheet.write(file).sheet().doWrite(data);

    List<Map<Integer, String>> rows = FesodSheet.read(file).headRowNumber(0).sheet().doReadSync();
    System.out.println(ext + " -> " + rows);
}

Current Behavior

The same content reads back differently depending only on the file extension:

Row written .xlsx .xls .csv
[" ", "\t"] skipped {0="", 1=""} {0=null, 1=null}
["", ""] skipped {0="", 1=""} {0=null, 1=null}
[" ", "z"] {0=null, 1="z"} {0="", 1="z"} {0=null, 1="z"}

So XLSX returns 3 rows, while XLS and CSV return 5 rows. XLS also returns "" where the other formats return null, including in rows that have data.

With autoTrim(false), XLSX and XLS keep " " and "\t", but CSV still returns null for them.

Expected Behavior

All three formats should read the same content the same way. That means following the rule the XLSX reader already applies:

  • A cell that is empty after autoTrim/autoStrip is null.
  • A row whose cells are all empty is an empty row, so it's skipped while ignoreEmptyRow is true (the default).

Expected result for every format: [{0=x, 1=y}, {0=null, 1=z}, {0=p, 1=q}].

Anything else?

The fix is to call checkEmpty() in the two XLS label handlers and only mark the row as DATA when the cell isn't empty. In CSV, trim first, then check for empty, and mark the row EMPTY when every cell is empty.

This is a behaviour change: XLS users get null instead of "", and XLS/CSV users no longer receive all-blank rows unless they set ignoreEmptyRow(false).

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions