miachm / SODS

A simple Java library for handle ODS (Open Document Spreadsheet, compatible with Excel and Libreoffice)
The Unlicense
74 stars 30 forks source link

Reading problem with empty cells #49

Closed adn35350 closed 1 year ago

adn35350 commented 1 year ago

Hello,

There is a problem when attempting to read lines which contain empty cells and non empty cells.

Here is the content of the ods file : image :

The complete file

And this is the result of reading :

content | content | 
content | content | 
content | content | 

Please tell me if you need more informations.

Thanks

github-actions[bot] commented 1 year ago

Thanks for your report! Please ensure you have provided enough info in order to recreate the issue, including the problematic ODS File.

miachm commented 1 year ago

This was really tricky one. The file is loaded correctly but at the end is corrupted by the "trim" feature.

Thanks for reporting, I can fix it now :)

miachm commented 1 year ago

Fixed in v1.5.2

adn35350 commented 1 year ago

Tanks for the fix. I think the problem is partially resolved.

When I read the same file, I obtain this result :

content | content |         | content
content | content | content | 
content | content | content | 

First line and second lines are good but not the third.

Here is the good result that I obtain with the 1.4.0 version :

content | content |         | content
content | content | content | 
content |         |         | 

Please tell me if you need more informations.

miachm commented 1 year ago

@adn35350 That's really weird. I created an unit test with your file and it's passing.

I am using sheet.getDataRange().getValues(). But maybe you are accesing the data in another way.

Can I ask you how are you testing this? A sample code would be great.

adn35350 commented 1 year ago

I'm using the same method sheet.getDataRange().getValues()

Here is the JUnit test that failed. You must to change the file path before testing.

@Test
void testReadContent() throws FileNotFoundException, IOException {
  final String[] line1 = new String[] { "content", "content", null, "content" };
  final String[] line2 = new String[] { "content", "content", "content", };
  final String[] line3 = new String[] { "content", null, null, null };
  final String[][] expected = new String[][] { line1, line2, line3 };

  final File testFile = new File("/path/to/test-file.ods");
  final SpreadSheet spreadsheet = new SpreadSheet(new FileInputStream(testFile));
  final Sheet sheet = spreadsheet.getSheet(0);
  final Range dataRange = sheet.getDataRange();
  final Object[][] values = dataRange.getValues();

  for (int i = 0; i < expected.length; i++) {
    for (int j = 0; j < expected[i].length; j++) {
      Assertions.assertEquals(expected[i][j], values[i][j], "Reading line " + (i + 1) + ", column " + (j + 1));
    }
  }
}

The result is : org.opentest4j.AssertionFailedError: Reading line 3, column 2 ==> expected: <null> but was: <content>

Maybe the way I'm reading the ods file is bad ?

adn35350 commented 1 year ago

Apparently the test is valid when executing on another local machine.

I think it's not a problem with the library but on my computer.

It's very strange !

miachm commented 1 year ago

@adn35350 JDK versions?

adn35350 commented 1 year ago
openjdk 11.0.17 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing)
miachm commented 1 year ago

The test is passing for me in JDK8. But when I try in the Github CI with JDK11:

Failed tests: testReadContent(com.github.miachm.sods.SpreadSheetTest): content expected: but was:<VALUE: 'content' != 'content'. Reading line 1, column 1>

https://github.com/miachm/SODS/pull/50

This is really weird...

adn35350 commented 1 year ago

I deleted all maven depencies in the .m2 directory. After doing this, test finally passes. Maybe it was just a refresh problem after branch checkout or after pom.xml update.

You can close this issue. Thanks for your help

miachm commented 1 year ago

Okay then, let´s close :)