From 35048f165f6f7f3fb47a8bcd4800dea63073fffb Mon Sep 17 00:00:00 2001 From: Jan Marvin Garbuszus Date: Mon, 3 Jul 2023 23:57:31 +0200 Subject: [PATCH] load person.xml and threadedCommentXML --- R/class-workbook.R | 17 ++++++++--------- R/wb_load.R | 19 ++++++------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/R/class-workbook.R b/R/class-workbook.R index fdeb8cf1e..40240a238 100644 --- a/R/class-workbook.R +++ b/R/class-workbook.R @@ -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)) ) } } @@ -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) { diff --git a/R/wb_load.R b/R/wb_load.R index a81289e0c..85f0c8736 100644 --- a/R/wb_load.R +++ b/R/wb_load.R @@ -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 @@ -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('', @@ -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", ''