Skip to content

Commit

Permalink
[save] No copy sheet data (#1256)
Browse files Browse the repository at this point in the history
* [save] avoid copying sheet_data nodes

* [save] tweaks
  • Loading branch information
JanMarvin authored Jan 29, 2025
1 parent d8b59af commit 9f965be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
5 changes: 3 additions & 2 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -9788,9 +9788,9 @@ wbWorkbook <- R6::R6Class(
prior <- ws$get_prior_sheet_data()
post <- ws$get_post_sheet_data()

cc <- ws$sheet_data$cc
if (!is.null(ws$sheet_data$cc)) {

if (!is.null(cc)) {
cc <- ws$sheet_data$cc
cc$r <- stringi::stri_join(cc$c_r, cc$row_r)
# prepare data for output

Expand Down Expand Up @@ -9819,6 +9819,7 @@ wbWorkbook <- R6::R6Class(
)
ws_file <- file.path(xlworksheetsDir, sprintf("sheet%s.xml", i))
write_xmlPtr(doc = sheet_xml, fl = ws_file)
rm(sheet_xml)

## write worksheet rels
if (length(self$worksheets_rels[[i]])) {
Expand Down
11 changes: 3 additions & 8 deletions src/write_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ Rcpp::CharacterVector set_sst(Rcpp::CharacterVector sharedStrings) {
// the column data used in this row. This function uses both to create a single
// row and passes it to write_worksheet_xml_2 which will create the entire
// sheet_data part for this worksheet
pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) {

void xml_sheet_data(pugi::xml_node &doc, Rcpp::DataFrame &row_attr, Rcpp::DataFrame &cc) {
auto lastrow = 0; // integer value of the last row with column data
auto thisrow = 0; // integer value of the current row with column data
auto row_idx = 0; // the index of the row_attr file. this is != rowid
auto rowid = 0; // integer value of the r field in row_attr

pugi::xml_document doc;
pugi::xml_node row;

std::string xml_preserver = " ";
Expand Down Expand Up @@ -194,8 +194,6 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc)
}
}
}

return doc;
}

// TODO: convert to pugi
Expand Down Expand Up @@ -223,10 +221,7 @@ XPtrXML write_worksheet(std::string prior, std::string post, Rcpp::Environment s
pugi::xml_node sheetData = worksheet.append_child("sheetData");

if (cc.size() > 0) {
pugi::xml_document xml_sd;
xml_sd = xml_sheet_data(row_attr, cc);
for (auto sd : xml_sd.children())
sheetData.append_copy(sd);
xml_sheet_data(sheetData, row_attr, cc);
}

if (!post.empty()) {
Expand Down

0 comments on commit 9f965be

Please sign in to comment.