Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
1 result

Target

Select target project
  • sfb1280/createstudyapp
1 result
Select Git revision
  • main
1 result
Show changes
Commits on Source (2)
No preview for this file type
...@@ -225,6 +225,13 @@ public class Main { ...@@ -225,6 +225,13 @@ public class Main {
obj.put("Subject age", currentRow[1]); obj.put("Subject age", currentRow[1]);
obj.put("Subject sex", SFB_JSON_Util.getGenderFromStringStart(currentRow[2]).toString()); obj.put("Subject sex", SFB_JSON_Util.getGenderFromStringStart(currentRow[2]).toString());
if (currentRow[3].equals("patient")) {
currentRow[3] = "Patient";
}
if (currentRow[3].toLowerCase().equals("healthy control subject")) {
currentRow[3] = "Healthy control subject";
}
if (!currentRow[3].equals("Healthy test subject") && !currentRow[3].equals("Patient") && !currentRow[3].equals("Healthy control subject")) if (!currentRow[3].equals("Healthy test subject") && !currentRow[3].equals("Patient") && !currentRow[3].equals("Healthy control subject"))
currentRow[3] = "Healthy test subject"; currentRow[3] = "Healthy test subject";
......
...@@ -5,15 +5,11 @@ import java.io.FileInputStream; ...@@ -5,15 +5,11 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Calendar; import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Scanner; import java.util.Scanner;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.io.InputStream;
public class CSV_Reader { public class CSV_Reader {
private String[] headers; private String[] headers;
...@@ -198,14 +194,18 @@ public class CSV_Reader { ...@@ -198,14 +194,18 @@ public class CSV_Reader {
LinkedList<CellData> cellDatas = null; LinkedList<CellData> cellDatas = null;
String[] sharedStrings = null; String[] sharedStrings = null;
LinkedList<Integer> dateStyles = null;
while(ze != null) { while(ze != null) {
String fileName = ze.getName(); String fileName = ze.getName();
if ((sheet == null && fileName.contains("worksheets")) || (sheet != null && fileName.endsWith(sheet + ".xml"))) { int workSheetsIndx = fileName.indexOf("/worksheets/");
if ((sheet == null && workSheetsIndx != -1 && fileName.lastIndexOf("/") == workSheetsIndx + 11 && fileName.endsWith(".xml")) || (sheet != null && fileName.endsWith(sheet + ".xml"))) {
cellDatas = cellDataFromXLSXextractedXML(readZipEntryToString(zis)); cellDatas = cellDataFromXLSXextractedXML(readZipEntryToString(zis));
} else if (fileName.endsWith("sharedStrings.xml")) { } else if (fileName.endsWith("sharedStrings.xml")) {
sharedStrings = sharedStringsFromXML(readZipEntryToString(zis)); sharedStrings = sharedStringsFromXML(readZipEntryToString(zis));
} else if (fileName.endsWith("styles.xml")) {
dateStyles = dateStylesFromXML(readZipEntryToString(zis));
} }
...@@ -241,7 +241,14 @@ public class CSV_Reader { ...@@ -241,7 +241,14 @@ public class CSV_Reader {
continue; continue;
} }
c.value = sharedStrings[val]; c.value = sharedStrings[val];
}
//Handle Styled Entries
if(c.type == CellData.Type.STYLED) {
if (dateStyles.contains(c.style)) {
c.switchType(CellData.Type.DATE);
} else {
c.switchType(CellData.Type.NUMBER);
}
} }
} }
int w = maxX - minX + 1; int w = maxX - minX + 1;
...@@ -282,6 +289,34 @@ public class CSV_Reader { ...@@ -282,6 +289,34 @@ public class CSV_Reader {
return xml.toString(); return xml.toString();
} }
private static LinkedList<Integer> dateStylesFromXML(String xml) {
int cellStylesIndx = xml.indexOf("<cellXfs");
LinkedList<Integer> dateStyles = new LinkedList<>();
if (cellStylesIndx == -1)
return dateStyles;
xml = xml.substring(cellStylesIndx, xml.indexOf("</cellXfs>", cellStylesIndx));
int index = 0;
int elementIndex = -1;
while((index = xml.indexOf("<xf", index)) != -1) {
elementIndex++;
int endOfTag = xml.indexOf('>', index);
int numFormatIdIndx = xml.indexOf("numFmtId=\"", index);
if (numFormatIdIndx > endOfTag) {
index = endOfTag;
continue;
}
numFormatIdIndx += 10;
int formatId = Integer.parseInt(xml.substring(numFormatIdIndx, xml.indexOf('\"', numFormatIdIndx)));
if (formatId == 14 || formatId == 15 || formatId == 16 || formatId == 17 || formatId == 22)
dateStyles.add(elementIndex);
index = endOfTag;
}
return dateStyles;
}
private static String[] sharedStringsFromXML(String xml) { private static String[] sharedStringsFromXML(String xml) {
LinkedList<String> res = new LinkedList<>(); LinkedList<String> res = new LinkedList<>();
...@@ -308,16 +343,19 @@ public class CSV_Reader { ...@@ -308,16 +343,19 @@ public class CSV_Reader {
CellData.Type type = CellData.Type.NUMBER; CellData.Type type = CellData.Type.NUMBER;
int typeString = sheetData.indexOf("t=\"s\"", index); int typeString = sheetData.indexOf("t=\"s\"", index);
boolean isStr = typeString != -1 && typeString < endOfTag; boolean isStr = typeString != -1 && typeString < endOfTag;
int style = 0;
if (isStr) { if (isStr) {
type = CellData.Type.STRING; type = CellData.Type.STRING;
} } else {
int typeDate = sheetData.indexOf("s=\"1\"", index);
boolean isDate = typeDate != -1 && typeDate < endOfTag;
if (isDate) { int typeStyled = sheetData.indexOf("s=\"", index);
type = CellData.Type.DATE; boolean isStyled = typeStyled != -1 && typeStyled < endOfTag;
if (isStyled) {
type = CellData.Type.STYLED;
style = Integer.parseInt(sheetData.substring (typeStyled + 3, sheetData.indexOf('\"', typeStyled + 3)));
}
} }
int valOpen = sheetData.indexOf("<v>", endOfTag); int valOpen = sheetData.indexOf("<v>", endOfTag);
...@@ -329,7 +367,7 @@ public class CSV_Reader { ...@@ -329,7 +367,7 @@ public class CSV_Reader {
} }
String value = sheetData.substring(valOpen + 3, valClose); String value = sheetData.substring(valOpen + 3, valClose);
cellData.add(new CellData(cellID, value, type)); cellData.add(new CellData(cellID, value, type, style));
index = endOfTag; index = endOfTag;
} }
...@@ -338,18 +376,24 @@ public class CSV_Reader { ...@@ -338,18 +376,24 @@ public class CSV_Reader {
private static class CellData { private static class CellData {
private static final Calendar CALENDAR = Calendar.getInstance(); private static final Calendar CALENDAR = Calendar.getInstance();
public static enum Type {NUMBER, STRING, DATE} public static enum Type {NUMBER, STRING, DATE, STYLED}
public String cellID; public String cellID;
public String value; public String value;
public Type type; public Type type;
public int style;
public CellData(String cellID, String value, Type type) { public CellData(String cellID, String value, Type type, int style) {
this.cellID = cellID; this.cellID = cellID;
this.value = value; this.value = value;
this.type = type; this.type = type;
this.style = style;
if (type == Type.DATE) {
}
public void switchType(Type newType) {
type = newType;
if (newType == Type.DATE) {
if (this.value.contains(".")) { if (this.value.contains(".")) {
this.value = this.value.substring(0, value.indexOf(".")); this.value = this.value.substring(0, value.indexOf("."));
} }
......