Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CreateStudyApp
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SFB1280
CreateStudyApp
Commits
b9b1e0f1
Commit
b9b1e0f1
authored
2 months ago
by
Erik Diers
Browse files
Options
Downloads
Patches
Plain Diff
Fixed xlsx read errors
parent
a25fb7a9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
builds/SFB_CreateStudy.jar
+0
-0
0 additions, 0 deletions
builds/SFB_CreateStudy.jar
src/main/Main.java
+7
-0
7 additions, 0 deletions
src/main/Main.java
src/utils/CSV_Reader.java
+61
-17
61 additions, 17 deletions
src/utils/CSV_Reader.java
with
68 additions
and
17 deletions
builds/SFB_CreateStudy.jar
+
0
−
0
View file @
b9b1e0f1
No preview for this file type
This diff is collapsed.
Click to expand it.
src/main/Main.java
+
7
−
0
View file @
b9b1e0f1
...
...
@@ -225,6 +225,13 @@ public class Main {
obj
.
put
(
"Subject age"
,
currentRow
[
1
]);
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"
))
currentRow
[
3
]
=
"Healthy test subject"
;
...
...
This diff is collapsed.
Click to expand it.
src/utils/CSV_Reader.java
+
61
−
17
View file @
b9b1e0f1
...
...
@@ -5,15 +5,11 @@ import java.io.FileInputStream;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.Calendar
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.Scanner
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
import
java.io.InputStream
;
public
class
CSV_Reader
{
private
String
[]
headers
;
...
...
@@ -198,14 +194,18 @@ public class CSV_Reader {
LinkedList
<
CellData
>
cellDatas
=
null
;
String
[]
sharedStrings
=
null
;
LinkedList
<
Integer
>
dateStyles
=
null
;
while
(
ze
!=
null
)
{
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
));
}
else
if
(
fileName
.
endsWith
(
"sharedStrings.xml"
))
{
sharedStrings
=
sharedStringsFromXML
(
readZipEntryToString
(
zis
));
}
else
if
(
fileName
.
endsWith
(
"styles.xml"
))
{
dateStyles
=
dateStylesFromXML
(
readZipEntryToString
(
zis
));
}
...
...
@@ -241,7 +241,14 @@ public class CSV_Reader {
continue
;
}
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
;
...
...
@@ -282,6 +289,34 @@ public class CSV_Reader {
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
)
{
LinkedList
<
String
>
res
=
new
LinkedList
<>();
...
...
@@ -308,16 +343,19 @@ public class CSV_Reader {
CellData
.
Type
type
=
CellData
.
Type
.
NUMBER
;
int
typeString
=
sheetData
.
indexOf
(
"t=\"s\""
,
index
);
boolean
isStr
=
typeString
!=
-
1
&&
typeString
<
endOfTag
;
int
style
=
0
;
if
(
isStr
)
{
type
=
CellData
.
Type
.
STRING
;
}
int
typeDate
=
sheetData
.
indexOf
(
"s=\"1\""
,
index
);
boolean
isDate
=
typeDate
!=
-
1
&&
typeDate
<
endOfTag
;
}
else
{
if
(
isDate
)
{
type
=
CellData
.
Type
.
DATE
;
int
typeStyled
=
sheetData
.
indexOf
(
"s=\""
,
index
);
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
);
...
...
@@ -329,7 +367,7 @@ public class CSV_Reader {
}
String
value
=
sheetData
.
substring
(
valOpen
+
3
,
valClose
);
cellData
.
add
(
new
CellData
(
cellID
,
value
,
type
));
cellData
.
add
(
new
CellData
(
cellID
,
value
,
type
,
style
));
index
=
endOfTag
;
}
...
...
@@ -338,18 +376,24 @@ public class CSV_Reader {
private
static
class
CellData
{
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
value
;
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
.
value
=
value
;
this
.
type
=
type
;
if
(
type
==
Type
.
DATE
)
{
this
.
style
=
style
;
}
public
void
switchType
(
Type
newType
)
{
type
=
newType
;
if
(
newType
==
Type
.
DATE
)
{
if
(
this
.
value
.
contains
(
"."
))
{
this
.
value
=
this
.
value
.
substring
(
0
,
value
.
indexOf
(
"."
));
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment