Fix Open Office Spreadsheet (ODS) dates (#2843)

* Truncate any completely empty columns on the right

Fixes #565
The current versions of Open Office create default spreadsheets
with over 1000 empty columns. Keep track of the rightmost
non-empty column when importing and truncate everything else.

Also adds a basic ODS import test.

* Fix dates in ODS spreadsheets

Fixes #2224
This commit is contained in:
Tom Morris 2020-07-04 02:42:33 -04:00 committed by GitHub
parent 952447461f
commit 3717111db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View File

@ -39,6 +39,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
import java.time.ZoneOffset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -216,7 +217,7 @@ public class OdsImporter extends TabularImportingParserBase {
} else if ("float".equals(cellType)) { } else if ("float".equals(cellType)) {
value = cell.getDoubleValue(); value = cell.getDoubleValue();
} else if ("date".equals(cellType)) { } else if ("date".equals(cellType)) {
value = cell.getDateValue(); value = cell.getDateValue().toInstant().atOffset(ZoneOffset.UTC);
} else if ("currency".equals(cellType)) { } else if ("currency".equals(cellType)) {
value = cell.getCurrencyValue(); value = cell.getCurrencyValue();
} else if ("percentage".equals(cellType)) { } else if ("percentage".equals(cellType)) {

View File

@ -43,6 +43,7 @@ import static org.testng.Assert.assertTrue;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.time.OffsetDateTime;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
@ -109,8 +110,7 @@ public class OdsImporterTests extends ImporterTest {
Row row = project.rows.get(0); Row row = project.rows.get(0);
assertEquals(row.cells.size(), COLUMNS); assertEquals(row.cells.size(), COLUMNS);
assertEquals((String)row.getCellValue(1),"2 Days In New York"); assertEquals((String)row.getCellValue(1),"2 Days In New York");
// FIXME: Dates are currently broken assertEquals(((OffsetDateTime)row.getCellValue(3)).toString().substring(0, 10),"2012-03-28");
// assertEquals(((OffsetDateTime)row.getCellValue(3)).toString().substring(0, 10),"2012-03-28");
assertEquals(((Number)row.getCellValue(5)).doubleValue(), 4.5, EPSILON); assertEquals(((Number)row.getCellValue(5)).doubleValue(), 4.5, EPSILON);
assertFalse((Boolean)row.getCellValue(7)); assertFalse((Boolean)row.getCellValue(7));