Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
9324ba7a
Verified
Commit
9324ba7a
authored
1 year ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Filling XLSX
parent
2dc4f469
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!100
WIP: Filling XLSX: Seems to be working.
,
!93
Filling XLSX: Everything except multiple choice.
Pipeline
#48178
passed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+23
-10
23 additions, 10 deletions
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
with
23 additions
and
10 deletions
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+
23
−
10
View file @
9324ba7a
...
...
@@ -57,11 +57,12 @@ def _get_path_rows(worksheet):
return
rows
def
_
generate_path_col_mapping
(
workbook
)
:
rt_col
=
_get_row_type_column_index
(
workbook
)
def
_
next_row_index
(
sheet
)
->
int
:
"""
Return the index for the next data row.
for
col
in
workbook
.
columns
:
pass
This is defined as the first row without any content.
"""
return
sheet
.
max_row
class
TemplateFiller
:
...
...
@@ -117,10 +118,15 @@ class TemplateFiller:
assert
len
(
common_path
)
>=
1
self
.
_sheet_index
[
"
.
"
.
join
(
common_path
)]
=
SimpleNamespace
(
common_path
=
common_path
,
sheetname
=
sheetname
,
sheet
=
sheet
)
common_path
=
common_path
,
sheetname
=
sheetname
,
sheet
=
sheet
,
col_index
=
col_index
)
def
_handle_data
(
self
,
data
:
dict
,
current_path
:
List
[
str
]
=
None
):
"""
Handle the data and write it into ``workbook``.
Parameters
----------
data: dict
The data at the current path position. Elements may be dicts, lists or simple scalar values.
"""
if
current_path
is
None
:
current_path
=
[]
...
...
@@ -129,24 +135,31 @@ class TemplateFiller:
if
isinstance
(
content
,
list
):
if
not
content
:
continue
# Must be all of the same type.
assert
len
(
set
(
type
(
entry
)
for
entry
in
content
))
==
1
if
isinstance
(
content
[
0
],
dict
):
# An array of objects: must go into exploded sheet
for
entry
in
content
:
self
.
_handle_data
(
data
=
entry
,
current_path
=
path
)
continue
for
entry
in
content
:
pass
else
:
self
.
_handle_single_data
(
data
=
content
,
current_path
=
path
)
self
.
_handle_simple_data
(
data
=
content
,
current_path
=
path
)
def
_handle_si
ng
le_data
(
self
,
data
,
current_path
:
List
[
str
]):
def
_handle_si
mp
le_data
(
self
,
data
,
current_path
:
List
[
str
]):
"""
Enter this single data item into the workbook.
Parameters
----------
data: dict
The data at the current path position. Must be single items (dict or simple scalar) or lists of
simple values.
"""
sheet
=
self
.
_sheet_index
[
"
.
"
.
join
(
current_path
)].
sheet
next_row
=
_next_row_index
(
sheet
)
for
name
,
content
in
data
.
items
():
if
isinstance
(
content
,
list
):
# TODO handle later
# scalar elements: semicolon separated
# nested dicts: recurse
continue
if
isinstance
(
content
,
dict
):
pass
...
...
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