Commit 31569226 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Improved Excel source

fix row handler
parent ff6e4078
/**
* Copyright 2014 Global Crop Diversity Trust
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -16,10 +16,13 @@
package org.genesys2.anno.reader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
......@@ -134,15 +137,15 @@ public class MyXSSFSheetHandler extends DefaultHandler {
// c => cell
else if ("c".equals(name)) {
// Get the cell reference
String r = attributes.getValue("r");
final String newColRef = attributes.getValue("r");
int firstDigit = -1;
for (int c = 0; c < r.length(); ++c) {
if (Character.isDigit(r.charAt(c))) {
for (int c = 0; c < newColRef.length(); ++c) {
if (Character.isDigit(newColRef.charAt(c))) {
firstDigit = c;
break;
}
}
thisColumn = nameToColumn(r.substring(0, firstDigit));
thisColumn = nameToColumn(newColRef.substring(0, firstDigit));
// Set up defaults.
this.nextDataType = xssfDataType.NUMBER;
......@@ -225,8 +228,11 @@ public class MyXSSFSheetHandler extends DefaultHandler {
break;
case NUMBER:
String n = value.toString();
if (n.contains("."))
final String n = value.toString();
if (DateUtil.isADateFormat(this.formatIndex, this.formatString)) {
final Date date = DateUtil.getJavaDate(Double.valueOf(n));
thisObj = new SimpleDateFormat("yyyyMMdd").format(date);
} else if (n.contains("."))
thisObj = Double.parseDouble(n);
else
thisObj = Long.parseLong(n);
......@@ -247,9 +253,14 @@ public class MyXSSFSheetHandler extends DefaultHandler {
// Emit commas for any fields that were missing on this row
if (lastColumnNumber == -1) {
lastColumnNumber = 0;
for (int i = lastColumnNumber; i < thisColumn; ++i) {
row.add("");
}
} else {
for (int i = lastColumnNumber; i < thisColumn - 1; ++i) {
row.add("");
}
}
for (int i = lastColumnNumber; i < thisColumn - 1; ++i)
row.add(null);
// Might be the empty string.
row.add(thisObj);
......@@ -314,5 +325,4 @@ public class MyXSSFSheetHandler extends DefaultHandler {
}
return column;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment