Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
basic
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor 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
xrm
basic
Commits
5d8cb7d5
Commit
5d8cb7d5
authored
4 years ago
by
Sebastian Listl
Browse files
Options
Downloads
Patches
Plain Diff
1064788 Odt table replacing
parent
8cb82a44
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
process/DocumentTemplate_lib/process.js
+49
-21
49 additions, 21 deletions
process/DocumentTemplate_lib/process.js
with
49 additions
and
21 deletions
process/DocumentTemplate_lib/process.js
+
49
−
21
View file @
5d8cb7d5
...
...
@@ -744,6 +744,17 @@ DocumentTemplate.prototype._getReplacedODT = function (pReplacements, pTableData
pReplacements
=
[
pReplacements
];
if
(
!
pTableData
)
pTableData
=
[];
var
tablePlaceholders
=
[];
if
(
pTableData
.
length
>
0
)
{
//pTableData[0] = first document
tablePlaceholders
=
pTableData
[
0
].
map
(
function
(
tblData
)
{
if
(
tblData
&&
tblData
.
length
>
0
)
return
new
Set
(
Object
.
keys
(
tblData
[
0
]));
//tblData[0] = first row
return
new
Set
();
});
}
if
(
pReplacements
.
length
!==
0
)
{
...
...
@@ -775,31 +786,48 @@ DocumentTemplate.prototype._getReplacedODT = function (pReplacements, pTableData
let
tables
=
pTableData
[
i
]
||
[];
let
tableEnd
=
0
;
for
(
let
tblIndex
=
0
;
tblIndex
<
tables
.
length
;
tblIndex
++
)
//iterate over all tables in the document
//for (let tblIndex = 0; tblIndex < tables.length; tblIndex++) //iterate over all tables in the document
if
(
tables
.
length
>
0
)
{
let
tableData
=
tables
[
tblIndex
]
;
if
(
tableData
&&
tableData
.
length
>
0
)
let
hasMoreTables
=
currentBody
.
includes
(
"
</table:table>
"
)
;
for
(
let
tblI
=
0
;
tblI
<
10
&&
hasMoreTables
;
tblI
++
)
{
tableEnd
=
currentBody
.
indexOf
(
"
</table:table>
"
,
tableEnd
)
+
14
;
if
(
tableEnd
===
-
1
)
//stop if there is no table
break
;
let
rowBegin
=
currentBody
.
slice
(
0
,
tableEnd
).
lastIndexOf
(
"
<table:table-row
"
);
let
rowEnd
=
currentBody
.
indexOf
(
"
</table:table-row>
"
,
rowBegin
)
+
18
;
let
afterTable
=
currentBody
.
slice
(
rowEnd
);
let
tableRow
=
currentBody
.
slice
(
rowBegin
,
rowEnd
);
tableEnd
-=
tableRow
.
length
;
currentBody
=
currentBody
.
slice
(
0
,
rowBegin
);
for
(
let
rowIndex
=
0
;
rowIndex
<
tableData
.
length
;
rowIndex
++
)
tableEnd
=
currentBody
.
indexOf
(
"
</table:table>
"
,
tableEnd
);
if
(
tableEnd
!==
-
1
)
//stop if there is no table
{
let
tableRowData
=
tableData
[
rowIndex
];
let
replacedRow
=
that
.
_replaceText
(
tableRow
,
tableRowData
);
currentBody
+=
replacedRow
;
tableEnd
+=
replacedRow
.
length
;
tableEnd
+=
14
;
let
rowBegin
=
currentBody
.
slice
(
0
,
tableEnd
).
lastIndexOf
(
"
<table:table-row
"
);
let
rowEnd
=
currentBody
.
indexOf
(
"
</table:table-row>
"
,
rowBegin
)
+
18
;
let
tableRow
=
currentBody
.
slice
(
rowBegin
,
rowEnd
);
let
rowPlaceholders
=
tableRow
.
match
(
PlaceholderUtils
.
getRegexpMatchAll
());
//find the table data that contains all required placeholders
let
tableDataIndex
=
!
rowPlaceholders
?
-
1
:
tablePlaceholders
.
findIndex
(
function
(
placeholderSet
)
{
return
rowPlaceholders
.
every
(
function
(
placeholderName
)
{
return
placeholderSet
.
has
(
placeholderName
);
});
});
if
(
tableDataIndex
!==
-
1
)
{
let
afterTable
=
currentBody
.
slice
(
rowEnd
);
currentBody
=
currentBody
.
slice
(
0
,
rowBegin
);
tableEnd
-=
tableRow
.
length
;
let
tableData
=
tables
[
tableDataIndex
];
for
(
let
rowIndex
=
0
;
rowIndex
<
tableData
.
length
;
rowIndex
++
)
{
let
tableRowData
=
tableData
[
rowIndex
];
let
replacedRow
=
that
.
_replaceText
(
tableRow
,
tableRowData
);
currentBody
+=
replacedRow
;
tableEnd
+=
replacedRow
.
length
;
}
currentBody
+=
afterTable
;
}
}
currentBody
+=
afterTable
;
else
hasMoreTables
=
false
;
}
}
fullBody
+=
currentBody
;
...
...
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