Skip to content

Commit

Permalink
load person.xml and threadedCommentXML
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 3, 2023
1 parent b5072be commit 35048f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
17 changes: 8 additions & 9 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -1593,12 +1593,9 @@ wbWorkbook <- R6::R6Class(

for (i in seq_len(nSheets)) {
if (length(self$threadComments[[i]])) {
fl <- self$threadComments[[i]]
file.copy(
from = fl,
to = file.path(xlThreadComments, basename(fl)),
overwrite = TRUE,
copy.date = TRUE
write_file(
body = self$threadComments[[i]],
fl = file.path(xlThreadComments, sprintf("threadedComment%s.xml", i))
)
}
}
Expand All @@ -1607,11 +1604,13 @@ wbWorkbook <- R6::R6Class(
## xl/persons/person.xml
if (nPersons) {
personDir <- dir_create(tmpDir, "xl", "persons")
file.copy(self$persons, personDir, overwrite = TRUE)
write_file(
body = self$persons,
fl = file.path(personDir, "person.xml")
)
}



## xl/embeddings
if (length(self$embeddings)) {
embeddingsDir <- dir_create(tmpDir, "xl", "embeddings")
for (fl in self$embeddings) {
Expand Down
19 changes: 6 additions & 13 deletions R/wb_load.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ wb_load <- function(
on.exit(
unlink(
# TODO: this removes all files, the folders remain. grep instead grep_xml?
grep_xml("media|vmlDrawing|customXml|comment|embeddings|vbaProject|person", ignore.case = TRUE, invert = TRUE),
grep_xml("media|vmlDrawing|customXml|embeddings|vbaProject", ignore.case = TRUE, invert = TRUE),
recursive = TRUE, force = TRUE
),
add = TRUE
Expand Down Expand Up @@ -1111,19 +1111,11 @@ wb_load <- function(

## Threaded comments
if (length(threadCommentsXML) > 0) {
threadCommentsXMLrelationship <- lapply(xml, function(x) grep("threadedComment[0-9]+\\.xml", x, value = TRUE))
hasThreadComments <- lengths(threadCommentsXMLrelationship) > 0
if (any(hasThreadComments)) {
for (i in seq_along(xml)) {
if (hasThreadComments[i]) {
target <- apply_reg_match(threadCommentsXMLrelationship[[i]], '(?<=Target=").*?"')
target <- basename(gsub('"$', "", target))

wb$threadComments[[i]] <- grep(target, threadCommentsXML, value = TRUE)

}
}
if (lengths(threadCommentsXML)) {
wb$threadComments <- lapply(threadCommentsXML, read_xml, pointer = FALSE)
}

wb$append(
"Content_Types",
sprintf('<Override PartName="/xl/threadedComments/%s" ContentType="application/vnd.ms-excel.threadedcomments+xml"/>',
Expand All @@ -1133,7 +1125,8 @@ wb_load <- function(

## Persons (needed for Threaded Comment)
if (length(personXML) > 0) {
wb$persons <- personXML
wb$persons <- read_xml(personXML, pointer = FALSE)

wb$append(
"Content_Types",
'<Override PartName="/xl/persons/person.xml" ContentType="application/vnd.ms-excel.person+xml"/>'
Expand Down

0 comments on commit 35048f1

Please sign in to comment.