diff --git a/.Rbuildignore b/.Rbuildignore index d6a074f9c..cf0404921 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -13,6 +13,7 @@ README.Rmd codecov.yml .lintr .covrignore +^src/.clang-format$ # Temporary files .DS_Store diff --git a/R/RcppExports.R b/R/RcppExports.R index 77566d09a..3271fec6f 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -169,22 +169,22 @@ write_xml_file <- function(xml_content, escapes) { #' #' @examples #' # add single node -#' xml_node <- "openxlsx2" -#' xml_attr <- c(qux = "quux") -#' # "openxlsx2" -#' xml_attr_mod(xml_node, xml_attr) +#' xml_node <- "openxlsx2" +#' xml_attr <- c(qux = "quux") +#' # "openxlsx2" +#' xml_attr_mod(xml_node, xml_attr) #' #' # update node and add node -#' xml_node <- "openxlsx2" -#' xml_attr <- c(foo = "baz", qux = "quux") -#' # "openxlsx2" -#' xml_attr_mod(xml_node, xml_attr) +#' xml_node <- "openxlsx2" +#' xml_attr <- c(foo = "baz", qux = "quux") +#' # "openxlsx2" +#' xml_attr_mod(xml_node, xml_attr) #' #' # remove node and add node -#' xml_node <- "openxlsx2" -#' xml_attr <- c(foo = "", qux = "quux") -#' # "openxlsx2" -#' xml_attr_mod(xml_node, xml_attr) +#' xml_node <- "openxlsx2" +#' xml_attr <- c(foo = "", qux = "quux") +#' # "openxlsx2" +#' xml_attr_mod(xml_node, xml_attr) #' @export xml_attr_mod <- function(xml_content, xml_attributes, escapes = FALSE, declaration = FALSE, remove_empty_attr = TRUE) { .Call(`_openxlsx2_xml_attr_mod`, xml_content, xml_attributes, escapes, declaration, remove_empty_attr) diff --git a/man/xml_attr_mod.Rd b/man/xml_attr_mod.Rd index d30865d2d..171c397cd 100644 --- a/man/xml_attr_mod.Rd +++ b/man/xml_attr_mod.Rd @@ -36,20 +36,20 @@ updated else it is added as attribute. } \examples{ # add single node - xml_node <- "openxlsx2" - xml_attr <- c(qux = "quux") - # "openxlsx2" - xml_attr_mod(xml_node, xml_attr) + xml_node <- "openxlsx2" + xml_attr <- c(qux = "quux") + # "openxlsx2" + xml_attr_mod(xml_node, xml_attr) # update node and add node - xml_node <- "openxlsx2" - xml_attr <- c(foo = "baz", qux = "quux") - # "openxlsx2" - xml_attr_mod(xml_node, xml_attr) + xml_node <- "openxlsx2" + xml_attr <- c(foo = "baz", qux = "quux") + # "openxlsx2" + xml_attr_mod(xml_node, xml_attr) # remove node and add node - xml_node <- "openxlsx2" - xml_attr <- c(foo = "", qux = "quux") - # "openxlsx2" - xml_attr_mod(xml_node, xml_attr) + xml_node <- "openxlsx2" + xml_attr <- c(foo = "", qux = "quux") + # "openxlsx2" + xml_attr_mod(xml_node, xml_attr) } diff --git a/src/.clang-format b/src/.clang-format new file mode 100644 index 000000000..356c6ce16 --- /dev/null +++ b/src/.clang-format @@ -0,0 +1,14 @@ +IndentWidth: 2 +ContinuationIndentWidth: 2 # Control the indentation width after a line break, such as in function arguments +ColumnLimit: 100 # Set the maximum line length to 100 characters +BreakBeforeBraces: Attach # Keep braces on the same line as the function declaration +BinPackParameters: false # Force each parameter to appear on its own line +BinPackArguments: false # Force each argument in calls to appear on its own line +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: true # Align equal signs in consecutive assignments +AlignConsecutiveDeclarations: true # Align types and variables in consecutive declarations +AlignTrailingComments: true # Align trailing comments +AllowShortFunctionsOnASingleLine: None # Break short functions into multiple lines +Cpp11BracedListStyle: true # Format braced initializer lists cleanly +PenaltyBreakBeforeFirstCallParameter: 0 # Encourage breaking after the first parameter + diff --git a/src/helper_functions.cpp b/src/helper_functions.cpp index caadd5a53..e502c1dbf 100644 --- a/src/helper_functions.cpp +++ b/src/helper_functions.cpp @@ -16,17 +16,18 @@ //' @noRd // [[Rcpp::export]] bool to_long(std::string path) { - return path.size() > R_PATH_MAX; + return path.size() > R_PATH_MAX; } // [[Rcpp::export]] SEXP openxlsx2_type(SEXP x) { const SEXP names = Rf_getAttrib(x, R_NamesSymbol); - R_xlen_t ncol = Rf_length(x); + R_xlen_t ncol = Rf_length(x); Rcpp::IntegerVector type(ncol); - if (!Rf_isNull(names)) type.attr("names") = names; + if (!Rf_isNull(names)) + type.attr("names") = names; for (R_xlen_t i = 0; i < ncol; ++i) { @@ -104,15 +105,12 @@ SEXP openxlsx2_type(SEXP x) { type[i] = list; break; - // whatever is not covered from above default: { type[i] = character; break; } - } - } return type; @@ -122,9 +120,9 @@ SEXP openxlsx2_type(SEXP x) { Rcpp::IntegerVector col_to_int(Rcpp::CharacterVector x) { // This function converts the Excel column letter to an integer - R_xlen_t n = static_cast(x.size()); + R_xlen_t n = static_cast(x.size()); std::unordered_map col_map; - Rcpp::IntegerVector colNums(n); + Rcpp::IntegerVector colNums(n); for (R_xlen_t i = 0; i < n; ++i) { std::string a = Rcpp::as(x[i]); @@ -143,8 +141,8 @@ Rcpp::IntegerVector col_to_int(Rcpp::CharacterVector x) { } else { // Compute the integer value and store it in the map int col_int = cell_to_colint(a); - col_map[a] = col_int; - colNums[i] = col_int; + col_map[a] = col_int; + colNums[i] = col_int; } } @@ -153,8 +151,8 @@ Rcpp::IntegerVector col_to_int(Rcpp::CharacterVector x) { // [[Rcpp::export]] Rcpp::CharacterVector ox_int_to_col(Rcpp::NumericVector x) { - R_xlen_t n = static_cast(x.size()); - Rcpp::CharacterVector colNames(n); + R_xlen_t n = static_cast(x.size()); + Rcpp::CharacterVector colNames(n); std::unordered_map cache; // Updated key type for (R_xlen_t i = 0; i < n; ++i) { @@ -166,8 +164,8 @@ Rcpp::CharacterVector ox_int_to_col(Rcpp::NumericVector x) { } else { // Compute the column name and store it in the cache std::string col_name = int_to_col(num); - cache[num] = col_name; - colNames[i] = col_name; + cache[num] = col_name; + colNames[i] = col_name; } } @@ -178,48 +176,48 @@ Rcpp::CharacterVector ox_int_to_col(Rcpp::NumericVector x) { // [[Rcpp::export]] SEXP rbindlist(Rcpp::List x) { - R_xlen_t nn = static_cast(x.size()); + R_xlen_t nn = static_cast(x.size()); std::vector all_names; // get unique names and create set for (R_xlen_t i = 0; i < nn; ++i) { - if (Rf_isNull(x[i])) continue; + if (Rf_isNull(x[i])) + continue; std::vector name_i = Rcpp::as(x[i]).attr("names"); std::unique_copy(name_i.begin(), name_i.end(), std::back_inserter(all_names)); } std::sort(all_names.begin(), all_names.end()); - std::set unique_names(std::make_move_iterator(all_names.begin()), - std::make_move_iterator(all_names.end())); + std::set unique_names( + std::make_move_iterator(all_names.begin()), std::make_move_iterator(all_names.end())); R_xlen_t kk = static_cast(unique_names.size()); // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } for (R_xlen_t i = 0; i < nn; ++i) { - if (Rf_isNull(x[i])) continue; + if (Rf_isNull(x[i])) + continue; std::vector values = Rcpp::as>(x[i]); - std::vector names = Rcpp::as(x[i]).attr("names"); + std::vector names = Rcpp::as(x[i]).attr("names"); for (size_t j = 0; j < names.size(); ++j) { - auto find_res = unique_names.find(names[j]); - R_xlen_t mtc = std::distance(unique_names.begin(), find_res); + auto find_res = unique_names.find(names[j]); + R_xlen_t mtc = std::distance(unique_names.begin(), find_res); Rcpp::as(df[mtc])[i] = Rcpp::String(values[j]); } - } // 3. Create a data.frame df.attr("row.names") = Rcpp::IntegerVector::create(NA_INTEGER, nn); - df.attr("names") = unique_names; - df.attr("class") = "data.frame"; + df.attr("names") = unique_names; + df.attr("class") = "data.frame"; return df; } @@ -230,18 +228,18 @@ SEXP copy(SEXP x) { } // [[Rcpp::export]] -Rcpp::CharacterVector needed_cells(const std::string& range) { +Rcpp::CharacterVector needed_cells(const std::string &range) { std::vector cells; // Parse the input range std::string startCell, endCell; - size_t colonPos = range.find(':'); + size_t colonPos = range.find(':'); if (colonPos != std::string::npos) { startCell = range.substr(0, colonPos); - endCell = range.substr(colonPos + 1); + endCell = range.substr(colonPos + 1); } else { startCell = range; - endCell = range; + endCell = range; } if (!validate_dims(startCell) || !validate_dims(endCell)) { @@ -250,7 +248,7 @@ Rcpp::CharacterVector needed_cells(const std::string& range) { // Extract column and row numbers from start and end cells uint32_t startRow, endRow; - int32_t startCol = 0, endCol = 0; + int32_t startCol = 0, endCol = 0; startCol = cell_to_colint(startCell); endCol = cell_to_colint(endCell); @@ -272,8 +270,12 @@ Rcpp::CharacterVector needed_cells(const std::string& range) { // provide a basic rbindlist for lists of named characters // [[Rcpp::export]] -SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Nullable filled, bool fill, - Rcpp::Nullable fcols) { +SEXP dims_to_df( + Rcpp::IntegerVector rows, + Rcpp::CharacterVector cols, + Rcpp::Nullable filled, + bool fill, + Rcpp::Nullable fcols) { R_xlen_t kk = static_cast(cols.size()); R_xlen_t nn = static_cast(rows.size()); @@ -283,8 +285,7 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { if (fill) SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); else @@ -294,20 +295,19 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null if (fill) { if (has_filled) { - std::vector flld = Rcpp::as>(filled.get()); + std::vector flld = Rcpp::as>(filled.get()); std::unordered_set flls(flld.begin(), flld.end()); // with has_filled we always have to run this loop for (R_xlen_t i = 0; i < kk; ++i) { Rcpp::CharacterVector cvec = Rcpp::as(df[i]); - std::string coli = Rcpp::as(cols[i]); + std::string coli = Rcpp::as(cols[i]); for (R_xlen_t j = 0; j < nn; ++j) { std::string cell = coli + std::to_string(rows[j]); if (has_cell(cell, flls)) cvec[j] = cell; } } - } else { // insert cells into data frame std::vector fcls; @@ -319,7 +319,7 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null if (has_fcols && std::find(fcls.begin(), fcls.end(), i) == fcls.end()) continue; Rcpp::CharacterVector cvec = Rcpp::as(df[i]); - std::string coli = Rcpp::as(cols[i]); + std::string coli = Rcpp::as(cols[i]); for (R_xlen_t j = 0; j < nn; ++j) { cvec[j] = coli + std::to_string(rows[j]); } @@ -330,8 +330,8 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null // 3. Create a data.frame df.attr("row.names") = rows; - df.attr("names") = cols; - df.attr("class") = "data.frame"; + df.attr("names") = cols; + df.attr("class") = "data.frame"; return df; } @@ -340,11 +340,11 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null // [[Rcpp::export]] void long_to_wide(Rcpp::DataFrame z, Rcpp::DataFrame tt, Rcpp::DataFrame zz) { - R_xlen_t n = static_cast(zz.nrow()); + R_xlen_t n = static_cast(zz.nrow()); R_xlen_t col = 0, row = 0; - Rcpp::IntegerVector cols = zz["cols"]; - Rcpp::IntegerVector rows = zz["rows"]; + Rcpp::IntegerVector cols = zz["cols"]; + Rcpp::IntegerVector rows = zz["rows"]; Rcpp::CharacterVector vals = zz["val"]; Rcpp::CharacterVector typs = zz["typ"]; @@ -374,25 +374,24 @@ Rcpp::LogicalVector is_charnum(Rcpp::CharacterVector x) { // similar to dcast converts cc dataframe to z dataframe // [[Rcpp::export]] void wide_to_long( - Rcpp::DataFrame z, - std::vector vtyps, - Rcpp::DataFrame zz, - bool ColNames, - int32_t start_col, - int32_t start_row, - Rcpp::Nullable refed, - int32_t string_nums, - bool na_null, - bool na_missing, - std::string na_strings, - bool inline_strings, - std::string c_cm, - std::vector dims -) { - - R_xlen_t n = static_cast(z.nrow()); - R_xlen_t m = static_cast(z.ncol()); - bool has_dims = static_cast(dims.size()) == (n * m); + Rcpp::DataFrame z, + std::vector vtyps, + Rcpp::DataFrame zz, + bool ColNames, + int32_t start_col, + int32_t start_row, + Rcpp::Nullable refed, + int32_t string_nums, + bool na_null, + bool na_missing, + std::string na_strings, + bool inline_strings, + std::string c_cm, + std::vector dims) { + + R_xlen_t n = static_cast(z.nrow()); + R_xlen_t m = static_cast(z.ncol()); + bool has_dims = static_cast(dims.size()) == (n * m); std::vector srows(static_cast(n)); for (size_t j = 0; j < static_cast(n); ++j) { @@ -404,10 +403,11 @@ void wide_to_long( scols[i] = int_to_col(static_cast(start_col) + i); } - bool has_refs = refed.isNotNull(); + bool has_refs = refed.isNotNull(); std::vector ref; - if (has_refs) ref = Rcpp::as>(refed.get()); + if (has_refs) + ref = Rcpp::as>(refed.get()); int32_t in_string_nums = string_nums; @@ -430,36 +430,35 @@ void wide_to_long( R_xlen_t idx = 0; - SEXP blank_sexp = Rf_mkChar(""); - SEXP array_sexp = Rf_mkChar("array"); - SEXP inlineStr_sexp = Rf_mkChar("inlineStr"); - SEXP bool_sexp = Rf_mkChar("b"); - SEXP expr_sexp = Rf_mkChar("e"); - SEXP sharedStr_sexp = Rf_mkChar("s"); - SEXP string_sexp = Rf_mkChar("str"); + SEXP blank_sexp = Rf_mkChar(""); + SEXP array_sexp = Rf_mkChar("array"); + SEXP inlineStr_sexp = Rf_mkChar("inlineStr"); + SEXP bool_sexp = Rf_mkChar("b"); + SEXP expr_sexp = Rf_mkChar("e"); + SEXP sharedStr_sexp = Rf_mkChar("s"); + SEXP string_sexp = Rf_mkChar("str"); SEXP na_sexp = Rf_mkChar("#N/A"); SEXP num_sexp = Rf_mkChar("#NUM!"); SEXP value_sexp = Rf_mkChar("#VALUE!"); SEXP na_strings_sexp = Rf_mkChar(na_strings.c_str()); - for (R_xlen_t i = 0; i < m; ++i) { - Rcpp::CharacterVector cvec = Rcpp::as(z[i]); - const std::string& col = scols[static_cast(i)]; - int8_t vtyp_i = static_cast(vtyps[static_cast(i)]); + Rcpp::CharacterVector cvec = Rcpp::as(z[i]); + const std::string &col = scols[static_cast(i)]; + int8_t vtyp_i = static_cast(vtyps[static_cast(i)]); for (R_xlen_t j = 0; j < n; ++j, ++idx) { checkInterrupt(idx); // if colname is provided, the first row is always a character - int8_t vtyp = (ColNames && j == 0) ? character : vtyp_i; - SEXP vals_sexp = STRING_ELT(cvec, j); - const char* vals = CHAR(vals_sexp); + int8_t vtyp = (ColNames && j == 0) ? character : vtyp_i; + SEXP vals_sexp = STRING_ELT(cvec, j); + const char *vals = CHAR(vals_sexp); - const std::string& row = srows[static_cast(j)]; + const std::string &row = srows[static_cast(j)]; R_xlen_t pos = (j * m) + i; @@ -477,8 +476,7 @@ void wide_to_long( else string_nums = in_string_nums; - switch(vtyp) - { + switch (vtyp) { case currency: case short_date: @@ -494,7 +492,7 @@ void wide_to_long( break; case logical: // v and c_t = "b" - SET_STRING_ELT(zz_v, pos, vals_sexp); + SET_STRING_ELT(zz_v, pos, vals_sexp); SET_STRING_ELT(zz_c_t, pos, bool_sexp); break; case factor: @@ -504,17 +502,17 @@ void wide_to_long( if (string_nums && is_double(vals)) { // v SET_STRING_ELT(zz_v, pos, vals_sexp); - vtyp = (string_nums == 1) ? string_num : numeric; + vtyp = (string_nums == 1) ? string_num : numeric; } else { // check if we write sst or inlineStr if (inline_strings) { - // is and c_t = "inlineStr" - SET_STRING_ELT(zz_c_t, pos, inlineStr_sexp); - SET_STRING_ELT(zz_is, pos, Rf_mkChar(txt_to_is(vals, 0, 1, 1).c_str())); - } else { - // v and c_t = "s" - SET_STRING_ELT(zz_c_t, pos, sharedStr_sexp); - SET_STRING_ELT(zz_v, pos, Rf_mkChar(txt_to_si(vals, 0, 1, 1).c_str())); + // is and c_t = "inlineStr" + SET_STRING_ELT(zz_c_t, pos, inlineStr_sexp); + SET_STRING_ELT(zz_is, pos, Rf_mkChar(txt_to_is(vals, 0, 1, 1).c_str())); + } else { + // v and c_t = "s" + SET_STRING_ELT(zz_c_t, pos, sharedStr_sexp); + SET_STRING_ELT(zz_v, pos, Rf_mkChar(txt_to_si(vals, 0, 1, 1).c_str())); } } break; @@ -522,19 +520,19 @@ void wide_to_long( case formula: // f and c_t = "str"; SET_STRING_ELT(zz_c_t, pos, string_sexp); - SET_STRING_ELT(zz_f, pos, vals_sexp); + SET_STRING_ELT(zz_f, pos, vals_sexp); break; case array_formula: // f, f_t = "array", and f_ref - SET_STRING_ELT(zz_f, pos, vals_sexp); - SET_STRING_ELT(zz_f_t, pos, array_sexp); + SET_STRING_ELT(zz_f, pos, vals_sexp); + SET_STRING_ELT(zz_f_t, pos, array_sexp); SET_STRING_ELT(zz_f_ref, pos, Rf_mkChar(ref_str.c_str())); break; case cm_formula: // c_cm, f, f_t = "array", and f_ref - SET_STRING_ELT(zz_c_cm, pos, Rf_mkChar(c_cm.c_str())); - SET_STRING_ELT(zz_f, pos, vals_sexp); - SET_STRING_ELT(zz_f_t, pos, array_sexp); + SET_STRING_ELT(zz_c_cm, pos, Rf_mkChar(c_cm.c_str())); + SET_STRING_ELT(zz_f, pos, vals_sexp); + SET_STRING_ELT(zz_f_t, pos, array_sexp); SET_STRING_ELT(zz_f_ref, pos, Rf_mkChar(ref_str.c_str())); break; } @@ -543,34 +541,34 @@ void wide_to_long( if (na_missing) { // v = "#N/A" - SET_STRING_ELT(zz_v, pos, na_sexp); + SET_STRING_ELT(zz_v, pos, na_sexp); SET_STRING_ELT(zz_c_t, pos, expr_sexp); // is = "" - required only if inline_strings // and vtyp = character || vtyp = factor - SET_STRING_ELT(zz_is, pos, blank_sexp); - } else { + SET_STRING_ELT(zz_is, pos, blank_sexp); + } else { if (na_null) { - // all three v, c_t, and is = "" - there should be nothing in this row - SET_STRING_ELT(zz_v, pos, blank_sexp); + // all three v, c_t, and is = "" - there should be nothing in this + // row + SET_STRING_ELT(zz_v, pos, blank_sexp); SET_STRING_ELT(zz_c_t, pos, blank_sexp); - SET_STRING_ELT(zz_is, pos, blank_sexp); + SET_STRING_ELT(zz_is, pos, blank_sexp); } else { // c_t = "inlineStr" or "s" - SET_STRING_ELT(zz_c_t, pos, inline_strings ? inlineStr_sexp : sharedStr_sexp); + SET_STRING_ELT(zz_c_t, pos, inline_strings ? inlineStr_sexp : sharedStr_sexp); // for inlineStr is = na_strings else "" - SET_STRING_ELT(zz_is, pos, inline_strings ? na_strings_sexp : blank_sexp); + SET_STRING_ELT(zz_is, pos, inline_strings ? na_strings_sexp : blank_sexp); // otherwise v = na_strings else "" - SET_STRING_ELT(zz_v, pos, !inline_strings ? na_strings_sexp : blank_sexp); + SET_STRING_ELT(zz_v, pos, !inline_strings ? na_strings_sexp : blank_sexp); } } - } else if (strcmp(vals, "NaN") == 0) { // v = "#VALUE!" - SET_STRING_ELT(zz_v, pos, value_sexp); + SET_STRING_ELT(zz_v, pos, value_sexp); SET_STRING_ELT(zz_c_t, pos, expr_sexp); } else if (strcmp(vals, "-Inf") == 0 || strcmp(vals, "Inf") == 0) { // v = "#NUM!" - SET_STRING_ELT(zz_v, pos, num_sexp); + SET_STRING_ELT(zz_v, pos, num_sexp); SET_STRING_ELT(zz_c_t, pos, expr_sexp); } @@ -612,8 +610,8 @@ Rcpp::DataFrame create_char_dataframe(Rcpp::CharacterVector colnames, R_xlen_t n // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = colnames; - df.attr("class") = "data.frame"; + df.attr("names") = colnames; + df.attr("class") = "data.frame"; return df; } @@ -621,31 +619,34 @@ Rcpp::DataFrame create_char_dataframe(Rcpp::CharacterVector colnames, R_xlen_t n // TODO styles_xml.cpp should be converted to use these functions // [[Rcpp::export]] -Rcpp::DataFrame read_xml2df(XPtrXML xml, std::string vec_name, std::vector vec_attrs, std::vector vec_chlds) { +Rcpp::DataFrame read_xml2df( + XPtrXML xml, + std::string vec_name, + std::vector vec_attrs, + std::vector vec_chlds) { std::set nam_attrs(vec_attrs.begin(), vec_attrs.end()); std::set nam_chlds(vec_chlds.begin(), vec_chlds.end()); - auto total_length = nam_attrs.size() + nam_chlds.size(); + auto total_length = nam_attrs.size() + nam_chlds.size(); std::vector all_names(total_length); std::copy(nam_attrs.begin(), nam_attrs.end(), all_names.begin()); - std::copy(nam_chlds.begin(), nam_chlds.end(), all_names.begin() + static_cast(nam_attrs.size())); + std::copy( + nam_chlds.begin(), nam_chlds.end(), all_names.begin() + static_cast(nam_attrs.size())); - std::set nams(std::make_move_iterator(all_names.begin()), - std::make_move_iterator(all_names.end())); + std::set nams( + std::make_move_iterator(all_names.begin()), std::make_move_iterator(all_names.end())); - - R_xlen_t nn = std::distance(xml->begin(), xml->end()); - R_xlen_t kk = static_cast(nams.size()); + R_xlen_t nn = std::distance(xml->begin(), xml->end()); + R_xlen_t kk = static_cast(nams.size()); uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; Rcpp::CharacterVector rvec(nn); // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -655,15 +656,15 @@ Rcpp::DataFrame read_xml2df(XPtrXML xml, std::string vec_name, std::vectorchildren(vec_name.c_str())) { for (auto attrs : xml_node.attributes()) { - std::string attr_name = attrs.name(); + std::string attr_name = attrs.name(); std::string attr_value = attrs.value(); - auto find_res = nams.find(attr_name); + auto find_res = nams.find(attr_name); // check if name is already known if (nams.count(attr_name) == 0) { Rcpp::warning("%s: not found in %s name table", attr_name, vec_name); } else { - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = attr_value; } } @@ -671,7 +672,7 @@ Rcpp::DataFrame read_xml2df(XPtrXML xml, std::string vec_name, std::vector(df[mtc])[itr] = cld_value; } } rvec[itr] = std::to_string(itr); ++itr; - } // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] -Rcpp::CharacterVector write_df2xml(Rcpp::DataFrame df, std::string vec_name, std::vector vec_attrs, std::vector vec_chlds) { +Rcpp::CharacterVector write_df2xml( + Rcpp::DataFrame df, + std::string vec_name, + std::vector vec_attrs, + std::vector vec_chlds) { - int64_t n = df.nrow(); + int64_t n = df.nrow(); Rcpp::CharacterVector z(n); - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; // openxml 2.8.1 - std::vector attrnams = df.names(); - std::set nam_attrs(vec_attrs.begin(), vec_attrs.end()); - std::set nam_chlds(vec_chlds.begin(), vec_chlds.end()); + std::vector attrnams = df.names(); + std::set nam_attrs(vec_attrs.begin(), vec_attrs.end()); + std::set nam_chlds(vec_chlds.begin(), vec_chlds.end()); for (int64_t i = 0; i < n; ++i) { pugi::xml_document doc; - pugi::xml_node xml_node = doc.append_child(vec_name.c_str()); + pugi::xml_node xml_node = doc.append_child(vec_name.c_str()); for (auto j = 0; j < df.ncol(); ++j) { @@ -737,30 +741,30 @@ Rcpp::CharacterVector write_df2xml(Rcpp::DataFrame df, std::string vec_name, std // check if name is already known if (nam_attrs.count(attr_j) != 0) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df[j])[i]; + cv_s = Rcpp::as(df[j])[i]; // only write attributes where cv_s has a value if (cv_s[0] != "") { // Rf_PrintValue(cv_s); - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); xml_node.append_attribute(attr_j.c_str()) = val_strl.c_str(); } } if (nam_chlds.count(attr_j) != 0) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df[j])[i]; + cv_s = Rcpp::as(df[j])[i]; if (cv_s[0] != "") { std::string child_i = Rcpp::as(cv_s[0]); - pugi::xml_document xml_child; + pugi::xml_document xml_child; pugi::xml_parse_result result = xml_child.load_string(child_i.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading %s child node fail: %s", vec_name, cv_s); + if (!result) + Rcpp::stop("loading %s child node fail: %s", vec_name, cv_s); xml_node.append_copy(xml_child.first_child()); - } } diff --git a/src/load_workbook.cpp b/src/load_workbook.cpp index 36bb6b054..b0ac591ed 100644 --- a/src/load_workbook.cpp +++ b/src/load_workbook.cpp @@ -4,7 +4,7 @@ // [[Rcpp::export]] Rcpp::DataFrame col_to_df(XPtrXML doc) { - std::set col_nams= { + std::set col_nams = { "bestFit", "collapsed", "customWidth", @@ -14,8 +14,7 @@ Rcpp::DataFrame col_to_df(XPtrXML doc) { "outlineLevel", "phonetic", "style", - "width" - }; + "width"}; R_xlen_t nn = std::distance(doc->begin(), doc->end()); R_xlen_t kk = static_cast(col_nams.size()); @@ -24,8 +23,7 @@ Rcpp::DataFrame col_to_df(XPtrXML doc) { // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -35,18 +33,17 @@ Rcpp::DataFrame col_to_df(XPtrXML doc) { for (auto col : doc->children("col")) { for (auto attrs : col.attributes()) { - std::string attr_name = attrs.name(); + std::string attr_name = attrs.name(); std::string attr_value = attrs.value(); - auto find_res = col_nams.find(attr_name); + auto find_res = col_nams.find(attr_name); // check if name is already known if (col_nams.count(attr_name) == 0) { Rcpp::Rcout << attr_name << ": not found in col name table" << std::endl; } else { - R_xlen_t mtc = std::distance(col_nams.begin(), find_res); + R_xlen_t mtc = std::distance(col_nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = attr_value; } - } // rownames as character vectors matching to @@ -57,33 +54,32 @@ Rcpp::DataFrame col_to_df(XPtrXML doc) { // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = col_nams; - df.attr("class") = "data.frame"; + df.attr("names") = col_nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector df_to_xml(std::string name, Rcpp::DataFrame df_col) { - auto n = df_col.nrow(); + auto n = df_col.nrow(); Rcpp::CharacterVector z(n); for (auto i = 0; i < n; ++i) { - pugi::xml_document doc; + pugi::xml_document doc; Rcpp::CharacterVector attrnams = df_col.names(); pugi::xml_node col = doc.append_child(name.c_str()); for (auto j = 0; j < df_col.ncol(); ++j) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_col[j])[i]; + cv_s = Rcpp::as(df_col[j])[i]; // only write attributes where cv_s has a value if (cv_s[0] != "") { // Rf_PrintValue(cv_s); - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); col.append_attribute(attrnams[j]) = val_strl.c_str(); } } @@ -97,12 +93,11 @@ Rcpp::CharacterVector df_to_xml(std::string name, Rcpp::DataFrame df_col) { return z; } - inline Rcpp::DataFrame row_to_df(XPtrXML doc) { auto ws = doc->child("worksheet").child("sheetData"); - std::set row_nams { + std::set row_nams{ "r", "spans", "s", @@ -115,8 +110,7 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) { "outlineLevel", "ph", "thickBot", - "thickTop" - }; + "thickTop"}; R_xlen_t nn = std::distance(ws.children("row").begin(), ws.children("row").end()); R_xlen_t kk = static_cast(row_nams.size()); @@ -125,8 +119,7 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) { // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -137,7 +130,7 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) { bool has_rowname = false; for (auto attrs : row.attributes()) { - std::string attr_name = attrs.name(); + std::string attr_name = attrs.name(); std::string attr_value = attrs.value(); // mimic which @@ -147,18 +140,18 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) { if (row_nams.count(attr_name) == 0) { Rcpp::Rcout << attr_name << ": not found in row name table" << std::endl; } else { - R_xlen_t mtc = std::distance(row_nams.begin(), find_res); + R_xlen_t mtc = std::distance(row_nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = attr_value; - if (attr_name == "r") has_rowname = true; + if (attr_name == "r") + has_rowname = true; } - } // some files have no row name in this case, we add one if (!has_rowname) { - std::string attr_name = "r"; - auto find_res = row_nams.find(attr_name); - R_xlen_t mtc = std::distance(row_nams.begin(), find_res); + std::string attr_name = "r"; + auto find_res = row_nams.find(attr_name); + R_xlen_t mtc = std::distance(row_nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = std::to_string(itr + 1); } @@ -170,8 +163,8 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) { // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = row_nams; - df.attr("class") = "data.frame"; + df.attr("names") = row_nams; + df.attr("class") = "data.frame"; return df; } @@ -188,21 +181,19 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) { std::vector xml_cols; // we check against these - const std::string f_str = "f"; - const std::string r_str = "r"; - const std::string s_str = "s"; - const std::string t_str = "t"; - const std::string v_str = "v"; - const std::string ca_str = "ca"; - const std::string cm_str = "cm"; - const std::string is_str = "is"; - const std::string ph_str = "ph"; - const std::string si_str = "si"; - const std::string vm_str = "vm"; + const std::string f_str = "f"; + const std::string r_str = "r"; + const std::string s_str = "s"; + const std::string t_str = "t"; + const std::string v_str = "v"; + const std::string ca_str = "ca"; + const std::string cm_str = "cm"; + const std::string is_str = "is"; + const std::string ph_str = "ph"; + const std::string si_str = "si"; + const std::string vm_str = "vm"; const std::string ref_str = "ref"; - - /***************************************************************************** * Row information is returned as list of lists returning as much as possible. * @@ -212,7 +203,7 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) { row_attributes = row_to_df(doc); R_xlen_t idx = 0, itr_rows = 0; - for (auto worksheet: ws.children("row")) { + for (auto worksheet : ws.children("row")) { /* ---------------------------------------------------------------------- */ /* read cval, and ctyp -------------------------------------------------- */ @@ -236,7 +227,7 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) { bool has_colname = false; for (auto attr : col.attributes()) { - buffer = attr.value(); + buffer = attr.value(); attr_name = attr.name(); if (attr_name == r_str) { @@ -246,7 +237,7 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) { // get col name single_xml_col.c_r = rm_rownum(buffer); - has_colname = true; + has_colname = true; // get colnum single_xml_col.row_r = rm_colnum(buffer); @@ -254,28 +245,31 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) { // if some cells of the workbook have colnames but other dont, // this will increase itr_cols and avoid duplicates in cc itr_cols = static_cast(uint_col_to_int(single_xml_col.c_r) - 1); - } - if (attr_name == s_str) single_xml_col.c_s = buffer; - if (attr_name == t_str) single_xml_col.c_t = buffer; - if (attr_name == cm_str) single_xml_col.c_cm = buffer; - if (attr_name == ph_str) single_xml_col.c_ph = buffer; - if (attr_name == vm_str) single_xml_col.c_vm = buffer; - + if (attr_name == s_str) + single_xml_col.c_s = buffer; + if (attr_name == t_str) + single_xml_col.c_t = buffer; + if (attr_name == cm_str) + single_xml_col.c_cm = buffer; + if (attr_name == ph_str) + single_xml_col.c_ph = buffer; + if (attr_name == vm_str) + single_xml_col.c_vm = buffer; } // some files have no colnames. in this case we need to add c_r and row_r // if the file provides dimensions, they could be fixed later if (!has_colname) { - single_xml_col.c_r = int_to_col(itr_cols + 1); + single_xml_col.c_r = int_to_col(itr_cols + 1); single_xml_col.row_r = std::to_string(itr_rows + 1); - single_xml_col.r = single_xml_col.c_r + single_xml_col.row_r; + single_xml_col.r = single_xml_col.c_r + single_xml_col.row_r; } // val ------------------------------------------------------------------ if (nn > 0) { - for (auto val: col.children()) { + for (auto val : col.children()) { val_name = val.name(); @@ -297,21 +291,24 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) { // * ref= // * ca= // * si= - for (auto cattr : val.attributes()) - { - buffer = cattr.value(); + for (auto cattr : val.attributes()) { + buffer = cattr.value(); cattr_name = cattr.name(); - if (cattr_name == t_str) single_xml_col.f_t = buffer; - if (cattr_name == ref_str) single_xml_col.f_ref = buffer; - if (cattr_name == ca_str) single_xml_col.f_ca = buffer; - if (cattr_name == si_str) single_xml_col.f_si = buffer; + if (cattr_name == t_str) + single_xml_col.f_t = buffer; + if (cattr_name == ref_str) + single_xml_col.f_ref = buffer; + if (cattr_name == ca_str) + single_xml_col.f_ca = buffer; + if (cattr_name == si_str) + single_xml_col.f_si = buffer; } } // // - if (val_name == v_str) single_xml_col.v = val.text().get(); - + if (val_name == v_str) + single_xml_col.v = val.text().get(); } /* row is done */ @@ -322,12 +319,11 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) { ++itr_cols; } - /* ---------------------------------------------------------------------- */ ++itr_rows; } sheet_data["row_attr"] = row_attributes; - sheet_data["cc"] = Rcpp::wrap(xml_cols); + sheet_data["cc"] = Rcpp::wrap(xml_cols); } diff --git a/src/pugi.cpp b/src/pugi.cpp index e321fbf40..3707e68fe 100644 --- a/src/pugi.cpp +++ b/src/pugi.cpp @@ -1,17 +1,29 @@ #include "openxlsx2.h" // [[Rcpp::export]] -SEXP readXML(std::string path, bool isfile, bool escapes, bool declaration, bool whitespace, bool empty_tags, bool skip_control, bool pointer) { - - xmldoc *doc = new xmldoc; +SEXP readXML( + std::string path, + bool isfile, + bool escapes, + bool declaration, + bool whitespace, + bool empty_tags, + bool skip_control, + bool pointer) { + + xmldoc *doc = new xmldoc; pugi::xml_parse_result result; // pugi::parse_default without escapes flag uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_eol; - if (escapes) pugi_parse_flags |= pugi::parse_escapes; - if (declaration) pugi_parse_flags |= pugi::parse_declaration; - if (whitespace) pugi_parse_flags |= pugi::parse_ws_pcdata_single; - if (!whitespace) pugi_parse_flags |= pugi::parse_trim_pcdata; + if (escapes) + pugi_parse_flags |= pugi::parse_escapes; + if (declaration) + pugi_parse_flags |= pugi::parse_declaration; + if (whitespace) + pugi_parse_flags |= pugi::parse_ws_pcdata_single; + if (!whitespace) + pugi_parse_flags |= pugi::parse_trim_pcdata; if (isfile) { result = doc->load_file(path.c_str(), pugi_parse_flags, pugi::encoding_utf8); @@ -24,33 +36,39 @@ SEXP readXML(std::string path, bool isfile, bool escapes, bool declaration, bool } uint32_t pugi_format_flags = pugi::format_raw; - if (!escapes) pugi_format_flags |= pugi::format_no_escapes; - if (empty_tags) pugi_format_flags |= pugi::format_no_empty_element_tags; - if (skip_control) pugi_format_flags |= pugi::format_skip_control_chars; + if (!escapes) + pugi_format_flags |= pugi::format_no_escapes; + if (empty_tags) + pugi_format_flags |= pugi::format_no_empty_element_tags; + if (skip_control) + pugi_format_flags |= pugi::format_skip_control_chars; if (pointer) { XPtrXML ptr(doc, true); - ptr.attr("class") = Rcpp::CharacterVector::create("pugi_xml"); - ptr.attr("escapes") = escapes; - ptr.attr("empty_tags") = empty_tags; + ptr.attr("class") = Rcpp::CharacterVector::create("pugi_xml"); + ptr.attr("escapes") = escapes; + ptr.attr("empty_tags") = empty_tags; ptr.attr("skip_control") = skip_control; return ptr; } std::ostringstream oss; doc->print(oss, " ", pugi_format_flags); - return Rcpp::wrap(Rcpp::String(oss.str())); + return Rcpp::wrap(Rcpp::String(oss.str())); } -inline uint32_t pugi_format(XPtrXML doc){ - bool escapes = Rcpp::as(doc.attr("escapes")); - bool empty_tags = Rcpp::as(doc.attr("empty_tags")); +inline uint32_t pugi_format(XPtrXML doc) { + bool escapes = Rcpp::as(doc.attr("escapes")); + bool empty_tags = Rcpp::as(doc.attr("empty_tags")); bool skip_control = Rcpp::as(doc.attr("skip_control")); uint32_t pugi_format_flags = pugi::format_raw; - if (!escapes) pugi_format_flags |= pugi::format_no_escapes; - if (empty_tags) pugi_format_flags |= pugi::format_no_empty_element_tags; - if (skip_control) pugi_format_flags |= pugi::format_skip_control_chars; + if (!escapes) + pugi_format_flags |= pugi::format_no_escapes; + if (empty_tags) + pugi_format_flags |= pugi::format_no_empty_element_tags; + if (skip_control) + pugi_format_flags |= pugi::format_skip_control_chars; return pugi_format_flags; } @@ -58,7 +76,7 @@ inline uint32_t pugi_format(XPtrXML doc){ // [[Rcpp::export]] Rcpp::LogicalVector is_xml(std::string str) { - pugi::xml_document doc; + pugi::xml_document doc; pugi::xml_parse_result result; result = doc.load_string(str.c_str()); @@ -74,12 +92,11 @@ SEXP getXMLXPtrName1(XPtrXML doc) { vec_string res; - for (auto lvl0 : doc->children()) - { + for (auto lvl0 : doc->children()) { res.push_back(lvl0.name()); } - return Rcpp::wrap(res); + return Rcpp::wrap(res); } // [[Rcpp::export]] @@ -87,15 +104,13 @@ SEXP getXMLXPtrName2(XPtrXML doc, std::string level1) { vec_string res; - for (auto lvl0 : doc->children(level1.c_str())) - { - for (auto lvl1 : lvl0.children()) - { + for (auto lvl0 : doc->children(level1.c_str())) { + for (auto lvl1 : lvl0.children()) { res.push_back(lvl1.name()); } } - return Rcpp::wrap(res); + return Rcpp::wrap(res); } // [[Rcpp::export]] @@ -103,58 +118,52 @@ SEXP getXMLXPtrName3(XPtrXML doc, std::string level1, std::string level2) { vec_string res; - for (auto lvl0 : doc->children(level1.c_str())) - { - for (auto lvl1 : lvl0.children()) - { - for (auto lvl2 : lvl1.children()) - { + for (auto lvl0 : doc->children(level1.c_str())) { + for (auto lvl1 : lvl0.children()) { + for (auto lvl2 : lvl1.children()) { res.push_back(lvl2.name()); } } } - return Rcpp::wrap(res); + return Rcpp::wrap(res); } // [[Rcpp::export]] SEXP getXMLXPtr0(XPtrXML doc) { vec_string res; - uint32_t pugi_format_flags = pugi_format(doc); + uint32_t pugi_format_flags = pugi_format(doc); - for (auto worksheet : doc->children()) - { + for (auto worksheet : doc->children()) { std::ostringstream oss; worksheet.print(oss, " ", pugi_format_flags); res.push_back(Rcpp::String(oss.str())); } - return Rcpp::wrap(res); + return Rcpp::wrap(res); } // [[Rcpp::export]] SEXP getXMLXPtr1(XPtrXML doc, std::string child) { vec_string res; - uint32_t pugi_format_flags = pugi_format(doc); + uint32_t pugi_format_flags = pugi_format(doc); - for (auto cld : doc->children(child.c_str())) - { + for (auto cld : doc->children(child.c_str())) { std::ostringstream oss; cld.print(oss, " ", pugi_format_flags); res.push_back(Rcpp::String(oss.str())); } - return Rcpp::wrap(res); + return Rcpp::wrap(res); } - // [[Rcpp::export]] SEXP getXMLXPtr2(XPtrXML doc, std::string level1, std::string child) { vec_string res; - uint32_t pugi_format_flags = pugi_format(doc); + uint32_t pugi_format_flags = pugi_format(doc); for (auto lvl1 : doc->children(level1.c_str())) { for (auto cld : lvl1.children(child.c_str())) { @@ -164,14 +173,14 @@ SEXP getXMLXPtr2(XPtrXML doc, std::string level1, std::string child) { } } - return Rcpp::wrap(res); + return Rcpp::wrap(res); } // [[Rcpp::export]] SEXP getXMLXPtr3(XPtrXML doc, std::string level1, std::string level2, std::string child) { vec_string res; - uint32_t pugi_format_flags = pugi_format(doc); + uint32_t pugi_format_flags = pugi_format(doc); for (auto lvl1 : doc->children(level1.c_str())) { for (auto lvl2 : lvl1.children(level2.c_str())) { @@ -183,7 +192,7 @@ SEXP getXMLXPtr3(XPtrXML doc, std::string level1, std::string level2, std::strin } } - return Rcpp::wrap(res); + return Rcpp::wrap(res); } // level2 is wildcard. (for border only color nodes are imported. @@ -192,7 +201,7 @@ SEXP getXMLXPtr3(XPtrXML doc, std::string level1, std::string level2, std::strin SEXP unkgetXMLXPtr3(XPtrXML doc, std::string level1, std::string child) { vec_string res; - uint32_t pugi_format_flags = pugi_format(doc); + uint32_t pugi_format_flags = pugi_format(doc); for (auto lvl1 : doc->children(level1.c_str())) { for (auto lvl2 : lvl1.children()) { @@ -204,17 +213,16 @@ SEXP unkgetXMLXPtr3(XPtrXML doc, std::string level1, std::string child) { } } - return Rcpp::wrap(res); + return Rcpp::wrap(res); } // [[Rcpp::export]] SEXP getXMLPtr1con(XPtrXML doc) { vec_string res; - uint32_t pugi_format_flags = pugi_format(doc); + uint32_t pugi_format_flags = pugi_format(doc); - for (auto node : doc->children()) - { + for (auto node : doc->children()) { for (auto cld : node.children()) { std::ostringstream oss; cld.print(oss, " ", pugi_format_flags); @@ -222,7 +230,7 @@ SEXP getXMLPtr1con(XPtrXML doc) { } } - return Rcpp::wrap(res); + return Rcpp::wrap(res); } // [[Rcpp::export]] @@ -231,12 +239,11 @@ SEXP getXMLXPtr1val(XPtrXML doc, std::string child) { // returns a single vector, not a list of vectors! std::vector x; - for (auto worksheet : doc->children(child.c_str())) - { + for (auto worksheet : doc->children(child.c_str())) { x.push_back(Rcpp::String(worksheet.text().get())); } - return Rcpp::wrap(x); + return Rcpp::wrap(x); } // [[Rcpp::export]] @@ -252,7 +259,7 @@ SEXP getXMLXPtr2val(XPtrXML doc, std::string level1, std::string child) { } } - return Rcpp::wrap(x); + return Rcpp::wrap(x); } // [[Rcpp::export]] @@ -261,37 +268,34 @@ SEXP getXMLXPtr3val(XPtrXML doc, std::string level1, std::string level2, std::st // returns a single vector, not a list of vectors! std::vector x; - for (auto worksheet : doc->child(level1.c_str()).children(level2.c_str())) - { + for (auto worksheet : doc->child(level1.c_str()).children(level2.c_str())) { for (auto col : worksheet.children(child.c_str())) x.push_back(Rcpp::String(col.text().get())); } - return Rcpp::wrap(x); + return Rcpp::wrap(x); } - // [[Rcpp::export]] SEXP getXMLXPtr1attr(XPtrXML doc, std::string child) { auto children = doc->children(child.c_str()); - R_xlen_t n = std::distance(children.begin(), - children.end()); + R_xlen_t n = std::distance(children.begin(), children.end()); // for a childless single line node the distance might be zero - if (n == 0) n++; + if (n == 0) + n++; Rcpp::List z(n); auto itr = 0; for (auto chld : children) { - Rcpp::CharacterVector res; + Rcpp::CharacterVector res; std::vector nam; - for (auto attrs : chld.attributes()) - { + for (auto attrs : chld.attributes()) { nam.push_back(Rcpp::String(attrs.name())); res.push_back(Rcpp::String(attrs.value())); } @@ -309,13 +313,12 @@ SEXP getXMLXPtr1attr(XPtrXML doc, std::string child) { // [[Rcpp::export]] Rcpp::List getXMLXPtr2attr(XPtrXML doc, std::string level1, std::string child) { - auto worksheet = doc->child(level1.c_str()).children(child.c_str()); - R_xlen_t n = std::distance(worksheet.begin() , worksheet.end()); + auto worksheet = doc->child(level1.c_str()).children(child.c_str()); + R_xlen_t n = std::distance(worksheet.begin(), worksheet.end()); Rcpp::List z(n); auto itr = 0; - for (auto ws : worksheet) - { + for (auto ws : worksheet) { R_xlen_t w_n = std::distance(ws.attributes_begin(), ws.attributes_end()); @@ -323,8 +326,7 @@ Rcpp::List getXMLXPtr2attr(XPtrXML doc, std::string level1, std::string child) { Rcpp::CharacterVector nam(w_n); auto attr_itr = 0; - for (auto attr : ws.attributes()) - { + for (auto attr : ws.attributes()) { nam[attr_itr] = Rcpp::String(attr.name()); res[attr_itr] = Rcpp::String(attr.value()); ++attr_itr; @@ -343,13 +345,12 @@ Rcpp::List getXMLXPtr2attr(XPtrXML doc, std::string level1, std::string child) { // [[Rcpp::export]] SEXP getXMLXPtr3attr(XPtrXML doc, std::string level1, std::string level2, std::string child) { - auto worksheet = doc->child(level1.c_str()).child(level2.c_str()).children(child.c_str()); - R_xlen_t n = std::distance(worksheet.begin(), worksheet.end()); + auto worksheet = doc->child(level1.c_str()).child(level2.c_str()).children(child.c_str()); + R_xlen_t n = std::distance(worksheet.begin(), worksheet.end()); Rcpp::List z(n); auto itr = 0; - for (auto ws : worksheet) - { + for (auto ws : worksheet) { R_xlen_t w_n = std::distance(ws.attributes_begin(), ws.attributes_end()); @@ -357,8 +358,7 @@ SEXP getXMLXPtr3attr(XPtrXML doc, std::string level1, std::string level2, std::s Rcpp::CharacterVector nam(w_n); auto attr_itr = 0; - for (auto attr : ws.attributes()) - { + for (auto attr : ws.attributes()) { nam[attr_itr] = Rcpp::String(attr.name()); res[attr_itr] = Rcpp::String(attr.value()); ++attr_itr; @@ -374,7 +374,6 @@ SEXP getXMLXPtr3attr(XPtrXML doc, std::string level1, std::string level2, std::s return z; } - // [[Rcpp::export]] SEXP printXPtr(XPtrXML doc, std::string indent, bool raw, bool attr_indent) { @@ -385,7 +384,8 @@ SEXP printXPtr(XPtrXML doc, std::string indent, bool raw, bool attr_indent) { pugi_format_flags &= ~pugi::format_raw; pugi_format_flags |= pugi::format_indent; } - if (attr_indent) pugi_format_flags |= pugi::format_indent_attributes; + if (attr_indent) + pugi_format_flags |= pugi::format_indent_attributes; std::ostringstream oss; doc->print(oss, indent.c_str(), pugi_format_flags); @@ -393,27 +393,29 @@ SEXP printXPtr(XPtrXML doc, std::string indent, bool raw, bool attr_indent) { return Rcpp::wrap(Rcpp::String(oss.str())); } - // [[Rcpp::export]] XPtrXML write_xml_file(std::string xml_content, bool escapes) { xmldoc *doc = new xmldoc; // pugi::parse_default without escapes flag - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; - if (escapes) pugi_parse_flags |= pugi::parse_escapes; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + if (escapes) + pugi_parse_flags |= pugi::parse_escapes; // load and validate node if (xml_content != "") { pugi::xml_parse_result result; result = doc->load_string(xml_content.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("Loading xml_content node failed: \n %s", xml_content); + if (!result) + Rcpp::stop("Loading xml_content node failed: \n %s", xml_content); } // Needs to be added after the node has been loaded and validated - pugi::xml_node decl = doc->prepend_child(pugi::node_declaration); - decl.append_attribute("version") = "1.0"; - decl.append_attribute("encoding") = "UTF-8"; + pugi::xml_node decl = doc->prepend_child(pugi::node_declaration); + decl.append_attribute("version") = "1.0"; + decl.append_attribute("encoding") = "UTF-8"; decl.append_attribute("standalone") = "yes"; XPtrXML ptr(doc, true); @@ -440,49 +442,57 @@ XPtrXML write_xml_file(std::string xml_content, bool escapes) { //' //' @examples //' # add single node -//' xml_node <- "openxlsx2" -//' xml_attr <- c(qux = "quux") -//' # "openxlsx2" -//' xml_attr_mod(xml_node, xml_attr) +//' xml_node <- "openxlsx2" +//' xml_attr <- c(qux = "quux") +//' # "openxlsx2" +//' xml_attr_mod(xml_node, xml_attr) //' //' # update node and add node -//' xml_node <- "openxlsx2" -//' xml_attr <- c(foo = "baz", qux = "quux") -//' # "openxlsx2" -//' xml_attr_mod(xml_node, xml_attr) +//' xml_node <- "openxlsx2" +//' xml_attr <- c(foo = "baz", qux = "quux") +//' # "openxlsx2" +//' xml_attr_mod(xml_node, xml_attr) //' //' # remove node and add node -//' xml_node <- "openxlsx2" -//' xml_attr <- c(foo = "", qux = "quux") -//' # "openxlsx2" -//' xml_attr_mod(xml_node, xml_attr) +//' xml_node <- "openxlsx2" +//' xml_attr <- c(foo = "", qux = "quux") +//' # "openxlsx2" +//' xml_attr_mod(xml_node, xml_attr) //' @export // [[Rcpp::export]] -Rcpp::CharacterVector xml_attr_mod(std::string xml_content, Rcpp::CharacterVector xml_attributes, - bool escapes = false, bool declaration = false, - bool remove_empty_attr = true) { - - pugi::xml_document doc; +Rcpp::CharacterVector xml_attr_mod( + std::string xml_content, + Rcpp::CharacterVector xml_attributes, + bool escapes = false, + bool declaration = false, + bool remove_empty_attr = true) { + + pugi::xml_document doc; pugi::xml_parse_result result; - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; - if (escapes) pugi_parse_flags |= pugi::parse_escapes; - if (declaration) pugi_parse_flags |= pugi::parse_declaration; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + if (escapes) + pugi_parse_flags |= pugi::parse_escapes; + if (declaration) + pugi_parse_flags |= pugi::parse_declaration; uint32_t pugi_format_flags = pugi::format_raw; - if (!escapes) pugi_format_flags |= pugi::format_no_escapes; + if (!escapes) + pugi_format_flags |= pugi::format_no_escapes; // load and validate node if (xml_content != "") { result = doc.load_string(xml_content.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("Loading xml_content node failed: \n %s ", xml_content); + if (!result) + Rcpp::stop("Loading xml_content node failed: \n %s ", xml_content); } std::vector new_attr_nam = xml_attributes.names(); std::vector new_attr_val = Rcpp::as>(xml_attributes); for (auto cld : doc.children()) { - for (size_t i = 0; i < static_cast(xml_attributes.length()); ++i){ + for (size_t i = 0; i < static_cast(xml_attributes.length()); ++i) { // check if attribute_val is empty. if yes, remove the attribute. // otherwise add or update the attribute @@ -534,19 +544,24 @@ Rcpp::CharacterVector xml_attr_mod(std::string xml_content, Rcpp::CharacterVecto //' @export // [[Rcpp::export]] Rcpp::CharacterVector xml_node_create( - std::string xml_name, - Rcpp::Nullable xml_children = R_NilValue, - Rcpp::Nullable xml_attributes = R_NilValue, - bool escapes = false, bool declaration = false) { + std::string xml_name, + Rcpp::Nullable xml_children = R_NilValue, + Rcpp::Nullable xml_attributes = R_NilValue, + bool escapes = false, + bool declaration = false) { pugi::xml_document doc; - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; - if (escapes) pugi_parse_flags |= pugi::parse_escapes; - if (declaration) pugi_parse_flags |= pugi::parse_declaration; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + if (escapes) + pugi_parse_flags |= pugi::parse_escapes; + if (declaration) + pugi_parse_flags |= pugi::parse_declaration; uint32_t pugi_format_flags = pugi::format_raw; - if (!escapes) pugi_format_flags |= pugi::format_no_escapes; + if (!escapes) + pugi_format_flags |= pugi::format_no_escapes; pugi::xml_node cld = doc.append_child(xml_name.c_str()); @@ -559,7 +574,7 @@ Rcpp::CharacterVector xml_node_create( std::string xml_cld = std::string(xml_child[i]); - pugi::xml_document is_node; + pugi::xml_document is_node; pugi::xml_parse_result result = is_node.load_string(xml_cld.c_str(), pugi_parse_flags); // check if result is a valid xml_node, else append as is @@ -580,7 +595,7 @@ Rcpp::CharacterVector xml_node_create( std::vector new_attr_nam = xml_attr.names(); std::vector new_attr_val = Rcpp::as>(xml_attr); - for (size_t i = 0; i < static_cast(xml_attr.length()); ++i){ + for (size_t i = 0; i < static_cast(xml_attr.length()); ++i) { if (!new_attr_val[i].empty()) cld.append_attribute(new_attr_nam[i].c_str()) = new_attr_val[i].c_str(); } @@ -602,7 +617,7 @@ SEXP xml_append_child1(XPtrXML node, XPtrXML child, bool pointer) { uint32_t pugi_format_flags = pugi_format(node); - for (auto cld: child->children()) { + for (auto cld : child->children()) { node->first_child().append_copy(cld); } @@ -626,7 +641,7 @@ SEXP xml_append_child2(XPtrXML node, XPtrXML child, std::string level1, bool poi uint32_t pugi_format_flags = pugi_format(node); - for (auto cld: child->children()) { + for (auto cld : child->children()) { node->first_child().child(level1.c_str()).append_copy(cld); } @@ -647,11 +662,12 @@ SEXP xml_append_child2(XPtrXML node, XPtrXML child, std::string level1, bool poi // @param pointer bool if pointer should be returned // @export // [[Rcpp::export]] -SEXP xml_append_child3(XPtrXML node, XPtrXML child, std::string level1, std::string level2, bool pointer) { +SEXP xml_append_child3( + XPtrXML node, XPtrXML child, std::string level1, std::string level2, bool pointer) { uint32_t pugi_format_flags = pugi_format(node); - for (auto cld: child->children()) { + for (auto cld : child->children()) { node->first_child().child(level1.c_str()).child(level2.c_str()).append_copy(cld); } @@ -676,10 +692,11 @@ SEXP xml_remove_child1(XPtrXML node, std::string child, int32_t which, bool poin uint32_t pugi_format_flags = pugi_format(node); auto ctr = 0; - for (pugi::xml_node cld = node->first_child().child(child.c_str()); cld; ) { + for (pugi::xml_node cld = node->first_child().child(child.c_str()); cld;) { auto next = cld.next_sibling(); - if (ctr == which || which < 0) cld.parent().remove_child(cld); - cld = next; + if (ctr == which || which < 0) + cld.parent().remove_child(cld); + cld = next; ++ctr; } @@ -700,14 +717,16 @@ SEXP xml_remove_child1(XPtrXML node, std::string child, int32_t which, bool poin // @param escapes bool if escapes should be used // @export // [[Rcpp::export]] -SEXP xml_remove_child2(XPtrXML node, std::string child, std::string level1, int32_t which, bool pointer) { +SEXP xml_remove_child2( + XPtrXML node, std::string child, std::string level1, int32_t which, bool pointer) { uint32_t pugi_format_flags = pugi_format(node); auto ctr = 0; - for (pugi::xml_node cld = node->first_child().child(level1.c_str()).child(child.c_str()); cld; ) { + for (pugi::xml_node cld = node->first_child().child(level1.c_str()).child(child.c_str()); cld;) { auto next = cld.next_sibling(); - if (ctr == which || which < 0) cld.parent().remove_child(cld); + if (ctr == which || which < 0) + cld.parent().remove_child(cld); cld = next; ++ctr; } @@ -730,14 +749,23 @@ SEXP xml_remove_child2(XPtrXML node, std::string child, std::string level1, int3 // @param escapes bool if escapes should be used // @export // [[Rcpp::export]] -SEXP xml_remove_child3(XPtrXML node, std::string child, std::string level1, std::string level2, int32_t which, bool pointer) { +SEXP xml_remove_child3( + XPtrXML node, + std::string child, + std::string level1, + std::string level2, + int32_t which, + bool pointer) { uint32_t pugi_format_flags = pugi_format(node); auto ctr = 0; - for (pugi::xml_node cld = node->first_child().child(level1.c_str()).child(level2.c_str()).child(child.c_str()); cld; ) { + for (pugi::xml_node cld = + node->first_child().child(level1.c_str()).child(level2.c_str()).child(child.c_str()); + cld;) { auto next = cld.next_sibling(); - if (ctr == which || which < 0) cld.parent().remove_child(cld); + if (ctr == which || which < 0) + cld.parent().remove_child(cld); cld = next; ++ctr; } diff --git a/src/strings_xml.cpp b/src/strings_xml.cpp index 893ed5a0e..cd14f5dd2 100644 --- a/src/strings_xml.cpp +++ b/src/strings_xml.cpp @@ -6,13 +6,12 @@ SEXP xml_si_to_txt(XPtrXML doc) { auto sst = doc->child("sst"); - auto n = std::distance(sst.begin(), sst.end()); + auto n = std::distance(sst.begin(), sst.end()); Rcpp::CharacterVector res(Rcpp::no_init(n)); auto i = 0; - for (auto si : doc->child("sst").children("si")) - { + for (auto si : doc->child("sst").children("si")) { // text to export std::string text = ""; @@ -24,7 +23,7 @@ SEXP xml_si_to_txt(XPtrXML doc) { // has r node with t node // linebreaks and spaces are handled in the nodes for (auto r : si.children("r")) { - for (auto t :r.children("t")) { + for (auto t : r.children("t")) { text += t.text().get(); } } @@ -39,7 +38,7 @@ SEXP xml_si_to_txt(XPtrXML doc) { SEXP xml_to_txt(Rcpp::CharacterVector vec, std::string type) { - auto n = vec.length(); + auto n = vec.length(); Rcpp::CharacterVector res(Rcpp::no_init(n)); for (auto i = 0; i < n; ++i) { @@ -51,15 +50,15 @@ SEXP xml_to_txt(Rcpp::CharacterVector vec, std::string type) { continue; } - pugi::xml_document doc; - pugi::xml_parse_result result = doc.load_string(tmp.c_str(), pugi::parse_default | pugi::parse_ws_pcdata | pugi::parse_escapes); + pugi::xml_document doc; + pugi::xml_parse_result result = doc.load_string( + tmp.c_str(), pugi::parse_default | pugi::parse_ws_pcdata | pugi::parse_escapes); if (!result) { Rcpp::stop(type.c_str(), " xml import unsuccessful"); } - for (auto is : doc.children(type.c_str())) - { + for (auto is : doc.children(type.c_str())) { // text to export std::string text = ""; @@ -76,7 +75,7 @@ SEXP xml_to_txt(Rcpp::CharacterVector vec, std::string type) { // t (Text) // linebreaks and spaces are handled in the nodes for (auto r : is.children("r")) { - for (auto t :r.children("t")) { + for (auto t : r.children("t")) { text += t.text().get(); } } @@ -84,7 +83,6 @@ SEXP xml_to_txt(Rcpp::CharacterVector vec, std::string type) { // push everything back res[i] = Rcpp::String(text); } - } return res; @@ -100,38 +98,37 @@ SEXP si_to_txt(Rcpp::CharacterVector si_vec) { return xml_to_txt(si_vec, "si"); } -std::string txt_to_xml( - std::string text, - bool no_escapes, - bool raw, - bool skip_control, - std::string type -) { +std::string +txt_to_xml(std::string text, bool no_escapes, bool raw, bool skip_control, std::string type) { pugi::xml_document doc; uint32_t pugi_format_flags = pugi::format_indent; - if (no_escapes) pugi_format_flags |= pugi::format_no_escapes; - if (raw) pugi_format_flags |= pugi::format_raw; - if (skip_control) pugi_format_flags |= pugi::format_skip_control_chars; + if (no_escapes) + pugi_format_flags |= pugi::format_no_escapes; + if (raw) + pugi_format_flags |= pugi::format_raw; + if (skip_control) + pugi_format_flags |= pugi::format_skip_control_chars; pugi::xml_node is_node = doc.append_child(type.c_str()); // txt input beginning with "", 0) == 0 || text.rfind("", 0) == 0) { - pugi::xml_document txt_node; - pugi::xml_parse_result result = txt_node.load_string(text.c_str(), pugi::parse_default | pugi::parse_ws_pcdata | pugi::parse_escapes); - if (!result) Rcpp::stop("Could not parse xml in txt_to_xml()"); + pugi::xml_document txt_node; + pugi::xml_parse_result result = txt_node.load_string( + text.c_str(), pugi::parse_default | pugi::parse_ws_pcdata | pugi::parse_escapes); + if (!result) + Rcpp::stop("Could not parse xml in txt_to_xml()"); for (auto is_n : txt_node.children()) - is_node.append_copy(is_n); - + is_node.append_copy(is_n); } else { // text to export pugi::xml_node t_node = is_node.append_child("t"); - if ((text.size() > 0) && (std::isspace(text.at(0)) || std::isspace(text.at(text.size()-1)))) { + if ((text.size() > 0) && (std::isspace(text.at(0)) || std::isspace(text.at(text.size() - 1)))) { t_node.append_attribute("xml:space").set_value("preserve"); } @@ -146,13 +143,13 @@ std::string txt_to_xml( } // [[Rcpp::export]] -std::string txt_to_is(std::string text, - bool no_escapes = false, bool raw = true, bool skip_control = true) { +std::string +txt_to_is(std::string text, bool no_escapes = false, bool raw = true, bool skip_control = true) { return txt_to_xml(text, no_escapes, raw, skip_control, "is"); } // [[Rcpp::export]] -std::string txt_to_si(std::string text, - bool no_escapes = false, bool raw = true, bool skip_control = true) { +std::string +txt_to_si(std::string text, bool no_escapes = false, bool raw = true, bool skip_control = true) { return txt_to_xml(text, no_escapes, raw, skip_control, "si"); } diff --git a/src/styles_xml.cpp b/src/styles_xml.cpp index c87eceee1..b8b48e945 100644 --- a/src/styles_xml.cpp +++ b/src/styles_xml.cpp @@ -8,22 +8,22 @@ bool has_it(Rcpp::DataFrame df_xf, std::set xf_nams, R_xlen_t row) // names as vector and set. because set is ordered, we have to change the // order of the data frame columns as well. std::vector df_nms = df_xf.names(); - std::set df_names(df_nms.begin(), df_nms.end()); + std::set df_names(df_nms.begin(), df_nms.end()); std::vector xf_names(xf_nams.begin(), xf_nams.end()); Rcpp::CharacterVector sel_chr; - Rcpp::IntegerVector sel_int; - Rcpp::DataFrame df_tmp; + Rcpp::IntegerVector sel_int; + Rcpp::DataFrame df_tmp; sel_chr = Rcpp::wrap(df_names); - df_tmp = df_xf[sel_chr]; + df_tmp = df_xf[sel_chr]; // get the position of the xf_nams in the sorted df_xf data frame std::vector idx; for (size_t i = 0; i < xf_names.size(); ++i) { std::string xf_name = xf_names[i]; if (df_names.count(xf_name) > 0) { - auto res = df_names.find(xf_name); + auto res = df_names.find(xf_name); R_xlen_t mtc = std::distance(df_names.begin(), res); idx.push_back(mtc); } @@ -31,7 +31,7 @@ bool has_it(Rcpp::DataFrame df_xf, std::set xf_nams, R_xlen_t row) // get a subset of the original data frame sel_int = Rcpp::wrap(idx); - df_tmp = df_tmp[sel_int]; + df_tmp = df_tmp[sel_int]; // check every column of the selected row for (auto ii = 0; ii < df_tmp.ncol(); ++ii) { @@ -55,7 +55,7 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) { // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.cellformat?view=openxml-2.8.1 // openxml 2.8.1 - std::set nams { + std::set nams{ "numFmtId", "fontId", "fillId", @@ -83,8 +83,7 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) { "extLst", // child protection "hidden", - "locked" - }; + "locked"}; R_xlen_t nn = std::distance(xml_doc_xf->begin(), xml_doc_xf->end()); R_xlen_t kk = static_cast(nams.size()); @@ -93,8 +92,7 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) { // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -104,15 +102,15 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) { for (auto xml_xf : xml_doc_xf->children("xf")) { for (auto attrs : xml_xf.attributes()) { - std::string attr_name = attrs.name(); + std::string attr_name = attrs.name(); std::string attr_value = attrs.value(); - auto find_res = nams.find(attr_name); + auto find_res = nams.find(attr_name); // check if name is already known if (nams.count(attr_name) == 0) { Rcpp::warning("%s: not found in xf name table", attr_name); } else { - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = attr_value; } } @@ -126,25 +124,25 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) { std::string cld_name = cld.name(); // check known names - if (cld_name == "alignment" || cld_name == "extLst" || cld_name == "protection") { + if (cld_name == "alignment" || cld_name == "extLst" || cld_name == "protection") { if (cld_name == "extLst") { - R_xlen_t mtc = std::distance(nams.begin(), nams.find(cld_name)); - uint32_t pugi_format_flags = pugi::format_raw; + R_xlen_t mtc = std::distance(nams.begin(), nams.find(cld_name)); + uint32_t pugi_format_flags = pugi::format_raw; std::ostringstream oss; cld.print(oss, " ", pugi_format_flags); Rcpp::as(df[mtc])[itr] = Rcpp::String(oss.str()); } else { for (auto attrs : cld.attributes()) { - std::string attr_name = attrs.name(); + std::string attr_name = attrs.name(); std::string attr_value = attrs.value(); - auto find_res = nams.find(attr_name); + auto find_res = nams.find(attr_name); // check if name is already known if (nams.count(attr_name) == 0) { Rcpp::warning("%s: not found in xf name table", attr_name); } else { - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = attr_value; } } @@ -163,18 +161,17 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) { // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) { - R_xlen_t n = static_cast(df_xf.nrow()); - R_xlen_t k = static_cast(df_xf.ncol()); + R_xlen_t n = static_cast(df_xf.nrow()); + R_xlen_t k = static_cast(df_xf.ncol()); Rcpp::CharacterVector z(n); uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; @@ -194,8 +191,7 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) { "applyNumberFormat", "applyProtection", "pivotButton", - "quotePrefix" - }; + "quotePrefix"}; std::set xf_nams_alignment = { "horizontal", @@ -206,17 +202,11 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) { "shrinkToFit", "textRotation", "vertical", - "wrapText" - }; + "wrapText"}; - std::set xf_nams_extLst = { - "extLst" - }; + std::set xf_nams_extLst = {"extLst"}; - std::set xf_nams_protection = { - "hidden", - "locked" - }; + std::set xf_nams_protection = {"hidden", "locked"}; for (R_xlen_t i = 0; i < n; ++i) { pugi::xml_document doc; @@ -225,7 +215,7 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) { // check if alignment node is required bool has_alignment = false; - has_alignment = has_it(df_xf, xf_nams_alignment, i); + has_alignment = has_it(df_xf, xf_nams_alignment, i); pugi::xml_node xf_alignment; if (has_alignment) { @@ -234,13 +224,13 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) { // check if extLst node is required bool has_extLst = false; - has_extLst = has_it(df_xf, xf_nams_extLst, i); + has_extLst = has_it(df_xf, xf_nams_extLst, i); pugi::xml_node xf_extLst; // check if protection node is required bool has_protection = false; - has_protection = has_it(df_xf, xf_nams_protection, i); + has_protection = has_it(df_xf, xf_nams_protection, i); pugi::xml_node xf_protection; if (has_protection) { @@ -252,41 +242,41 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) { std::string attrnam = attrnams[static_cast(j)]; // not all missing in match: ergo they are - bool is_xf = xf_nams.count(attrnam) > 0; - bool is_alignment = xf_nams_alignment.count(attrnam) > 0; - bool is_extLst = xf_nams_extLst.count(attrnam) > 0; + bool is_xf = xf_nams.count(attrnam) > 0; + bool is_alignment = xf_nams_alignment.count(attrnam) > 0; + bool is_extLst = xf_nams_extLst.count(attrnam) > 0; bool is_protection = xf_nams_protection.count(attrnam) > 0; // if (is_xf) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_xf[j])[i]; + cv_s = Rcpp::as(df_xf[j])[i]; // only write attributes where cv_s has a value if (cv_s[0] != "") { // Rf_PrintValue(cv_s); - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); xf.append_attribute(attrnam.c_str()) = val_strl.c_str(); } } if (has_alignment && is_alignment) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_xf[j])[i]; + cv_s = Rcpp::as(df_xf[j])[i]; if (cv_s[0] != "") { - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); xf_alignment.append_attribute(attrnam.c_str()) = val_strl.c_str(); } } if (has_extLst && is_extLst) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_xf[j])[i]; + cv_s = Rcpp::as(df_xf[j])[i]; if (cv_s[0] != "") { - const std::string val_strl = Rcpp::as(cv_s); - pugi::xml_document tempDoc; + const std::string val_strl = Rcpp::as(cv_s); + pugi::xml_document tempDoc; pugi::xml_parse_result tempResult = tempDoc.load_string(val_strl.c_str()); if (tempResult) { xf.append_copy(tempDoc.first_child()); @@ -298,14 +288,13 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) { if (has_protection && is_protection) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_xf[j])[i]; + cv_s = Rcpp::as(df_xf[j])[i]; if (cv_s[0] != "") { - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); xf_protection.append_attribute(attrnam.c_str()) = val_strl.c_str(); } } - } std::ostringstream oss; @@ -317,14 +306,13 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) { return z; } - // [[Rcpp::export]] Rcpp::DataFrame read_font(XPtrXML xml_doc_font) { // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.font?view=openxml-2.8.1 // openxml 2.8.1 - std::set nams { + std::set nams{ "b", "charset", "color", @@ -340,19 +328,17 @@ Rcpp::DataFrame read_font(XPtrXML xml_doc_font) { "strike", "sz", "u", - "vertAlign" - }; + "vertAlign"}; - R_xlen_t nn = std::distance(xml_doc_font->begin(), xml_doc_font->end()); - R_xlen_t kk = static_cast(nams.size()); + R_xlen_t nn = std::distance(xml_doc_font->begin(), xml_doc_font->end()); + R_xlen_t kk = static_cast(nams.size()); uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; Rcpp::CharacterVector rvec(nn); // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -363,9 +349,9 @@ Rcpp::DataFrame read_font(XPtrXML xml_doc_font) { for (auto cld : xml_font.children()) { - std::string name = cld.name(); - std::string value = cld.value(); - auto find_res = nams.find(name); + std::string name = cld.name(); + std::string value = cld.value(); + auto find_res = nams.find(name); // check if name is already known if (nams.count(name) == 0) { @@ -375,7 +361,7 @@ Rcpp::DataFrame read_font(XPtrXML xml_doc_font) { std::ostringstream oss; cld.print(oss, " ", pugi_format_flags); - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = oss.str(); } @@ -389,19 +375,19 @@ Rcpp::DataFrame read_font(XPtrXML xml_doc_font) { // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector write_font(Rcpp::DataFrame df_font) { - auto n = df_font.nrow(); + auto n = df_font.nrow(); Rcpp::CharacterVector z(n); - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; for (auto i = 0; i < n; ++i) { @@ -409,24 +395,22 @@ Rcpp::CharacterVector write_font(Rcpp::DataFrame df_font) { pugi::xml_node font = doc.append_child("font"); - for (auto j = 0; j < df_font.ncol(); ++j) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_font[j])[i]; + cv_s = Rcpp::as(df_font[j])[i]; if (cv_s[0] != "") { std::string font_i = Rcpp::as(cv_s[0]); - pugi::xml_document font_node; + pugi::xml_document font_node; pugi::xml_parse_result result = font_node.load_string(font_i.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading font node fail: %s", cv_s); + if (!result) + Rcpp::stop("loading font node fail: %s", cv_s); font.append_copy(font_node.first_child()); - } - } std::ostringstream oss; @@ -438,17 +422,13 @@ Rcpp::CharacterVector write_font(Rcpp::DataFrame df_font) { return z; } - // [[Rcpp::export]] Rcpp::DataFrame read_numfmt(XPtrXML xml_doc_numfmt) { // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.numberingformat?view=openxml-2.8.1 // openxml 2.8.1 - std::set nams { - "formatCode", - "numFmtId" - }; + std::set nams{"formatCode", "numFmtId"}; R_xlen_t nn = std::distance(xml_doc_numfmt->begin(), xml_doc_numfmt->end()); R_xlen_t kk = static_cast(nams.size()); @@ -457,8 +437,7 @@ Rcpp::DataFrame read_numfmt(XPtrXML xml_doc_numfmt) { // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -468,15 +447,15 @@ Rcpp::DataFrame read_numfmt(XPtrXML xml_doc_numfmt) { for (auto xml_numfmt : xml_doc_numfmt->children("numFmt")) { for (auto attrs : xml_numfmt.attributes()) { - std::string attr_name = attrs.name(); + std::string attr_name = attrs.name(); std::string attr_value = attrs.value(); - auto find_res = nams.find(attr_name); + auto find_res = nams.find(attr_name); // check if name is already known if (nams.count(attr_name) == 0) { Rcpp::warning("%s: not found in numfmt name table", attr_name); } else { - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = attr_value; } } @@ -489,34 +468,33 @@ Rcpp::DataFrame read_numfmt(XPtrXML xml_doc_numfmt) { // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector write_numfmt(Rcpp::DataFrame df_numfmt) { - auto n = df_numfmt.nrow(); + auto n = df_numfmt.nrow(); Rcpp::CharacterVector z(n); - uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; + uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; for (auto i = 0; i < n; ++i) { - pugi::xml_document doc; + pugi::xml_document doc; Rcpp::CharacterVector attrnams = df_numfmt.names(); pugi::xml_node numFmt = doc.append_child("numFmt"); for (auto j = 0; j < df_numfmt.ncol(); ++j) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_numfmt[j])[i]; + cv_s = Rcpp::as(df_numfmt[j])[i]; // only write attributes where cv_s has a value if (cv_s[0] != "") { // Rf_PrintValue(cv_s); - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); numFmt.append_attribute(attrnams[j]) = val_strl.c_str(); } } @@ -536,32 +514,32 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) { // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.border?view=openxml-2.8.1 // openxml 2.8.1 - std::set nam_attrs {"diagonalDown", "diagonalUp", "outline"}; + std::set nam_attrs{"diagonalDown", "diagonalUp", "outline"}; - std::set nam_chlds {"start", "end", - "left", "right", "top", "bottom", "diagonal", - "vertical", "horizontal"}; + std::set nam_chlds{ + "start", "end", "left", "right", "top", "bottom", "diagonal", "vertical", "horizontal"}; - auto total_length = nam_attrs.size() + nam_chlds.size(); + auto total_length = nam_attrs.size() + nam_chlds.size(); std::vector all_names(total_length); std::copy(nam_attrs.begin(), nam_attrs.end(), all_names.begin()); - std::copy(nam_chlds.begin(), nam_chlds.end(), all_names.begin() + static_cast(nam_attrs.size())); - - std::set nams(std::make_move_iterator(all_names.begin()), - std::make_move_iterator(all_names.end())); + std::copy( + nam_chlds.begin(), + nam_chlds.end(), + all_names.begin() + static_cast(nam_attrs.size())); + std::set nams( + std::make_move_iterator(all_names.begin()), std::make_move_iterator(all_names.end())); - R_xlen_t nn = std::distance(xml_doc_border->begin(), xml_doc_border->end()); - R_xlen_t kk = static_cast(nams.size()); + R_xlen_t nn = std::distance(xml_doc_border->begin(), xml_doc_border->end()); + R_xlen_t kk = static_cast(nams.size()); uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; Rcpp::CharacterVector rvec(nn); // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -571,15 +549,15 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) { for (auto xml_border : xml_doc_border->children("border")) { for (auto attrs : xml_border.attributes()) { - std::string attr_name = attrs.name(); + std::string attr_name = attrs.name(); std::string attr_value = attrs.value(); - auto find_res = nams.find(attr_name); + auto find_res = nams.find(attr_name); // check if name is already known if (nams.count(attr_name) == 0) { Rcpp::warning("%s: not found in border name table", attr_name); } else { - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = attr_value; } } @@ -587,7 +565,7 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) { for (auto cld : xml_border.children()) { std::string cld_name = cld.name(); - auto find_res = nams.find(cld_name); + auto find_res = nams.find(cld_name); // check if name is already known if (nams.count(cld_name) == 0) { @@ -597,7 +575,7 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) { cld.print(oss, " ", pugi_format_flags); std::string cld_value = oss.str(); - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = cld_value; } } @@ -605,51 +583,48 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) { // rownames as character vectors matching to rvec[itr] = std::to_string(itr); ++itr; - } // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector write_border(Rcpp::DataFrame df_border) { - R_xlen_t n = static_cast(df_border.nrow()); - R_xlen_t k = static_cast(df_border.ncol()); + R_xlen_t n = static_cast(df_border.nrow()); + R_xlen_t k = static_cast(df_border.ncol()); Rcpp::CharacterVector z(n); - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; - // openxml 2.8.1 - std::vector attrnams = df_border.names(); - std::set nam_attrs = {"diagonalDown", "diagonalUp", "outline"}; - std::set nam_chlds = {"bottom", "diagonal", "end", "horizontal", - "left", "right", "start", "top", - "vertical"}; + std::vector attrnams = df_border.names(); + std::set nam_attrs = {"diagonalDown", "diagonalUp", "outline"}; + std::set nam_chlds = { + "bottom", "diagonal", "end", "horizontal", "left", "right", "start", "top", "vertical"}; for (R_xlen_t i = 0; i < n; ++i) { pugi::xml_document doc; - pugi::xml_node border = doc.append_child("border"); + pugi::xml_node border = doc.append_child("border"); for (R_xlen_t j = 0; j < k; ++j) { std::string attr_j = attrnams[static_cast(j)]; // mimic which - auto res1 = nam_attrs.find(attr_j); + auto res1 = nam_attrs.find(attr_j); R_xlen_t mtc1 = std::distance(nam_attrs.begin(), res1); std::vector idx1(static_cast(mtc1) + 1); std::iota(idx1.begin(), idx1.end(), 0); - auto res2 = nam_chlds.find(attr_j); + auto res2 = nam_chlds.find(attr_j); R_xlen_t mtc2 = std::distance(nam_chlds.begin(), res2); std::vector idx2(static_cast(mtc2) + 1); @@ -658,30 +633,30 @@ Rcpp::CharacterVector write_border(Rcpp::DataFrame df_border) { // check if name is already known if (nam_attrs.count(attr_j) != 0) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_border[j])[i]; + cv_s = Rcpp::as(df_border[j])[i]; // only write attributes where cv_s has a value if (cv_s[0] != "") { // Rf_PrintValue(cv_s); - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); border.append_attribute(attr_j.c_str()) = val_strl.c_str(); } } if (nam_chlds.count(attr_j) != 0) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_border[j])[i]; + cv_s = Rcpp::as(df_border[j])[i]; if (cv_s[0] != "") { std::string font_i = Rcpp::as(cv_s[0]); - pugi::xml_document border_node; + pugi::xml_document border_node; pugi::xml_parse_result result = border_node.load_string(font_i.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading border node fail: %s", cv_s); + if (!result) + Rcpp::stop("loading border node fail: %s", cv_s); border.append_copy(border_node.first_child()); - } } @@ -697,28 +672,23 @@ Rcpp::CharacterVector write_border(Rcpp::DataFrame df_border) { return z; } - // [[Rcpp::export]] Rcpp::DataFrame read_fill(XPtrXML xml_doc_fill) { // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.font?view=openxml-2.8.1 // openxml 2.8.1 - std::set nams { - "gradientFill", - "patternFill" - }; + std::set nams{"gradientFill", "patternFill"}; - R_xlen_t nn = std::distance(xml_doc_fill->begin(), xml_doc_fill->end()); - R_xlen_t kk = static_cast(nams.size()); + R_xlen_t nn = std::distance(xml_doc_fill->begin(), xml_doc_fill->end()); + R_xlen_t kk = static_cast(nams.size()); uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; Rcpp::CharacterVector rvec(nn); // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -729,8 +699,8 @@ Rcpp::DataFrame read_fill(XPtrXML xml_doc_fill) { for (auto cld : xml_fill.children()) { - std::string name = cld.name(); - auto find_res = nams.find(name); + std::string name = cld.name(); + auto find_res = nams.find(name); // check if name is already known if (nams.count(name) == 0) { @@ -740,7 +710,7 @@ Rcpp::DataFrame read_fill(XPtrXML xml_doc_fill) { std::ostringstream oss; cld.print(oss, " ", pugi_format_flags); - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = oss.str(); } @@ -754,19 +724,19 @@ Rcpp::DataFrame read_fill(XPtrXML xml_doc_fill) { // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector write_fill(Rcpp::DataFrame df_fill) { - auto n = df_fill.nrow(); + auto n = df_fill.nrow(); Rcpp::CharacterVector z(n); - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; for (auto i = 0; i < n; ++i) { @@ -774,24 +744,22 @@ Rcpp::CharacterVector write_fill(Rcpp::DataFrame df_fill) { pugi::xml_node fill = doc.append_child("fill"); - for (auto j = 0; j < df_fill.ncol(); ++j) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_fill[j])[i]; + cv_s = Rcpp::as(df_fill[j])[i]; if (cv_s[0] != "") { std::string font_i = Rcpp::as(cv_s[0]); - pugi::xml_document font_node; + pugi::xml_document font_node; pugi::xml_parse_result result = font_node.load_string(font_i.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading fill node fail: %s", cv_s); + if (!result) + Rcpp::stop("loading fill node fail: %s", cv_s); fill.append_copy(font_node.first_child()); - } - } std::ostringstream oss; @@ -803,38 +771,38 @@ Rcpp::CharacterVector write_fill(Rcpp::DataFrame df_fill) { return z; } - // [[Rcpp::export]] Rcpp::DataFrame read_cellStyle(XPtrXML xml_doc_cellStyle) { // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.border?view=openxml-2.8.1 // openxml 2.8.1 - std::set nam_attrs {"builtinId", "customBuiltin", "hidden", - "iLevel", "name", "xfId", "xr:uid"}; + std::set nam_attrs{ + "builtinId", "customBuiltin", "hidden", "iLevel", "name", "xfId", "xr:uid"}; - std::set nam_chlds {"extLst"}; + std::set nam_chlds{"extLst"}; - auto total_length = nam_attrs.size() + nam_chlds.size(); + auto total_length = nam_attrs.size() + nam_chlds.size(); std::vector all_names(total_length); std::copy(nam_attrs.begin(), nam_attrs.end(), all_names.begin()); - std::copy(nam_chlds.begin(), nam_chlds.end(), all_names.begin() + static_cast(nam_attrs.size())); - - std::set nams(std::make_move_iterator(all_names.begin()), - std::make_move_iterator(all_names.end())); + std::copy( + nam_chlds.begin(), + nam_chlds.end(), + all_names.begin() + static_cast(nam_attrs.size())); + std::set nams( + std::make_move_iterator(all_names.begin()), std::make_move_iterator(all_names.end())); - R_xlen_t nn = std::distance(xml_doc_cellStyle->begin(), xml_doc_cellStyle->end()); - R_xlen_t kk = static_cast(nams.size()); + R_xlen_t nn = std::distance(xml_doc_cellStyle->begin(), xml_doc_cellStyle->end()); + R_xlen_t kk = static_cast(nams.size()); uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; Rcpp::CharacterVector rvec(nn); // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -844,15 +812,15 @@ Rcpp::DataFrame read_cellStyle(XPtrXML xml_doc_cellStyle) { for (auto xml_cellStyle : xml_doc_cellStyle->children("cellStyle")) { for (auto attrs : xml_cellStyle.attributes()) { - std::string attr_name = attrs.name(); + std::string attr_name = attrs.name(); std::string attr_value = attrs.value(); - auto find_res = nams.find(attr_name); + auto find_res = nams.find(attr_name); // check if name is already known if (nams.count(attr_name) == 0) { Rcpp::warning("%s: not found in cellstyle name table", attr_name); } else { - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = attr_value; } } @@ -860,7 +828,7 @@ Rcpp::DataFrame read_cellStyle(XPtrXML xml_doc_cellStyle) { for (auto cld : xml_cellStyle.children()) { std::string cld_name = cld.name(); - auto find_res = nams.find(cld_name); + auto find_res = nams.find(cld_name); // check if name is already known if (nams.count(cld_name) == 0) { @@ -870,7 +838,7 @@ Rcpp::DataFrame read_cellStyle(XPtrXML xml_doc_cellStyle) { cld.print(oss, " ", pugi_format_flags); std::string cld_value = oss.str(); - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = cld_value; } } @@ -878,49 +846,48 @@ Rcpp::DataFrame read_cellStyle(XPtrXML xml_doc_cellStyle) { // rownames as character vectors matching to rvec[itr] = std::to_string(itr); ++itr; - } // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector write_cellStyle(Rcpp::DataFrame df_cellstyle) { - R_xlen_t n = static_cast(df_cellstyle.nrow()); - R_xlen_t k = static_cast(df_cellstyle.ncol()); + R_xlen_t n = static_cast(df_cellstyle.nrow()); + R_xlen_t k = static_cast(df_cellstyle.ncol()); Rcpp::CharacterVector z(n); - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; - // openxml 2.8.1 - std::vector attrnams = df_cellstyle.names(); - std::set nam_attrs = {"builtinId", "customBuiltin", "hidden", "iLevel", "name", "xfId"}; + std::vector attrnams = df_cellstyle.names(); + std::set nam_attrs = { + "builtinId", "customBuiltin", "hidden", "iLevel", "name", "xfId"}; std::set nam_chlds = {"extLst"}; for (R_xlen_t i = 0; i < n; ++i) { pugi::xml_document doc; - pugi::xml_node cellstyle = doc.append_child("cellStyle"); + pugi::xml_node cellstyle = doc.append_child("cellStyle"); for (R_xlen_t j = 0; j < k; ++j) { std::string attr_j = attrnams[static_cast(j)]; // mimic which - auto res1 = nam_attrs.find(attr_j); + auto res1 = nam_attrs.find(attr_j); R_xlen_t mtc1 = std::distance(nam_attrs.begin(), res1); std::vector idx1(static_cast(mtc1) + 1); std::iota(idx1.begin(), idx1.end(), 0); - auto res2 = nam_chlds.find(attr_j); + auto res2 = nam_chlds.find(attr_j); R_xlen_t mtc2 = std::distance(nam_chlds.begin(), res2); std::vector idx2(static_cast(mtc2) + 1); @@ -929,30 +896,30 @@ Rcpp::CharacterVector write_cellStyle(Rcpp::DataFrame df_cellstyle) { // check if name is already known if (nam_attrs.count(attr_j) != 0) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_cellstyle[j])[i]; + cv_s = Rcpp::as(df_cellstyle[j])[i]; // only write attributes where cv_s has a value if (cv_s[0] != "") { // Rf_PrintValue(cv_s); - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); cellstyle.append_attribute(attr_j.c_str()) = val_strl.c_str(); } } if (nam_chlds.count(attr_j) != 0) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_cellstyle[j])[i]; + cv_s = Rcpp::as(df_cellstyle[j])[i]; if (cv_s[0] != "") { std::string font_i = Rcpp::as(cv_s[0]); - pugi::xml_document border_node; + pugi::xml_document border_node; pugi::xml_parse_result result = border_node.load_string(font_i.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading cellStyle node fail: %s", cv_s); + if (!result) + Rcpp::stop("loading cellStyle node fail: %s", cv_s); cellstyle.append_copy(border_node.first_child()); - } } @@ -968,26 +935,27 @@ Rcpp::CharacterVector write_cellStyle(Rcpp::DataFrame df_cellstyle) { return z; } - // [[Rcpp::export]] Rcpp::DataFrame read_tableStyle(XPtrXML xml_doc_tableStyle) { // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.border?view=openxml-2.8.1 // openxml 2.8.1 - std::set nam_attrs {"count", "name", "pivot", "table", "xr9:uid"}; + std::set nam_attrs{"count", "name", "pivot", "table", "xr9:uid"}; - std::set nam_chlds {"tableStyleElement"}; + std::set nam_chlds{"tableStyleElement"}; - auto total_length = nam_attrs.size() + nam_chlds.size(); + auto total_length = nam_attrs.size() + nam_chlds.size(); std::vector all_names(total_length); std::copy(nam_attrs.begin(), nam_attrs.end(), all_names.begin()); - std::copy(nam_chlds.begin(), nam_chlds.end(), all_names.begin() + static_cast(nam_attrs.size())); - - std::set nams(std::make_move_iterator(all_names.begin()), - std::make_move_iterator(all_names.end())); + std::copy( + nam_chlds.begin(), + nam_chlds.end(), + all_names.begin() + static_cast(nam_attrs.size())); + std::set nams( + std::make_move_iterator(all_names.begin()), std::make_move_iterator(all_names.end())); R_xlen_t nn = std::distance(xml_doc_tableStyle->begin(), xml_doc_tableStyle->end()); R_xlen_t kk = static_cast(nams.size()); @@ -997,8 +965,7 @@ Rcpp::DataFrame read_tableStyle(XPtrXML xml_doc_tableStyle) { // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -1008,15 +975,15 @@ Rcpp::DataFrame read_tableStyle(XPtrXML xml_doc_tableStyle) { for (auto xml_tableStyle : xml_doc_tableStyle->children("tableStyle")) { for (auto attrs : xml_tableStyle.attributes()) { - std::string attr_name = attrs.name(); + std::string attr_name = attrs.name(); std::string attr_value = attrs.value(); - auto find_res = nams.find(attr_name); + auto find_res = nams.find(attr_name); // check if name is already known if (nams.count(attr_name) == 0) { Rcpp::warning("%s: not found in tablestyle name table", attr_name); } else { - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = attr_value; } } @@ -1025,7 +992,7 @@ Rcpp::DataFrame read_tableStyle(XPtrXML xml_doc_tableStyle) { for (auto cld : xml_tableStyle.children()) { std::string cld_name = cld.name(); - auto find_res = nams.find(cld_name); + auto find_res = nams.find(cld_name); // check if name is already known if (nams.count(cld_name) == 0) { @@ -1035,7 +1002,7 @@ Rcpp::DataFrame read_tableStyle(XPtrXML xml_doc_tableStyle) { cld.print(oss, " ", pugi_format_flags); cld_value += oss.str(); - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = cld_value; } } @@ -1043,51 +1010,48 @@ Rcpp::DataFrame read_tableStyle(XPtrXML xml_doc_tableStyle) { // rownames as character vectors matching to rvec[itr] = std::to_string(itr); ++itr; - } // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector write_tableStyle(Rcpp::DataFrame df_tablestyle) { - R_xlen_t n = static_cast(df_tablestyle.nrow()); - R_xlen_t k = static_cast(df_tablestyle.ncol()); + R_xlen_t n = static_cast(df_tablestyle.nrow()); + R_xlen_t k = static_cast(df_tablestyle.ncol()); Rcpp::CharacterVector z(n); - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; - // openxml 2.8.1 std::vector attrnams = df_tablestyle.names(); std::set nam_attrs = {"count", "name", "pivot", "table", "xr9:uid"}; std::set nam_chlds = {"tableStyleElement"}; - for (R_xlen_t i = 0; i < n; ++i) { pugi::xml_document doc; - pugi::xml_node tablestyle = doc.append_child("tableStyle"); + pugi::xml_node tablestyle = doc.append_child("tableStyle"); for (R_xlen_t j = 0; j < k; ++j) { std::string attr_j = attrnams[static_cast(j)]; // mimic which - auto res1 = nam_attrs.find(attr_j); + auto res1 = nam_attrs.find(attr_j); R_xlen_t mtc1 = std::distance(nam_attrs.begin(), res1); std::vector idx1(static_cast(mtc1) + 1); std::iota(idx1.begin(), idx1.end(), 0); - auto res2 = nam_chlds.find(attr_j); + auto res2 = nam_chlds.find(attr_j); R_xlen_t mtc2 = std::distance(nam_chlds.begin(), res2); std::vector idx2(static_cast(mtc2) + 1); @@ -1096,31 +1060,32 @@ Rcpp::CharacterVector write_tableStyle(Rcpp::DataFrame df_tablestyle) { // check if name is already known if (nam_attrs.count(attr_j) != 0) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_tablestyle[j])[i]; + cv_s = Rcpp::as(df_tablestyle[j])[i]; // only write attributes where cv_s has a value if (cv_s[0] != "") { // Rf_PrintValue(cv_s); - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); tablestyle.append_attribute(attr_j.c_str()) = val_strl.c_str(); } } if (nam_chlds.count(attr_j) != 0) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_tablestyle[j])[i]; + cv_s = Rcpp::as(df_tablestyle[j])[i]; if (cv_s[0] != "") { std::string font_i = Rcpp::as(cv_s[0]); - pugi::xml_document tableStyleElement; - pugi::xml_parse_result result = tableStyleElement.load_string(font_i.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading df_tablestyle node fail: %s", cv_s); + pugi::xml_document tableStyleElement; + pugi::xml_parse_result result = + tableStyleElement.load_string(font_i.c_str(), pugi_parse_flags); + if (!result) + Rcpp::stop("loading df_tablestyle node fail: %s", cv_s); - for (auto chld: tableStyleElement.children()) + for (auto chld : tableStyleElement.children()) tablestyle.append_copy(chld); - } } @@ -1136,34 +1101,24 @@ Rcpp::CharacterVector write_tableStyle(Rcpp::DataFrame df_tablestyle) { return z; } - - // [[Rcpp::export]] Rcpp::DataFrame read_dxf(XPtrXML xml_doc_dxf) { // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.font?view=openxml-2.8.1 // openxml 2.8.1 - std::set nams { - "alignment", - "border", - "extLst", - "fill", - "font", - "numFmt", - "protection" - }; + std::set nams{ + "alignment", "border", "extLst", "fill", "font", "numFmt", "protection"}; - R_xlen_t nn = std::distance(xml_doc_dxf->begin(), xml_doc_dxf->end()); - R_xlen_t kk = static_cast(nams.size()); + R_xlen_t nn = std::distance(xml_doc_dxf->begin(), xml_doc_dxf->end()); + R_xlen_t kk = static_cast(nams.size()); uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; Rcpp::CharacterVector rvec(nn); // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -1174,8 +1129,8 @@ Rcpp::DataFrame read_dxf(XPtrXML xml_doc_dxf) { for (auto cld : xml_dxf.children()) { - std::string name = cld.name(); - auto find_res = nams.find(name); + std::string name = cld.name(); + auto find_res = nams.find(name); // check if name is already known if (nams.count(name) == 0) { @@ -1185,7 +1140,7 @@ Rcpp::DataFrame read_dxf(XPtrXML xml_doc_dxf) { cld.print(oss, " ", pugi_format_flags); std::string value = oss.str(); - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = value; } @@ -1199,19 +1154,19 @@ Rcpp::DataFrame read_dxf(XPtrXML xml_doc_dxf) { // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector write_dxf(Rcpp::DataFrame df_dxf) { - auto n = df_dxf.nrow(); + auto n = df_dxf.nrow(); Rcpp::CharacterVector z(n); - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; for (auto i = 0; i < n; ++i) { @@ -1219,24 +1174,22 @@ Rcpp::CharacterVector write_dxf(Rcpp::DataFrame df_dxf) { pugi::xml_node dxf = doc.append_child("dxf"); - for (auto j = 0; j < df_dxf.ncol(); ++j) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_dxf[j])[i]; + cv_s = Rcpp::as(df_dxf[j])[i]; if (cv_s[0] != "") { std::string font_i = Rcpp::as(cv_s[0]); - pugi::xml_document font_node; + pugi::xml_document font_node; pugi::xml_parse_result result = font_node.load_string(font_i.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading dxf node fail: %s", cv_s); + if (!result) + Rcpp::stop("loading dxf node fail: %s", cv_s); dxf.append_copy(font_node.first_child()); - } - } std::ostringstream oss; @@ -1248,29 +1201,23 @@ Rcpp::CharacterVector write_dxf(Rcpp::DataFrame df_dxf) { return z; } - - // [[Rcpp::export]] Rcpp::DataFrame read_colors(XPtrXML xml_doc_colors) { // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.colors?view=openxml-2.8.1 // openxml 2.8.1 - std::set nams { - "indexedColors", - "mruColors" - }; + std::set nams{"indexedColors", "mruColors"}; - R_xlen_t nn = std::distance(xml_doc_colors->begin(), xml_doc_colors->end()); - R_xlen_t kk = static_cast(nams.size()); + R_xlen_t nn = std::distance(xml_doc_colors->begin(), xml_doc_colors->end()); + R_xlen_t kk = static_cast(nams.size()); uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; Rcpp::CharacterVector rvec(nn); // 1. create the list Rcpp::List df(kk); - for (R_xlen_t i = 0; i < kk; ++i) - { + for (R_xlen_t i = 0; i < kk; ++i) { SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn))); } @@ -1281,8 +1228,8 @@ Rcpp::DataFrame read_colors(XPtrXML xml_doc_colors) { for (auto cld : xml_color.children()) { - std::string name = cld.name(); - auto find_res = nams.find(name); + std::string name = cld.name(); + auto find_res = nams.find(name); // check if name is already known if (nams.count(name) == 0) { @@ -1292,7 +1239,7 @@ Rcpp::DataFrame read_colors(XPtrXML xml_doc_colors) { cld.print(oss, " ", pugi_format_flags); std::string cld_value = oss.str(); - R_xlen_t mtc = std::distance(nams.begin(), find_res); + R_xlen_t mtc = std::distance(nams.begin(), find_res); Rcpp::as(df[mtc])[itr] = cld_value; } @@ -1306,20 +1253,20 @@ Rcpp::DataFrame read_colors(XPtrXML xml_doc_colors) { // 3. Create a data.frame df.attr("row.names") = rvec; - df.attr("names") = nams; - df.attr("class") = "data.frame"; + df.attr("names") = nams; + df.attr("class") = "data.frame"; return df; } - // [[Rcpp::export]] Rcpp::CharacterVector write_colors(Rcpp::DataFrame df_colors) { - R_xlen_t n = static_cast(df_colors.nrow()); - R_xlen_t k = static_cast(df_colors.ncol()); + R_xlen_t n = static_cast(df_colors.nrow()); + R_xlen_t k = static_cast(df_colors.ncol()); Rcpp::CharacterVector z(n); - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; for (R_xlen_t i = 0; i < n; ++i) { @@ -1327,24 +1274,22 @@ Rcpp::CharacterVector write_colors(Rcpp::DataFrame df_colors) { pugi::xml_node color = doc.append_child("colors"); - for (R_xlen_t j = 0; j < k; ++j) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(df_colors[j])[i]; + cv_s = Rcpp::as(df_colors[j])[i]; if (cv_s[0] != "") { std::string font_i = Rcpp::as(cv_s[0]); - pugi::xml_document font_node; + pugi::xml_document font_node; pugi::xml_parse_result result = font_node.load_string(font_i.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading color node fail: %s", cv_s); + if (!result) + Rcpp::stop("loading color node fail: %s", cv_s); color.append_copy(font_node.first_child()); - } - } std::ostringstream oss; diff --git a/src/write_file.cpp b/src/write_file.cpp index 818f841ce..b2bfc0544 100644 --- a/src/write_file.cpp +++ b/src/write_file.cpp @@ -8,9 +8,12 @@ Rcpp::CharacterVector set_sst(Rcpp::CharacterVector sharedStrings) { for (auto i = 0; i < sharedStrings.length(); ++i) { pugi::xml_document si; - std::string sharedString = Rcpp::as(sharedStrings[i]); + std::string sharedString = Rcpp::as(sharedStrings[i]); - si.append_child("si").append_child("t").append_child(pugi::node_pcdata).set_value(sharedString.c_str()); + si.append_child("si") + .append_child("t") + .append_child(pugi::node_pcdata) + .set_value(sharedString.c_str()); std::ostringstream oss; si.print(oss, " ", pugi::format_raw); @@ -21,7 +24,6 @@ Rcpp::CharacterVector set_sst(Rcpp::CharacterVector sharedStrings) { return sst; } - // creates an xml row // data in xml is ordered row wise. therefore we need the row attributes and // the column data used in this row. This function uses both to create a single @@ -35,12 +37,13 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) auto rowid = 0; // integer value of the r field in row_attr pugi::xml_document doc; - pugi::xml_node row; + pugi::xml_node row; std::string xml_preserver = " "; // non optional: treat input as valid at this stage - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; // uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; // we cannot access rows directly in the dataframe. @@ -51,16 +54,16 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) Rcpp::CharacterVector cc_c_t = cc["c_t"]; Rcpp::CharacterVector cc_c_s = cc["c_s"]; Rcpp::CharacterVector cc_c_cm = cc["c_cm"]; - Rcpp::CharacterVector cc_c_ph = cc["c_ph"]; // can be utf8 + Rcpp::CharacterVector cc_c_ph = cc["c_ph"]; // can be utf8 Rcpp::CharacterVector cc_c_vm = cc["c_vm"]; - Rcpp::CharacterVector cc_f = cc["f"]; // can be utf8 + Rcpp::CharacterVector cc_f = cc["f"]; // can be utf8 Rcpp::CharacterVector cc_f_t = cc["f_t"]; Rcpp::CharacterVector cc_f_ref = cc["f_ref"]; Rcpp::CharacterVector cc_f_ca = cc["f_ca"]; Rcpp::CharacterVector cc_f_si = cc["f_si"]; - Rcpp::CharacterVector cc_is = cc["is"]; // can be utf8 + Rcpp::CharacterVector cc_is = cc["is"]; // can be utf8 - Rcpp::CharacterVector row_r = row_attr["r"]; + Rcpp::CharacterVector row_r = row_attr["r"]; for (auto i = 0; i < cc.nrow(); ++i) { @@ -73,20 +76,18 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) // have every row and only then continue writing the column while (rowid < thisrow) { - rowid = std::stoi(Rcpp::as( - row_r[row_idx] - )); + rowid = std::stoi(Rcpp::as(row_r[row_idx])); - row = doc.append_child("row"); + row = doc.append_child("row"); Rcpp::CharacterVector attrnams = row_attr.names(); for (auto j = 0; j < row_attr.ncol(); ++j) { Rcpp::CharacterVector cv_s = ""; - cv_s = Rcpp::as(row_attr[j])[row_idx]; + cv_s = Rcpp::as(row_attr[j])[row_idx]; if (cv_s[0] != "") { - const std::string val_strl = Rcpp::as(cv_s); + const std::string val_strl = Rcpp::as(cv_s); row.append_attribute(attrnams[j]) = val_strl.c_str(); } } @@ -100,19 +101,9 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) lastrow = thisrow; if ( // skip blank cells entirely - cc_c_s[i] == "" && - cc_c_t[i] == "" && - cc_c_cm[i] == "" && - cc_c_ph[i] == "" && - cc_c_vm[i] == "" && - cc_v[i] == "" && - cc_f[i] == "" && - cc_f_t[i] == "" && - cc_f_ref[i] == "" && - cc_f_ca[i] == "" && - cc_f_si[i] == "" && - cc_is[i] == "" - ) { + cc_c_s[i] == "" && cc_c_t[i] == "" && cc_c_cm[i] == "" && cc_c_ph[i] == "" && + cc_c_vm[i] == "" && cc_v[i] == "" && cc_f[i] == "" && cc_f_t[i] == "" && cc_f_ref[i] == "" && + cc_f_ca[i] == "" && cc_f_si[i] == "" && cc_is[i] == "") { continue; } @@ -150,7 +141,9 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) // ... // f node: formula to be evaluated - if (!std::string(cc_f[i]).empty() || !std::string(cc_f_t[i]).empty() || !std::string(cc_f_si[i]).empty()) { + if ( + !std::string(cc_f[i]).empty() || !std::string(cc_f_t[i]).empty() || + !std::string(cc_f_si[i]).empty()) { pugi::xml_node f = cell.append_child("f"); if (!std::string(cc_f_t[i]).empty()) { f.append_attribute("t") = std::string(cc_f_t[i]).c_str(); @@ -163,7 +156,7 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) } if (!std::string(cc_f_si[i]).empty()) { f.append_attribute("si") = std::string(cc_f_si[i]).c_str(); - f_si = true; + f_si = true; } f.append_child(pugi::node_pcdata).set_value(to_string(cc_f[i]).c_str()); @@ -176,9 +169,13 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) cell.child("v").append_child(pugi::node_pcdata).set_value(" "); } else { if (std::string(cc_c_t[i]).empty() && std::string(cc_f_t[i]).empty()) - cell.append_child("v").append_child(pugi::node_pcdata).set_value(std::string(cc_v[i]).c_str()); + cell.append_child("v") + .append_child(pugi::node_pcdata) + .set_value(std::string(cc_v[i]).c_str()); else - cell.append_child("v").append_child(pugi::node_pcdata).set_value(to_string(cc_v[i]).c_str()); + cell.append_child("v") + .append_child(pugi::node_pcdata) + .set_value(to_string(cc_v[i]).c_str()); } } @@ -186,9 +183,11 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) if (std::string(cc_c_t[i]).compare("inlineStr") == 0) { if (!std::string(cc_is[i]).empty()) { - pugi::xml_document is_node; - pugi::xml_parse_result result = is_node.load_string(to_string(cc_is[i]).c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading inlineStr node while writing failed"); + pugi::xml_document is_node; + pugi::xml_parse_result result = + is_node.load_string(to_string(cc_is[i]).c_str(), pugi_parse_flags); + if (!result) + Rcpp::stop("loading inlineStr node while writing failed"); cell.append_copy(is_node.first_child()); } @@ -198,34 +197,29 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc) return doc; } - // TODO: convert to pugi // function that creates the xml worksheet // uses preparated data and writes it. It passes data to set_row() which will // create single xml rows of sheet_data. // // [[Rcpp::export]] -XPtrXML write_worksheet( - std::string prior, - std::string post, - Rcpp::Environment sheet_data -) { - - uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; +XPtrXML write_worksheet(std::string prior, std::string post, Rcpp::Environment sheet_data) { + uint32_t pugi_parse_flags = + pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol; // sheet_data will be in order, just need to check for row_heights // CharacterVector cell_col = int_to_col(sheet_data.field("cols")); Rcpp::DataFrame row_attr = Rcpp::as(sheet_data["row_attr"]); - Rcpp::DataFrame cc = Rcpp::as(sheet_data["cc_out"]); - + Rcpp::DataFrame cc = Rcpp::as(sheet_data["cc_out"]); - xmldoc *doc = new xmldoc; + xmldoc *doc = new xmldoc; pugi::xml_parse_result result; pugi::xml_document xml_pr; result = xml_pr.load_string(prior.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading prior while writing failed"); + if (!result) + Rcpp::stop("loading prior while writing failed"); pugi::xml_node worksheet = doc->append_copy(xml_pr.child("worksheet")); pugi::xml_node sheetData = worksheet.append_child("sheetData"); @@ -240,14 +234,15 @@ XPtrXML write_worksheet( if (!post.empty()) { pugi::xml_document xml_po; result = xml_po.load_string(post.c_str(), pugi_parse_flags); - if (!result) Rcpp::stop("loading post while writing failed"); + if (!result) + Rcpp::stop("loading post while writing failed"); for (auto po : xml_po.children()) worksheet.append_copy(po); } - pugi::xml_node decl = doc->prepend_child(pugi::node_declaration); - decl.append_attribute("version") = "1.0"; - decl.append_attribute("encoding") = "UTF-8"; + pugi::xml_node decl = doc->prepend_child(pugi::node_declaration); + decl.append_attribute("version") = "1.0"; + decl.append_attribute("encoding") = "UTF-8"; decl.append_attribute("standalone") = "yes"; XPtrXML ptr(doc, true); @@ -257,11 +252,9 @@ XPtrXML write_worksheet( } // [[Rcpp::export]] -void write_xmlPtr( - XPtrXML doc, - std::string fl -) { - uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; +void write_xmlPtr(XPtrXML doc, std::string fl) { + uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes; const bool success = doc->save_file(fl.c_str(), "", pugi_format_flags, pugi::encoding_utf8); - if (!success) Rcpp::stop("could not save file"); + if (!success) + Rcpp::stop("could not save file"); } diff --git a/src/xlsb.cpp b/src/xlsb.cpp index 5db95fefb..89b5cce93 100644 --- a/src/xlsb.cpp +++ b/src/xlsb.cpp @@ -19,38 +19,37 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { bin.seekg(0, std::ios_base::beg); bool end_of_style_sheet = false; - while(!end_of_style_sheet) { + while (!end_of_style_sheet) { Rcpp::checkUserInterrupt(); int32_t x = 0, size = 0; - if (debug) Rcpp::Rcout << "." << std::endl; + if (debug) + Rcpp::Rcout << "." << std::endl; RECORD(x, size, bin, swapit); - if (debug) Rcpp::Rcout << x << ": " << size << std::endl; + if (debug) + Rcpp::Rcout << x << ": " << size << std::endl; - switch(x) { + switch (x) { - case BrtBeginStyleSheet: - { + case BrtBeginStyleSheet: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } // fills - case BrtBeginFmts: - { + case BrtBeginFmts: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtFmt: - { + case BrtFmt: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginFonts: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginFonts: { + if (debug) + Rcpp::Rcout << "" << std::endl; // bin.seekg(size, bin.cur); uint32_t cfonts = 0; - cfonts = readbin(cfonts, bin, swapit); + cfonts = readbin(cfonts, bin, swapit); - out << "" << std::endl; + out << "" << std::endl; break; } - case BrtFont: - { + case BrtFont: { out << "" << std::endl; - uint8_t uls = 0, bFamily = 0, bCharSet = 0, unused = 0, bFontScheme = 0; + uint8_t uls = 0, bFamily = 0, bCharSet = 0, unused = 0, bFontScheme = 0; uint16_t dyHeight = 0, grbit = 0, bls = 0, sss = 0; - dyHeight = readbin(dyHeight, bin , swapit) / 20; // twip - grbit = readbin(grbit, bin , swapit); + dyHeight = readbin(dyHeight, bin, swapit) / 20; // twip + grbit = readbin(grbit, bin, swapit); FontFlagsFields *fields = (FontFlagsFields *)&grbit; - bls = readbin(bls, bin , swapit); + bls = readbin(bls, bin, swapit); // 0x0190 normal // 0x02BC bold - sss = readbin(sss, bin , swapit); + sss = readbin(sss, bin, swapit); // 0x0000 None // 0x0001 Superscript // 0x0002 Subscript - uls = readbin(uls, bin , swapit); + uls = readbin(uls, bin, swapit); // 0x00 None // 0x01 Single // 0x02 Double // 0x21 Single accounting // 0x22 Double accounting - bFamily = readbin(bFamily, bin , swapit); + bFamily = readbin(bFamily, bin, swapit); // 0x00 Not applicable // 0x01 Roman // 0x02 Swiss // 0x03 Modern // 0x04 Script // 0x05 Decorative - bCharSet = readbin(bCharSet, bin , swapit); + bCharSet = readbin(bCharSet, bin, swapit); // 0x00 ANSI_CHARSET English // 0x01 DEFAULT_CHARSET System locale based // 0x02 SYMBOL_CHARSET Symbol @@ -129,35 +124,44 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { // 0xDE THAI_CHARSET Thai // 0xEE EASTEUROPE_CHARSET Eastern European // 0xFF OEM_CHARSET OEM code page (based on system locale) - unused = readbin(unused, bin , swapit); + unused = readbin(unused, bin, swapit); std::vector color = brtColor(bin, swapit); // needs handling for rgb/hex colors - if (debug) Rf_PrintValue(Rcpp::wrap(color)); + if (debug) + Rf_PrintValue(Rcpp::wrap(color)); - bFontScheme = readbin(bFontScheme, bin , swapit); + bFontScheme = readbin(bFontScheme, bin, swapit); // 0x00 None // 0x01 Major font scheme // 0x02 Minor font scheme std::string name = XLWideString(bin, swapit); - if (bls == 0x02BC) out << "" << std::endl; - if (fields->fItalic) out << "" << std::endl; - if (fields->fStrikeout) out << "" << std::endl; + if (bls == 0x02BC) + out << "" << std::endl; + if (fields->fItalic) + out << "" << std::endl; + if (fields->fStrikeout) + out << "" << std::endl; // if (fields->fOutline) out << "" << std::endl; if (uls > 0) { - if (uls == 0x01) out << "" << std::endl; - if (uls == 0x02) out << "" << std::endl; - if (uls == 0x21) out << "" << std::endl; - if (uls == 0x22) out << "" << std::endl; + if (uls == 0x01) + out << "" << std::endl; + if (uls == 0x02) + out << "" << std::endl; + if (uls == 0x21) + out << "" << std::endl; + if (uls == 0x22) + out << "" << std::endl; } out << "" << std::endl; // if (color[0] == 0x01) { // wrong but right? - // Rcpp::Rcout << "" << std::endl; + // Rcpp::Rcout << "" << + // std::endl; // } if (color[0] == 0x01) { @@ -165,13 +169,15 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { } if (color[0] == 0x02) { - out << "" << std::endl; + out << "" + << std::endl; } if (color[0] == 0x03) { double tint = 0.0; - if (color[2] != 0) tint = (double)color[2]/32767; + if (color[2] != 0) + tint = (double)color[2] / 32767; std::stringstream stream; stream << std::setprecision(16) << tint; @@ -181,7 +187,7 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { if (color[1]) - out << "" << std::endl; + out << "" << std::endl; if (bFamily > 0) out << "" << std::endl; @@ -199,53 +205,45 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { break; } - case BrtEndFonts: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndFonts: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); out << "" << std::endl; break; } - // fills - case BrtBeginFills: - { + case BrtBeginFills: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtFill: - { + case BrtFill: { uint32_t fls = 0, iGradientType = 0, cNumStop = 0; - double - xnumDegree = 0.0, - xnumFillToLeft = 0.0, - xnumFillToRight = 0.0, - xnumFillToTop = 0.0, - xnumFillToBottom = 0.0, - aPos = 0.0 // not used - ; + double xnumDegree = 0.0, xnumFillToLeft = 0.0, xnumFillToRight = 0.0, xnumFillToTop = 0.0, + xnumFillToBottom = 0.0, + aPos = 0.0 // not used + ; std::vector aColor; // not used - fls = readbin(fls, bin, swapit); + fls = readbin(fls, bin, swapit); std::vector fgColor = brtColor(bin, swapit); std::vector bgColor = brtColor(bin, swapit); - iGradientType = readbin(iGradientType, bin, swapit); - xnumDegree = Xnum(bin, swapit); - xnumFillToLeft = Xnum(bin, swapit); - xnumFillToRight = Xnum(bin, swapit); - xnumFillToTop = Xnum(bin, swapit); - xnumFillToBottom = Xnum(bin, swapit); - cNumStop = readbin(cNumStop, bin, swapit); + iGradientType = readbin(iGradientType, bin, swapit); + xnumDegree = Xnum(bin, swapit); + xnumFillToLeft = Xnum(bin, swapit); + xnumFillToRight = Xnum(bin, swapit); + xnumFillToTop = Xnum(bin, swapit); + xnumFillToBottom = Xnum(bin, swapit); + cNumStop = readbin(cNumStop, bin, swapit); if (debug) { - Rcpp::Rcout << "unused gradinet filll colors" << - xnumDegree << ": " << xnumFillToLeft << ": " << ": " << - xnumFillToRight << ": " << xnumFillToTop << "; " << - xnumFillToBottom << std::endl; + Rcpp::Rcout << "unused gradinet filll colors" << xnumDegree << ": " << xnumFillToLeft + << ": " << ": " << xnumFillToRight << ": " << xnumFillToTop << "; " + << xnumFillToBottom << std::endl; } for (uint32_t i = 0; i < cNumStop; ++i) { @@ -253,9 +251,9 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { aColor = brtColor(bin, swapit); aPos = Xnum(bin, swapit); if (debug) { - Rcpp::Rcout << "unused gradient Colors: " << - to_argb(fgColor[6], fgColor[3], fgColor[4], fgColor[5]) << - ": " << aPos << std::endl; + Rcpp::Rcout << "unused gradient Colors: " + << to_argb(fgColor[6], fgColor[3], fgColor[4], fgColor[5]) << ": " << aPos + << std::endl; } } @@ -264,31 +262,52 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { if (fls != 0x00000028) { out << "" << std::endl; // if FF000000 & FFFFFFFF they can be omitted double bgtint = 0.0, fgtint = 0.0; - if (bgColor[2] != 0) bgtint = (double)bgColor[2]/32767; - if (fgColor[2] != 0) fgtint = (double)fgColor[2]/32767; + if (bgColor[2] != 0) + bgtint = (double)bgColor[2] / 32767; + if (fgColor[2] != 0) + fgtint = (double)fgColor[2] / 32767; std::stringstream bgstream, fgstream; bgstream << std::setprecision(16) << bgtint; @@ -299,7 +318,8 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { if (fgColor[0] == 0x01) out << ""; if (fgColor[0] == 0x02) - out << ""; + out << ""; if (fgColor[0] == 0x03) out << ""; @@ -308,7 +328,8 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { if (bgColor[0] == 0x01) out << ""; if (bgColor[0] == 0x02) - out << ""; + out << ""; if (bgColor[0] == 0x03) out << ""; @@ -321,27 +342,24 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { break; } - case BrtEndFills: - { + case BrtEndFills: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } // borders - case BrtBeginBorders: - { + case BrtBeginBorders: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBorder: - { + case BrtBorder: { out << "" << std::endl; // bool fBdrDiagDown = 0, fBdrDiagUp = 0; uint8_t borderFlags = 0; - borderFlags = readbin(borderFlags, bin, swapit); + borderFlags = readbin(borderFlags, bin, swapit); std::string top = brtBorder("top", bin, swapit); std::string bottom = brtBorder("bottom", bin, swapit); @@ -358,31 +376,27 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { break; } - case BrtEndBorders: - { + case BrtEndBorders: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } // cellStyleXfs - case BrtBeginCellStyleXFs: - { + case BrtBeginCellStyleXFs: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndCellStyleXFs: - { + case BrtEndCellStyleXFs: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } // cellXfs - case BrtBeginCellXFs: - { + case BrtBeginCellXFs: { out << "" << std::endl; bin.seekg(size, bin.cur); // uint32_t cxfs = 0; @@ -390,23 +404,22 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { break; } - case BrtXF: - { + case BrtXF: { out << " 250) { Rcpp::stop("indent to big"); @@ -418,9 +431,9 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { out << " xfId=\"" << ixfeParent << "\""; } - brtxf = readbin(brtxf, bin, swapit); + brtxf = readbin(brtxf, bin, swapit); XFFields *fields = (XFFields *)&brtxf; - uint8_t xfgbit = fields->xfGrbitAtr; + uint8_t xfgbit = fields->xfGrbitAtr; xfGrbitAtrFields *xfGrbitAtr = (xfGrbitAtrFields *)&xfgbit; @@ -428,33 +441,35 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { out << " fontId=\"" << iFont << "\""; out << " fillId=\"" << iFill << "\""; out << " borderId=\"" << ixBorder << "\""; - out << " applyNumberFormat=\""<< !xfGrbitAtr->bit1 <<"\""; - out << " applyFont=\""<< !xfGrbitAtr->bit2 << "\""; + out << " applyNumberFormat=\"" << !xfGrbitAtr->bit1 << "\""; + out << " applyFont=\"" << !xfGrbitAtr->bit2 << "\""; out << " applyBorder=\"" << !xfGrbitAtr->bit4 << "\""; out << " applyFill=\"" << !xfGrbitAtr->bit5 << "\""; - out << " applyAlignment=\""<< !xfGrbitAtr->bit3 << "\""; - out << " applyProtection=\""<< !xfGrbitAtr->bit6 << "\""; - + out << " applyAlignment=\"" << !xfGrbitAtr->bit3 << "\""; + out << " applyProtection=\"" << !xfGrbitAtr->bit6 << "\""; - if (fields->alc > 0 || fields->alcv > 0 || indent || trot || fields->iReadingOrder || fields->fShrinkToFit || fields->fWrap || fields->fJustLast) { + if ( + fields->alc > 0 || fields->alcv > 0 || indent || trot || fields->iReadingOrder || + fields->fShrinkToFit || fields->fWrap || fields->fJustLast) { out << ">alc); out << valign(fields->alcv); if (fields->fWrap) - out << " wrapText=\"" << fields->fWrap <<"\""; + out << " wrapText=\"" << fields->fWrap << "\""; if (fields->fShrinkToFit) - out << " shrinkToFit=\"" << fields->fWrap <<"\""; + out << " shrinkToFit=\"" << fields->fWrap << "\""; // something is not quite right here. - // I have a file which is left to right, but this here returns 2: right to left + // I have a file which is left to right, but this here returns 2: + // right to left if (fields->iReadingOrder) - out << " readingOrder=\"" << (uint16_t)fields->iReadingOrder <<"\""; + out << " readingOrder=\"" << (uint16_t)fields->iReadingOrder << "\""; if (indent) - out << " indent=\"" << (uint16_t)indent/3 <<"\""; + out << " indent=\"" << (uint16_t)indent / 3 << "\""; if (fields->fJustLast) - out << " justifyLastLine=\"" << fields->fJustLast <<"\""; + out << " justifyLastLine=\"" << fields->fJustLast << "\""; if (trot) - out << " textRotation=\"" << (uint16_t)trot <<"\""; + out << " textRotation=\"" << (uint16_t)trot << "\""; out << "/>"; out << "" << std::endl; @@ -466,31 +481,28 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { break; } - case BrtEndCellXFs: - { + case BrtEndCellXFs: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } // cellStyles - case BrtBeginStyles: - { + case BrtBeginStyles: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtStyle: - { + case BrtStyle: { - uint8_t iStyBuiltIn = 0, iLevel = 0; + uint8_t iStyBuiltIn = 0, iLevel = 0; uint16_t grbitObj1 = 0; - uint32_t ixf = 0; - ixf = readbin(ixf, bin, swapit); - grbitObj1 = readbin(grbitObj1, bin, swapit); - iStyBuiltIn = readbin(iStyBuiltIn, bin, swapit); - iLevel = readbin(iLevel, bin, swapit); + uint32_t ixf = 0; + ixf = readbin(ixf, bin, swapit); + grbitObj1 = readbin(grbitObj1, bin, swapit); + iStyBuiltIn = readbin(iStyBuiltIn, bin, swapit); + iLevel = readbin(iLevel, bin, swapit); std::string stName = XLWideString(bin, swapit); // StyleFlagsFields *fields = (StyleFlagsFields *)&grbitObj1; @@ -500,74 +512,65 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { out << " builtinId=\"" << (int32_t)iStyBuiltIn << "\""; out << " />" << std::endl; - // bin.seekg(size, bin.cur); break; } - case BrtEndStyles: - { + case BrtEndStyles: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginColorPalette: - { - out << "" <" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginIndexedColors: - { - out << "" <" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtIndexedColor: - { + case BrtIndexedColor: { uint8_t bRed = 0, bGreen = 0, bBlue = 0, reserved = 0; - bRed = readbin(bRed, bin, swapit); - bGreen = readbin(bGreen, bin, swapit); - bBlue = readbin(bBlue, bin, swapit); + bRed = readbin(bRed, bin, swapit); + bGreen = readbin(bGreen, bin, swapit); + bBlue = readbin(bBlue, bin, swapit); reserved = readbin(reserved, bin, swapit); // std::vector color = brtColor(bin); // if (color[0] == 0x02) { - out << "" << std::endl; + out << "" + << std::endl; // } break; } - case BrtEndIndexedColors: - { - out << "" <" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndColorPalette: - { - out << "" <" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginDXFs: - { + case BrtBeginDXFs: { uint32_t cdxfs = 0; - cdxfs = readbin(cdxfs, bin, swapit); + cdxfs = readbin(cdxfs, bin, swapit); out << "" << std::endl; break; } - // This is a todo. the xfPropDataBlob is almost the entire styles part again - // case BrtDXF: + // This is a todo. the xfPropDataBlob is almost the entire styles part + // again case BrtDXF: // { // uint16_t flags = 0, reserved = 0, cprops = 0; // flags = readbin(flags, bin, swapit); @@ -578,33 +581,27 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { // break; // } - case BrtEndDXFs: - { + case BrtEndDXFs: { out << "" << std::endl; break; } - case BrtEndStyleSheet: - { + case BrtEndStyleSheet: { end_of_style_sheet = true; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - default: - { + default: { if (debug) { - Rcpp::Rcout << "Unhandled Style: " << std::to_string(x) << - ": " << std::to_string(size) << - " @ " << bin.tellg() << std::endl; - } + Rcpp::Rcout << "Unhandled Style: " << std::to_string(x) << ": " << std::to_string(size) + << " @ " << bin.tellg() << std::endl; + } bin.seekg(size, bin.cur); break; } - } - } out.close(); @@ -613,7 +610,6 @@ int32_t styles_bin(std::string filePath, std::string outPath, bool debug) { } else { return -1; }; - } // [[Rcpp::export]] @@ -627,59 +623,64 @@ int32_t table_bin(std::string filePath, std::string outPath, bool debug) { // auto sas_size = bin.tellg(); if (bin) { bin.seekg(0, std::ios_base::beg); - bool end_of_table = false; + bool end_of_table = false; bool has_revision_record = false; - while(!end_of_table) { + while (!end_of_table) { Rcpp::checkUserInterrupt(); int32_t x = 0, size = 0; - if (debug) Rcpp::Rcout << "." << std::endl; + if (debug) + Rcpp::Rcout << "." << std::endl; RECORD(x, size, bin, swapit); - if (debug) Rcpp::Rcout << x << ": " << size << std::endl; + if (debug) + Rcpp::Rcout << x << ": " << size << std::endl; - switch(x) { + switch (x) { - case BrtUID: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtUID: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginList: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginList: { + if (debug) + Rcpp::Rcout << "
" << std::endl; std::vector rfxList = UncheckedRfX(bin, swapit); - std::string ref = int_to_col(rfxList[2] + 1) + std::to_string(rfxList[0] + 1) + ":" + int_to_col(rfxList[3] + 1) + std::to_string(rfxList[1] + 1); + std::string ref = int_to_col(rfxList[2] + 1) + std::to_string(rfxList[0] + 1) + ":" + + int_to_col(rfxList[3] + 1) + std::to_string(rfxList[1] + 1); - if (debug) Rcpp::Rcout << "table ref: " << ref << std::endl; + if (debug) + Rcpp::Rcout << "table ref: " << ref << std::endl; uint32_t lt = 0, idList = 0, crwHeader = 0, crwTotals = 0, flags = 0; - lt = readbin(lt, bin, swapit); - idList = readbin(idList, bin, swapit); + lt = readbin(lt, bin, swapit); + idList = readbin(idList, bin, swapit); crwHeader = readbin(crwHeader, bin, swapit); crwTotals = readbin(crwTotals, bin, swapit); - flags = readbin(flags, bin, swapit); + flags = readbin(flags, bin, swapit); - uint32_t nDxfHeader = 0, nDxfData = 0, nDxfAgg = 0, nDxfBorder = 0, nDxfHeaderBorder = 0, nDxfAggBorder = 0, dwConnID = 0; + uint32_t nDxfHeader = 0, nDxfData = 0, nDxfAgg = 0, nDxfBorder = 0, nDxfHeaderBorder = 0, + nDxfAggBorder = 0, dwConnID = 0; - nDxfHeader = readbin(nDxfHeader, bin, swapit); - nDxfData = readbin(nDxfData, bin, swapit); - nDxfAgg = readbin(nDxfAgg, bin, swapit); - nDxfBorder = readbin(nDxfBorder, bin, swapit); + nDxfHeader = readbin(nDxfHeader, bin, swapit); + nDxfData = readbin(nDxfData, bin, swapit); + nDxfAgg = readbin(nDxfAgg, bin, swapit); + nDxfBorder = readbin(nDxfBorder, bin, swapit); nDxfHeaderBorder = readbin(nDxfHeaderBorder, bin, swapit); - nDxfAggBorder = readbin(nDxfAggBorder, bin, swapit); - dwConnID = readbin(dwConnID, bin, swapit); + nDxfAggBorder = readbin(nDxfAggBorder, bin, swapit); + dwConnID = readbin(dwConnID, bin, swapit); - std::string stName = XLNullableWideString(bin, swapit); + std::string stName = XLNullableWideString(bin, swapit); std::string stDisplayName = XLNullableWideString(bin, swapit); - std::string stComment = XLNullableWideString(bin, swapit); + std::string stComment = XLNullableWideString(bin, swapit); std::string stStyleHeader = XLNullableWideString(bin, swapit); - std::string stStyleData = XLNullableWideString(bin, swapit); - std::string stStyleAgg = XLNullableWideString(bin, swapit); + std::string stStyleData = XLNullableWideString(bin, swapit); + std::string stStyleAgg = XLNullableWideString(bin, swapit); if (debug) { Rcpp::Rcout << "table:" << std::endl; Rcpp::Rcout << stName << std::endl; @@ -690,22 +691,26 @@ int32_t table_bin(std::string filePath, std::string outPath, bool debug) { Rcpp::Rcout << stStyleAgg << std::endl; } - out << "
" << std::endl; + out << "
" << std::endl; // if (debug) Rcpp::Rcout << bin.tellg() << std::endl; break; } // this is used in worksheet as well. move it to function? - case BrtBeginAFilter: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginAFilter: { + if (debug) + Rcpp::Rcout << "" << std::endl; std::vector rfx = UncheckedRfX(bin, swapit); std::string lref = int_to_col(rfx[2] + 1) + std::to_string(rfx[0] + 1); @@ -715,7 +720,7 @@ int32_t table_bin(std::string filePath, std::string outPath, bool debug) { if (lref.compare(rref) == 0) { ref = lref; } else { - ref = lref + ":" + rref; + ref = lref + ":" + rref; } // ignoring filterColumn for now @@ -726,85 +731,84 @@ int32_t table_bin(std::string filePath, std::string outPath, bool debug) { break; } - case BrtBeginFilterColumn: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginFilterColumn: { + if (debug) + Rcpp::Rcout << "" << std::endl; uint16_t flags = 0; uint32_t dwCol = 0; - dwCol = readbin(dwCol, bin, swapit); - flags = readbin(flags, bin, swapit); + dwCol = readbin(dwCol, bin, swapit); + flags = readbin(flags, bin, swapit); // fHideArrow // fNoBtn - out << "" << std::endl; + out << "" << std::endl; break; } - case BrtBeginFilters: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginFilters: { + if (debug) + Rcpp::Rcout << "" << std::endl; // bin.seekg(size, bin.cur); uint32_t fBlank = 0, unused = 0; - fBlank = readbin(fBlank, bin, swapit); // a 32bit flag, after all ... why not? + fBlank = readbin(fBlank, bin, + swapit); // a 32bit flag, after all ... why not? unused = readbin(unused, bin, swapit); // maybe calendarType? - out << "" << std::endl; + out << "" << std::endl; break; } - case BrtFilter: - { + case BrtFilter: { std::string rgch = XLWideString(bin, swapit); out << "" << std::endl; // bin.seekg(size, bin.cur); break; } - case BrtEndFilters: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndFilters: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtColorFilter: - { + case BrtColorFilter: { uint32_t dxfid = 0, fCellColor = 0; - dxfid = readbin(dxfid, bin, swapit); + dxfid = readbin(dxfid, bin, swapit); fCellColor = readbin(fCellColor, bin, swapit); - out << "" << std::endl; + out << "" + << std::endl; break; } case BrtBeginCustomFilters: case BrtBeginCustomFilters14: - case BrtBeginCustomRichFilters: - { + case BrtBeginCustomRichFilters: { int32_t fAnd = 0; // in xlsb it is flipped fAnd = readbin(fAnd, bin, swapit) ^ 1; out << ""; break; } case BrtCustomFilter: - case BrtCustomFilter14: - { - int8_t vts = 0, grbitSgn = 0; - double union_val = 0; + case BrtCustomFilter14: { + int8_t vts = 0, grbitSgn = 0; + double union_val = 0; std::string vtsStringXls; - vts = readbin(vts, bin, swapit); + vts = readbin(vts, bin, swapit); grbitSgn = readbin(grbitSgn, bin, swapit); if (vts == 4) { @@ -813,8 +817,8 @@ int32_t table_bin(std::string filePath, std::string outPath, bool debug) { } else if (vts == 8) { // a bool int8_t boolean = 0; - boolean = readbin(boolean, bin, swapit); - union_val = static_cast(readbin(boolean, bin, swapit)); + boolean = readbin(boolean, bin, swapit); + union_val = static_cast(readbin(boolean, bin, swapit)); for (int8_t blk = 0; blk < 7; ++blk) { readbin(boolean, bin, swapit); } @@ -839,122 +843,120 @@ int32_t table_bin(std::string filePath, std::string outPath, bool debug) { } case BrtEndCustomFilters: - case BrtEndCustomRichFilters: - { + case BrtEndCustomRichFilters: { out << "" << std::endl; break; } - case BrtDynamicFilter: - { + case BrtDynamicFilter: { Rcpp::warning("Dynamic Filter found. This is not handled."); bin.seekg(size, bin.cur); break; } case BrtIconFilter: - case BrtIconFilter14: - { + case BrtIconFilter14: { uint32_t iIconSet = 0, iIcon = 0; iIconSet = readbin(iIconSet, bin, swapit); - iIcon = readbin(iIcon, bin, swapit); + iIcon = readbin(iIcon, bin, swapit); std::string iconSet; - if (iIconSet) iconSet = to_iconset(iIconSet); + if (iIconSet) + iconSet = to_iconset(iIconSet); - out << "" << std::endl; + out << "" + << std::endl; break; } - case BrtEndFilterColumn: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndFilterColumn: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndAFilter: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndAFilter: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginListCols: - { + case BrtBeginListCols: { uint32_t nCols = 0; - nCols = readbin(nCols, bin, swapit); + nCols = readbin(nCols, bin, swapit); out << "" << std::endl; // bin.seekg(size, bin.cur); break; } - case BrtBeginListCol: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginListCol: { + if (debug) + Rcpp::Rcout << "" << std::endl; // bin.seekg(size, bin.cur); // break; uint32_t idField = 0, ilta = 0, nDxfHdr = 0, nDxfInsertRow = 0, nDxfAgg = 0, idqsif = 0; - idField = readbin(idField, bin, swapit); - ilta = readbin(ilta, bin, swapit); - nDxfHdr = readbin(nDxfHdr, bin, swapit); - nDxfInsertRow = readbin(nDxfInsertRow, bin, swapit); - nDxfAgg = readbin(nDxfAgg, bin, swapit); - idqsif = readbin(idqsif, bin, swapit); - std::string stName = XLNullableWideString(bin, swapit); + idField = readbin(idField, bin, swapit); + ilta = readbin(ilta, bin, swapit); + nDxfHdr = readbin(nDxfHdr, bin, swapit); + nDxfInsertRow = readbin(nDxfInsertRow, bin, swapit); + nDxfAgg = readbin(nDxfAgg, bin, swapit); + idqsif = readbin(idqsif, bin, swapit); + std::string stName = XLNullableWideString(bin, swapit); std::string stCaption = XLNullableWideString(bin, swapit); - std::string stTotal = XLNullableWideString(bin, swapit); - if (debug) Rcpp::Rcout << stName << ": " << stCaption << ": " << stTotal<< std::endl; - std::string stStyleHeader = XLNullableWideString(bin, swapit); + std::string stTotal = XLNullableWideString(bin, swapit); + if (debug) + Rcpp::Rcout << stName << ": " << stCaption << ": " << stTotal << std::endl; + std::string stStyleHeader = XLNullableWideString(bin, swapit); std::string stStyleInsertRow = XLNullableWideString(bin, swapit); - std::string stStyleAgg = XLNullableWideString(bin, swapit); - if (debug) Rcpp::Rcout << stStyleHeader << ": " << stStyleInsertRow << ": " << stStyleAgg << std::endl; + std::string stStyleAgg = XLNullableWideString(bin, swapit); + if (debug) + Rcpp::Rcout << stStyleHeader << ": " << stStyleInsertRow << ": " << stStyleAgg + << std::endl; out << "" << std::endl; break; } - case BrtEndListCol: - { + case BrtEndListCol: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndListCols: - { + case BrtEndListCols: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndList: - { + case BrtEndList: { end_of_table = true; out << "
" << std::endl; break; } - case BrtListCCFmla: - { + case BrtListCCFmla: { // calculated column formula - uint8_t flags = 0; + uint8_t flags = 0; std::string fml; - flags = readbin(flags, bin, swapit); + flags = readbin(flags, bin, swapit); int32_t sharedFormula = false; fml = CellParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); // need to write this formula somehwere // if (debug) Rcpp::Rcout << fml << std::endl; - if (debug) Rcpp::warning("Table formulas are not fully implemented."); + if (debug) + Rcpp::warning("Table formulas are not fully implemented."); out << ""; out << fml; @@ -963,44 +965,43 @@ int32_t table_bin(std::string filePath, std::string outPath, bool debug) { break; } - case BrtTableStyleClient: - { - uint16_t flags = 0; - flags = readbin(flags, bin, swapit); + case BrtTableStyleClient: { + uint16_t flags = 0; + flags = readbin(flags, bin, swapit); std::string stStyleName = XLNullableWideString(bin, swapit); - BrtTableStyleClientFields *fields = (BrtTableStyleClientFields*)&flags; - - out << "fColumnHeaders << "\""; // not part of tableStyleInfo? - out <<" showFirstColumn=\"" << fields->fFirstColumn << "\""; - out <<" showLastColumn=\"" << fields->fLastColumn << "\""; - // out <<" showRowHeaders=\"" << fields->fRowHeaders << "\""; // not part of tableStyleInfo? - out <<" showRowStripes=\"" << fields->fRowStripes << "\""; - out <<" showColumnStripes=\"" << fields->fColumnStripes << "\""; + BrtTableStyleClientFields *fields = (BrtTableStyleClientFields *)&flags; + + out << "fColumnHeaders << "\""; // not + // part of tableStyleInfo? + out << " showFirstColumn=\"" << fields->fFirstColumn << "\""; + out << " showLastColumn=\"" << fields->fLastColumn << "\""; + // out <<" showRowHeaders=\"" << fields->fRowHeaders << "\""; // not + // part of tableStyleInfo? + out << " showRowStripes=\"" << fields->fRowStripes << "\""; + out << " showColumnStripes=\"" << fields->fColumnStripes << "\""; out << " />" << std::endl; break; } case BrtRRChgCell: - case BrtRRDefName: - { + case BrtRRDefName: { has_revision_record = true; - // -- have not seen this yet. if it appears, treat it as if a revision record was found -- - // rgce.rgce or rgceOld.rgce in BrtRRDefName - if (debug) Rcpp::Rcout << "BrtRRChgCell or BrtRRDefName" << std::endl; + // -- have not seen this yet. if it appears, treat it as if a revision + // record was found -- rgce.rgce or rgceOld.rgce in BrtRRDefName + if (debug) + Rcpp::Rcout << "BrtRRChgCell or BrtRRDefName" << std::endl; Rcpp::warning("Assuming revision record."); bin.seekg(size, bin.cur); break; } - default: - { + default: { if (debug) { - Rcpp::Rcout << std::to_string(x) << - ": " << std::to_string(size) << - " @ " << bin.tellg() << std::endl; - } + Rcpp::Rcout << std::to_string(x) << ": " << std::to_string(size) << " @ " << bin.tellg() + << std::endl; + } bin.seekg(size, bin.cur); break; } @@ -1013,10 +1014,8 @@ int32_t table_bin(std::string filePath, std::string outPath, bool debug) { } else { return -1; }; - } - // [[Rcpp::export]] int32_t comments_bin(std::string filePath, std::string outPath, bool debug) { @@ -1030,53 +1029,56 @@ int32_t comments_bin(std::string filePath, std::string outPath, bool debug) { bin.seekg(0, std::ios_base::beg); bool end_of_comments = false; - while(!end_of_comments) { + while (!end_of_comments) { Rcpp::checkUserInterrupt(); int32_t x = 0, size = 0; - if (debug) Rcpp::Rcout << "." << std::endl; + if (debug) + Rcpp::Rcout << "." << std::endl; RECORD(x, size, bin, swapit); - if (debug) Rcpp::Rcout << x << ": " << size << std::endl; + if (debug) + Rcpp::Rcout << x << ": " << size << std::endl; - switch(x) { + switch (x) { - case BrtBeginComments: - { - out << "" << std::endl; + case BrtBeginComments: { + out << "" + << std::endl; break; } - case BrtBeginCommentAuthors: - { + case BrtBeginCommentAuthors: { out << "" << std::endl; break; } - case BrtCommentAuthor: - { + case BrtCommentAuthor: { std::string author = XLWideString(bin, swapit); out << "" << author << "" << std::endl; break; } - case BrtEndCommentAuthors: - { + case BrtEndCommentAuthors: { out << "" << std::endl; break; } - case BrtBeginCommentList: - { + case BrtBeginCommentList: { out << "" << std::endl; break; } - case BrtBeginComment: - { + case BrtBeginComment: { uint32_t iauthor = 0; - int32_t guid0 = 0, guid1 = 0, guid2 = 0, guid3 = 0; - iauthor = readbin(iauthor, bin, swapit); + int32_t guid0 = 0, guid1 = 0, guid2 = 0, guid3 = 0; + iauthor = readbin(iauthor, bin, swapit); std::vector rfx = UncheckedRfX(bin, swapit); std::string lref = int_to_col(rfx[2] + 1) + std::to_string(rfx[0] + 1); @@ -1086,7 +1088,7 @@ int32_t comments_bin(std::string filePath, std::string outPath, bool debug) { if (lref.compare(rref) == 0) { ref = lref; } else { - ref = lref + ":" + rref; + ref = lref + ":" + rref; } std::vector guids(4); @@ -1104,42 +1106,38 @@ int32_t comments_bin(std::string filePath, std::string outPath, bool debug) { break; } - case BrtEndComment: - { + case BrtEndComment: { out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndCommentList: - { + case BrtEndCommentList: { out << "" << std::endl; break; } - case BrtCommentText: - { + case BrtCommentText: { // we do not handle RichStr correctly. Ignore all formatting std::string commentText = RichStr(bin, swapit); - // out << "" << escape_xml(commentText) << "" << std::endl; + // out << "" << + // escape_xml(commentText) << "" << std::endl; out << "" << commentText << "" << std::endl; break; } - case BrtEndComments: - { + case BrtEndComments: { end_of_comments = true; out << "" << std::endl; break; } - default: - { + default: { if (debug) { - Rcpp::Rcout << std::to_string(x) << - ": " << std::to_string(size) << - " @ " << bin.tellg() << std::endl; - } + Rcpp::Rcout << std::to_string(x) << ": " << std::to_string(size) << " @ " << bin.tellg() + << std::endl; + } bin.seekg(size, bin.cur); break; } @@ -1152,7 +1150,6 @@ int32_t comments_bin(std::string filePath, std::string outPath, bool debug) { } else { return -1; }; - } // [[Rcpp::export]] int32_t externalreferences_bin(std::string filePath, std::string outPath, bool debug) { @@ -1165,25 +1162,26 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d // auto sas_size = bin.tellg(); if (bin) { bin.seekg(0, std::ios_base::beg); - bool first_row = true; - int32_t row = 0; - bool end_of_external_reference = false; + bool first_row = true; + int32_t row = 0; + bool end_of_external_reference = false; - while(!end_of_external_reference) { + while (!end_of_external_reference) { Rcpp::checkUserInterrupt(); int32_t x = 0, size = 0; - if (debug) Rcpp::Rcout << "." << std::endl; + if (debug) + Rcpp::Rcout << "." << std::endl; RECORD(x, size, bin, swapit); - if (debug) Rcpp::Rcout << x << ": " << size << std::endl; + if (debug) + Rcpp::Rcout << x << ": " << size << std::endl; - switch(x) { + switch (x) { - case BrtBeginSupBook: - { + case BrtBeginSupBook: { uint16_t sbt = 0; - sbt = readbin(sbt, bin, swapit); + sbt = readbin(sbt, bin, swapit); // wb. 0x0000 // dde 0x0001 // ole 0x0002 @@ -1196,27 +1194,41 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d else string2 = XLWideString(bin, swapit); - if (debug) Rcpp::Rcout << string1 << ": " << string2 << std::endl; + if (debug) + Rcpp::Rcout << string1 << ": " << string2 << std::endl; // no begin externalSheet? - out << "" << std::endl; + out << "" + << std::endl; // assume for now all external references are workbooks - out << "" << std::endl; + out << "" << std::endl; break; } - // looks like this file has case 5108: - // xxl21:absoluteUrl + // looks like this file has case 5108: + // xxl21:absoluteUrl - case BrtSupTabs: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtSupTabs: { + if (debug) + Rcpp::Rcout << "" << std::endl; uint32_t cTab = 0; cTab = readbin(cTab, bin, swapit); - if (cTab > 65535) Rcpp::stop("cTab to large"); + if (cTab > 65535) + Rcpp::stop("cTab to large"); out << "" << std::endl; @@ -1233,13 +1245,13 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d break; } - case BrtExternTableStart: - { - if (debug) Rcpp::Rcout << "" << std::endl; - uint8_t flags = 0; - uint32_t iTab = 0; - iTab = readbin(iTab, bin, debug); - flags = readbin(flags, bin, debug); + case BrtExternTableStart: { + if (debug) + Rcpp::Rcout << "" << std::endl; + uint8_t flags = 0; + uint32_t iTab = 0; + iTab = readbin(iTab, bin, debug); + flags = readbin(flags, bin, debug); first_row = true; out << "" << std::endl; @@ -1247,15 +1259,15 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d break; } - case BrtExternRowHdr: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtExternRowHdr: { + if (debug) + Rcpp::Rcout << "" << std::endl; row = UncheckedRw(bin, swapit); // close open rows if (!first_row) { - out << "" <" << std::endl; } else { first_row = false; } @@ -1264,9 +1276,9 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d break; } - case BrtExternCellBlank: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtExternCellBlank: { + if (debug) + Rcpp::Rcout << "" << std::endl; int32_t col = UncheckedCol(bin, swapit); out << "" << std::endl; @@ -1274,13 +1286,13 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d break; } - case BrtExternCellBool: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtExternCellBool: { + if (debug) + Rcpp::Rcout << "" << std::endl; uint8_t value = 0; - int32_t col = UncheckedCol(bin, swapit); - value = readbin(value, bin, swapit); + int32_t col = UncheckedCol(bin, swapit); + value = readbin(value, bin, swapit); out << "" << std::endl; out << "" << (uint16_t)value << "" << std::endl; out << "" << std::endl; @@ -1288,13 +1300,13 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d break; } - case BrtExternCellError: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtExternCellError: { + if (debug) + Rcpp::Rcout << "" << std::endl; std::string value; - int32_t col = UncheckedCol(bin, swapit); - value = BErr(bin, swapit); + int32_t col = UncheckedCol(bin, swapit); + value = BErr(bin, swapit); out << "" << std::endl; out << "" << value << "" << std::endl; out << "" << std::endl; @@ -1302,13 +1314,13 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d break; } - case BrtExternCellReal: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtExternCellReal: { + if (debug) + Rcpp::Rcout << "" << std::endl; - double value = 0; - int32_t col = UncheckedCol(bin, swapit); - value = Xnum(bin, swapit); + double value = 0; + int32_t col = UncheckedCol(bin, swapit); + value = Xnum(bin, swapit); out << "" << std::endl; out << "" << value << "" << std::endl; out << "" << std::endl; @@ -1316,11 +1328,11 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d break; } - case BrtExternCellString: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtExternCellString: { + if (debug) + Rcpp::Rcout << "" << std::endl; - int32_t col = UncheckedCol(bin, swapit); + int32_t col = UncheckedCol(bin, swapit); std::string value = XLWideString(bin, swapit); out << "" << std::endl; out << "" << value << "" << std::endl; @@ -1329,18 +1341,18 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d break; } - case BrtExternTableEnd: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtExternTableEnd: { + if (debug) + Rcpp::Rcout << "" << std::endl; - if (!first_row) out << "" << std::endl; + if (!first_row) + out << "" << std::endl; out << "" << std::endl; break; } - case BrtEndSupBook: - { + case BrtEndSupBook: { end_of_external_reference = true; out << "" << std::endl; out << "" << std::endl; @@ -1350,21 +1362,18 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d case BrtACBegin: case BrtExternalLinksAlternateUrls: - case BrtACEnd: - { + case BrtACEnd: { // unhandled bin.seekg(size, bin.cur); break; } - default: - { + default: { // if (debug) { - Rcpp::Rcout << "Unhandled ER: " << std::to_string(x) << - ": " << std::to_string(size) << - " @ " << bin.tellg() << std::endl; - // } + Rcpp::Rcout << "Unhandled ER: " << std::to_string(x) << ": " << std::to_string(size) + << " @ " << bin.tellg() << std::endl; + // } bin.seekg(size, bin.cur); break; } @@ -1377,10 +1386,8 @@ int32_t externalreferences_bin(std::string filePath, std::string outPath, bool d } else { return -1; }; - } - // [[Rcpp::export]] int32_t sharedstrings_bin(std::string filePath, std::string outPath, bool debug) { @@ -1394,41 +1401,39 @@ int32_t sharedstrings_bin(std::string filePath, std::string outPath, bool debug) bin.seekg(0, std::ios_base::beg); bool end_of_shared_strings = false; - while(!end_of_shared_strings) { + while (!end_of_shared_strings) { Rcpp::checkUserInterrupt(); int32_t x = 0, size = 0; - if (debug) Rcpp::Rcout << "." << std::endl; + if (debug) + Rcpp::Rcout << "." << std::endl; RECORD(x, size, bin, swapit); - if (debug) Rcpp::Rcout << x << ": " << size << std::endl; + if (debug) + Rcpp::Rcout << x << ": " << size << std::endl; - switch(x) { + switch (x) { - case BrtBeginSst: - { - uint32_t count= 0, uniqueCount= 0; - count = readbin(count, bin, swapit); + case BrtBeginSst: { + uint32_t count = 0, uniqueCount = 0; + count = readbin(count, bin, swapit); uniqueCount = readbin(uniqueCount, bin, swapit); - out << "" << std::endl; + out << "" + << std::endl; break; } - case BrtSSTItem: - { - std::string val; + case BrtSSTItem: { + std::string val; std::streampos pos = bin.tellg(); pos += static_cast(size); val += RichStr(bin, swapit); - if(bin.tellg() < pos) { + if (bin.tellg() < pos) { // if (debug) { - // some RichStr() behave different to what is documented. Not sure - // if this is padding or something else. 12 bytes seems common - size_t missing = static_cast(pos - bin.tellg()); - Rcpp::Rcout << "BrtSSTItem skipping ahead (bytes): " << missing << std::endl; + // some RichStr() behave different to what is documented. Not sure + // if this is padding or something else. 12 bytes seems common + size_t missing = static_cast(pos - bin.tellg()); + Rcpp::Rcout << "BrtSSTItem skipping ahead (bytes): " << missing << std::endl; // } bin.seekg(pos, bin.beg); } @@ -1437,21 +1442,18 @@ int32_t sharedstrings_bin(std::string filePath, std::string outPath, bool debug) break; } - case BrtEndSst: - { + case BrtEndSst: { end_of_shared_strings = true; out << "" << std::endl; break; } - default: - { + default: { // if (debug) { - Rcpp::Rcout << std::to_string(x) << - ": " << std::to_string(size) << - " @ " << bin.tellg() << std::endl; - // } - Rcpp::stop("nonsense"); + Rcpp::Rcout << std::to_string(x) << ": " << std::to_string(size) << " @ " << bin.tellg() + << std::endl; + // } + Rcpp::stop("nonsense"); bin.seekg(size, bin.cur); break; } @@ -1464,7 +1466,6 @@ int32_t sharedstrings_bin(std::string filePath, std::string outPath, bool debug) } else { return -1; }; - } // [[Rcpp::export]] @@ -1478,132 +1479,147 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { // auto sas_size = bin.tellg(); if (bin) { bin.seekg(0, std::ios_base::beg); - bool end_of_workbook = false; - bool first_extern_sheet = true; + bool end_of_workbook = false; + bool first_extern_sheet = true; bool has_revision_record = false; std::vector defNams, xtis, reference_type, customWorkbookView; defNams.push_back(""); xtis.push_back(""); - while(!end_of_workbook) { + while (!end_of_workbook) { Rcpp::checkUserInterrupt(); int32_t x = 0, size = 0; - if (debug) Rcpp::Rcout << "." << std::endl; + if (debug) + Rcpp::Rcout << "." << std::endl; RECORD(x, size, bin, swapit); - switch(x) { + switch (x) { - case BrtBeginBook: - { - if (debug) Rcpp::Rcout << "" << std::endl; - out << "" << std::endl; + case BrtBeginBook: { + if (debug) + Rcpp::Rcout << "" << std::endl; + out << "" + << std::endl; bin.seekg(size, bin.cur); break; } - case BrtFileVersion: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtFileVersion: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtWbProp: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtWbProp: { + if (debug) + Rcpp::Rcout << "" << std::endl; uint32_t flags = 0, dwThemeVersion = 0; - flags = readbin(flags, bin, swapit); - dwThemeVersion = readbin(dwThemeVersion, bin, swapit); + flags = readbin(flags, bin, swapit); + dwThemeVersion = readbin(dwThemeVersion, bin, swapit); std::string strName = XLWideString(bin, swapit); BrtWbPropFields *fields = (BrtWbPropFields *)&flags; - out << - "fAutoCompressPictures << "\" " << - " backupFile=\"" << fields->fBackup << "\" " << - " checkCompatibility=\"" << fields->fCheckCompat << "\" " << - " codeName=\"" << strName << "\" " << - " date1904=\"" << fields->f1904 << "\" " << - " defaultThemeVersion=\"" << dwThemeVersion << "\" " << - " filterPrivacy=\"" << fields->fFilterPrivacy << "\" " << - " hidePivotFieldList=\"" << fields->fHidePivotTableFList << "\" " << - " promptedSolutions=\"" << fields->fBuggedUserAboutSolution << "\" " << - " publishItems=\"" << fields->fPublishedBookItems << "\" " << - " refreshAllConnections=\"" << fields->fRefreshAll << "\" " << - " saveExternalLinkValues=\"" << fields->fNoSaveSup << "\" " << + " autoCompressPictures=\"" << fields->fAutoCompressPictures << "\" " + << " backupFile=\"" << fields->fBackup << "\" " + << " checkCompatibility=\"" << fields->fCheckCompat << "\" " + << " codeName=\"" << strName << "\" " << " date1904=\"" << fields->f1904 << "\" " + << " defaultThemeVersion=\"" << dwThemeVersion << "\" " + << " filterPrivacy=\"" << fields->fFilterPrivacy << "\" " + << " hidePivotFieldList=\"" << fields->fHidePivotTableFList << "\" " + << " promptedSolutions=\"" << fields->fBuggedUserAboutSolution << "\" " + << " publishItems=\"" << fields->fPublishedBookItems << "\" " + << " refreshAllConnections=\"" << fields->fRefreshAll << "\" " + << " saveExternalLinkValues=\"" << fields->fNoSaveSup << "\" " << // " showBorderUnselectedTables=\"" << << "\" " << - " showInkAnnotation=\"" << fields->fShowInkAnnotation << "\" " << - " showObjects=\"" << (uint32_t)fields->mdDspObj << "\" " << - " showPivotChartFilter=\"" << fields->fShowPivotChartFilter << "\" " << - " updateLinks=\"" << (uint32_t)fields->grbitUpdateLinks << "\" " << - "/>" << std::endl; + " showInkAnnotation=\"" << fields->fShowInkAnnotation << "\" " + << " showObjects=\"" << (uint32_t)fields->mdDspObj << "\" " + << " showPivotChartFilter=\"" << fields->fShowPivotChartFilter << "\" " + << " updateLinks=\"" << (uint32_t)fields->grbitUpdateLinks << "\" " << "/>" + << std::endl; break; } - case BrtACBegin: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtACBegin: { + if (debug) + Rcpp::Rcout << "" << std::endl; // bin.seekg(size, bin.cur); uint16_t cver = 0; - cver = readbin(cver, bin, swapit); + cver = readbin(cver, bin, swapit); for (uint16_t i = 0; i < cver; ++i) { ProductVersion(bin, swapit, debug); } break; - } - case BrtAbsPath15: - { + case BrtAbsPath15: { std::string absPath = XLWideString(bin, swapit); - if (debug) Rcpp::Rcout << absPath << std::endl; + if (debug) + Rcpp::Rcout << absPath << std::endl; break; } - case BrtACEnd: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtACEnd: { + if (debug) + Rcpp::Rcout << "" << std::endl; break; } - case BrtRevisionPtr: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtRevisionPtr: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtUID: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtUID: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginBookViews: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginBookViews: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBookView: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBookView: { + if (debug) + Rcpp::Rcout << "" << std::endl; // bin.seekg(size, bin.cur); - uint8_t flags = 0; - int32_t xWn = 0, yWn = 0; - uint32_t dxWn = 0, dyWn = 0, iTabRatio = 0, itabFirst= 0, itabCur = 0; + uint8_t flags = 0; + int32_t xWn = 0, yWn = 0; + uint32_t dxWn = 0, dyWn = 0, iTabRatio = 0, itabFirst = 0, itabCur = 0; xWn = readbin(xWn, bin, swapit); yWn = readbin(yWn, bin, swapit); dxWn = readbin(dxWn, bin, swapit); @@ -1613,35 +1629,36 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { itabCur = readbin(itabCur, bin, swapit); flags = readbin(flags, bin, swapit); - out << "" << std::endl; + out << "" + << std::endl; break; } - case BrtEndBookViews: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndBookViews: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtUserBookView: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtUserBookView: { + if (debug) + Rcpp::Rcout << "" << std::endl; std::ostringstream cwv; - int32_t xLeft = 0, xRight = 0, yTop = 0, yBot = 0, iTabid = 0, iTabRatio = 0, guid0 = 0, guid1 = 0, guid2 = 0, guid3 = 0, flags = 0; - int16_t wMergeInterval = 0; + int32_t xLeft = 0, xRight = 0, yTop = 0, yBot = 0, iTabid = 0, iTabRatio = 0, guid0 = 0, + guid1 = 0, guid2 = 0, guid3 = 0, flags = 0; + int16_t wMergeInterval = 0; std::string stName; - xLeft = readbin(xLeft, bin, swapit); - xRight = readbin(xRight, bin, swapit); - yTop = readbin(yTop, bin, swapit); - yBot = readbin(yBot, bin, swapit); - iTabid = readbin(iTabid, bin, swapit); + xLeft = readbin(xLeft, bin, swapit); + xRight = readbin(xRight, bin, swapit); + yTop = readbin(yTop, bin, swapit); + yBot = readbin(yBot, bin, swapit); + iTabid = readbin(iTabid, bin, swapit); iTabRatio = readbin(iTabRatio, bin, swapit); std::vector guids(4); @@ -1654,58 +1671,86 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { flags = readbin(flags, bin, swapit); - BrtUserBookViewFields *fields = (BrtUserBookViewFields*)&flags; + BrtUserBookViewFields *fields = (BrtUserBookViewFields *)&flags; stName = XLWideString(bin, swapit); std::string showComments; - if (fields->mdDspNote == 0) showComments = "commNone"; - if (fields->mdDspNote == 1) showComments = "commIndAndComment"; - if (fields->mdDspNote == 2) showComments = "commIndicator"; + if (fields->mdDspNote == 0) + showComments = "commNone"; + if (fields->mdDspNote == 1) + showComments = "commIndAndComment"; + if (fields->mdDspNote == 2) + showComments = "commIndicator"; std::string showObjects; - if (fields->mdHideObj == 0) showObjects = "all"; - if (fields->mdHideObj == 1) showObjects = "placeholders"; - if (fields->mdHideObj == 2) showObjects = "none"; + if (fields->mdHideObj == 0) + showObjects = "all"; + if (fields->mdHideObj == 1) + showObjects = "placeholders"; + if (fields->mdHideObj == 2) + showObjects = "none"; cwv << "fTimedUpdate) cwv << " autoUpdate=\"" << fields->fTimedUpdate << "\"" << std::endl; - if (fields->fTimedUpdate) cwv << " mergeInterval=\"" << wMergeInterval << "\"" << std::endl; - if (fields->fAllMemChanges) cwv << " changesSavedWin=\"" << fields->fAllMemChanges << "\"" << std::endl; - if (fields->fOnlySync) cwv << " onlySync=\"" << fields->fOnlySync << "\"" << std::endl; - if (fields->fPersonalView) cwv << " personalView=\"" << fields->fPersonalView << "\"" << std::endl; - if (!fields->fPrintIncl) cwv << " includePrintSettings=\"" << fields->fPrintIncl << "\"" << std::endl; + if (fields->fTimedUpdate) + cwv << " autoUpdate=\"" << fields->fTimedUpdate << "\"" << std::endl; + if (fields->fTimedUpdate) + cwv << " mergeInterval=\"" << wMergeInterval << "\"" << std::endl; + if (fields->fAllMemChanges) + cwv << " changesSavedWin=\"" << fields->fAllMemChanges << "\"" << std::endl; + if (fields->fOnlySync) + cwv << " onlySync=\"" << fields->fOnlySync << "\"" << std::endl; + if (fields->fPersonalView) + cwv << " personalView=\"" << fields->fPersonalView << "\"" << std::endl; + if (!fields->fPrintIncl) + cwv << " includePrintSettings=\"" << fields->fPrintIncl << "\"" << std::endl; // wrong? - // if (!fields->fRowColIncl) cwv << " includeHiddenRowCol=\"" << fields->fRowColIncl << "\"" << std::endl; - if (fields->fZoom) cwv << " maximized=\"" << fields->fZoom << "\"" << std::endl; - if (fields->fIconic) cwv << " minimized=\"" << fields->fIconic << "\"" << std::endl; - if (!fields->fDspHScroll) cwv << " showHorizontalScroll=\"" << fields->fDspHScroll << "\"" << std::endl; - if (!fields->fDspVScroll) cwv << " showVerticalScroll=\"" << fields->fDspVScroll << "\"" << std::endl; - if (!fields->fBotAdornment) cwv << " showSheetTabs=\"" << fields->fBotAdornment << "\"" << std::endl; - if (xLeft > 0) cwv << " xWindow=\"" << xLeft << "\"" << std::endl; - if (yTop > 0) cwv << " yWindow=\"" << yTop << "\"" << std::endl; - if (xRight > 0) cwv << " windowWidth=\"" << xRight << "\"" << std::endl; - if ((yBot - yTop) > 0) cwv << " windowHeight=\"" << (yBot - yTop) << "\"" << std::endl; - if (iTabRatio != 600) cwv << " tabRatio=\"" << iTabRatio << "\"" << std::endl; + // if (!fields->fRowColIncl) cwv << " includeHiddenRowCol=\"" << + // fields->fRowColIncl << "\"" << std::endl; + if (fields->fZoom) + cwv << " maximized=\"" << fields->fZoom << "\"" << std::endl; + if (fields->fIconic) + cwv << " minimized=\"" << fields->fIconic << "\"" << std::endl; + if (!fields->fDspHScroll) + cwv << " showHorizontalScroll=\"" << fields->fDspHScroll << "\"" << std::endl; + if (!fields->fDspVScroll) + cwv << " showVerticalScroll=\"" << fields->fDspVScroll << "\"" << std::endl; + if (!fields->fBotAdornment) + cwv << " showSheetTabs=\"" << fields->fBotAdornment << "\"" << std::endl; + if (xLeft > 0) + cwv << " xWindow=\"" << xLeft << "\"" << std::endl; + if (yTop > 0) + cwv << " yWindow=\"" << yTop << "\"" << std::endl; + if (xRight > 0) + cwv << " windowWidth=\"" << xRight << "\"" << std::endl; + if ((yBot - yTop) > 0) + cwv << " windowHeight=\"" << (yBot - yTop) << "\"" << std::endl; + if (iTabRatio != 600) + cwv << " tabRatio=\"" << iTabRatio << "\"" << std::endl; cwv << " activeSheetId=\"" << iTabid << "\"" << std::endl; - if (!fields->fDspFmlaBar) cwv << " showFormulaBar=\"" << fields->fDspFmlaBar << "\"" << std::endl; - if (!fields->fDspStatus) cwv << " showStatusbar=\"" << fields->fDspStatus << "\"" << std::endl; - if (showComments != "commIndicator") cwv << " showComments=\"" << showComments << "\"" << std::endl; - if (showObjects != "all") cwv << " showObjects=\"" << showObjects << "\"" << std::endl; + if (!fields->fDspFmlaBar) + cwv << " showFormulaBar=\"" << fields->fDspFmlaBar << "\"" << std::endl; + if (!fields->fDspStatus) + cwv << " showStatusbar=\"" << fields->fDspStatus << "\"" << std::endl; + if (showComments != "commIndicator") + cwv << " showComments=\"" << showComments << "\"" << std::endl; + if (showObjects != "all") + cwv << " showObjects=\"" << showObjects << "\"" << std::endl; cwv << "/>" << std::endl; - // Rcpp::Rcout << xLeft << ": " << xRight << ": " << yTop << ": " << yBot << std::endl; + // Rcpp::Rcout << xLeft << ": " << xRight << ": " << yTop << ": " << + // yBot << std::endl; customWorkbookView.push_back(cwv.str()); break; } - case BrtBeginBundleShs: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginBundleShs: { + if (debug) + Rcpp::Rcout << "" << std::endl; // unk = readbin(unk, bin, swapit); // unk = readbin(unk, bin, swapit); // uint32_t count, uniqueCount; @@ -1715,57 +1760,62 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { break; } - case BrtBundleSh: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBundleSh: { + if (debug) + Rcpp::Rcout << "" << std::endl; uint32_t hsState = 0, iTabID = 0; // strRelID ??? - hsState = readbin(hsState, bin, swapit); - iTabID = readbin(iTabID, bin, swapit); + hsState = readbin(hsState, bin, swapit); + iTabID = readbin(iTabID, bin, swapit); std::string rid = XLNullableWideString(bin, swapit); if (debug) - Rcpp::Rcout << "sheet vis: " << hsState << ": " << iTabID << ": " << rid << std::endl; + Rcpp::Rcout << "sheet vis: " << hsState << ": " << iTabID << ": " << rid << std::endl; std::string val = XLWideString(bin, swapit); std::string visible; - if (hsState == 0) visible = "visible"; - if (hsState == 1) visible = "hidden"; - if (hsState == 2) visible = "veryHidden"; + if (hsState == 0) + visible = "visible"; + if (hsState == 1) + visible = "hidden"; + if (hsState == 2) + visible = "veryHidden"; - out << "" << std::endl; + out << "" << std::endl; break; } - case BrtEndBundleShs: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndBundleShs: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; break; } - case BrtCalcProp: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtCalcProp: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtName: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtName: { + if (debug) + Rcpp::Rcout << "" << std::endl; std::streampos end_pos = bin.tellg(); end_pos += static_cast(size); - if (debug) Rcpp::Rcout << "BrtName endpos: "<< end_pos << std::endl; + if (debug) + Rcpp::Rcout << "BrtName endpos: " << end_pos << std::endl; - uint8_t chKey = 0; + uint8_t chKey = 0; uint16_t BrtNameUint = 0, BrtNameUint2 = 0; uint32_t itab = 0; - BrtNameUint = readbin(BrtNameUint, bin, swapit); - BrtNameUint2 = readbin(BrtNameUint2, bin, swapit); + BrtNameUint = readbin(BrtNameUint, bin, swapit); + BrtNameUint2 = readbin(BrtNameUint2, bin, swapit); BrtNameFields *fields = (BrtNameFields *)&BrtNameUint; // BrtNameFields2 *fields2 = (BrtNameFields2 *)&BrtNameUint2; @@ -1827,17 +1877,21 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { /* -- something is wrong. error with some nhs macro xlsb file -- */ // must be NULL - if (debug) Rcpp::Rcout << 1 << std::endl; + if (debug) + Rcpp::Rcout << 1 << std::endl; std::string unusedstring1 = XLNullableWideString(bin, swapit); // must be < 32768 characters - if (debug) Rcpp::Rcout << 2 << std::endl; + if (debug) + Rcpp::Rcout << 2 << std::endl; std::string description = XLNullableWideString(bin, swapit); - if (debug) Rcpp::Rcout << 3 << std::endl; + if (debug) + Rcpp::Rcout << 3 << std::endl; std::string helpTopic = XLNullableWideString(bin, swapit); // must be NULL - if (debug) Rcpp::Rcout << 4 << std::endl; + if (debug) + Rcpp::Rcout << 4 << std::endl; std::string unusedstring2 = XLNullableWideString(bin, swapit); } @@ -1864,16 +1918,16 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { defNam += "\" hidden=\"" + std::to_string(fields->fHidden); // lacks the formula for the defined name - defNam = defNam + "\">" + fml +""; + defNam = defNam + "\">" + fml + ""; defNams.push_back(defNam); break; } - case BrtBeginExternals: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginExternals: { + if (debug) + Rcpp::Rcout << "" << std::endl; // bin.seekg(size, bin.cur); break; } @@ -1883,177 +1937,174 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { // * BrtSupSame same sheet // * BrtSupAddin addin XLL // * BrtSupBookSrc external link - case BrtSupSelf: - { + case BrtSupSelf: { if (debug) - Rcpp::Rcout << "BrtSupSelf @"<< bin.tellg() << std::endl; + Rcpp::Rcout << "BrtSupSelf @" << bin.tellg() << std::endl; // Rcpp::Rcout << "" << std::endl; reference_type.push_back("0"); break; } - case BrtSupSame: - { + case BrtSupSame: { if (debug) - Rcpp::Rcout << "BrtSupSame @"<< bin.tellg() << std::endl; + Rcpp::Rcout << "BrtSupSame @" << bin.tellg() << std::endl; // Rcpp::Rcout << "" << std::endl; reference_type.push_back("1"); break; } - case BrtPlaceholderName: - { + case BrtPlaceholderName: { if (debug) - Rcpp::Rcout << "BrtPlaceholderName @"<< bin.tellg() << std::endl; + Rcpp::Rcout << "BrtPlaceholderName @" << bin.tellg() << std::endl; std::string name = XLWideString(bin, swapit); - // Rcpp::Rcout << "" << std::endl; + // Rcpp::Rcout << "" << + // std::endl; break; } - case BrtSupAddin: - { + case BrtSupAddin: { if (debug) - Rcpp::Rcout << "BrtSupAddin @"<< bin.tellg() << std::endl; + Rcpp::Rcout << "BrtSupAddin @" << bin.tellg() << std::endl; // Rcpp::Rcout << "" << std::endl; reference_type.push_back("2"); break; } - case BrtSupBookSrc: - { + case BrtSupBookSrc: { if (first_extern_sheet) { out << "" << std::endl; first_extern_sheet = false; } if (debug) - Rcpp::Rcout << "BrtSupBookSrc @"<< bin.tellg() << std::endl; + Rcpp::Rcout << "BrtSupBookSrc @" << bin.tellg() << std::endl; // Rcpp::stop("BrtSupSelf"); std::string strRelID = XLNullableWideString(bin, swapit); - out << "" << std::endl; + out << "" << std::endl; reference_type.push_back(strRelID); break; } - case BrtSupTabs: - { + case BrtSupTabs: { if (debug) Rcpp::Rcout << "" << std::endl; uint32_t cTab = 0; cTab = readbin(cTab, bin, swapit); - if (cTab > 65535) Rcpp::stop("cTab to large"); + if (cTab > 65535) + Rcpp::stop("cTab to large"); for (uint32_t i = 0; i < cTab; ++i) { std::string sheetName = XLWideString(bin, swapit); - Rcpp::Rcout << "BrtSupTabs: "<< sheetName << std::endl; + Rcpp::Rcout << "BrtSupTabs: " << sheetName << std::endl; } break; } - case BrtExternSheet: - { + case BrtExternSheet: { - if (debug) Rcpp::Rcout << "" << std::endl; + if (debug) + Rcpp::Rcout << "" << std::endl; uint32_t cXti = 0; cXti = readbin(cXti, bin, swapit); - if (cXti > 65535) Rcpp::stop("cXti to large"); + if (cXti > 65535) + Rcpp::stop("cXti to large"); std::vector rgXti(cXti); - // Rcpp::Rcout << "reference_type: " << reference_type.size() << std::endl; - // Rcpp::Rcout << "reference_type: " << cXti << std::endl; + // Rcpp::Rcout << "reference_type: " << reference_type.size() << + // std::endl; Rcpp::Rcout << "reference_type: " << cXti << std::endl; for (uint32_t i = 0; i < cXti; ++i) { std::vector xti = Xti(bin, swapit); - if ((size_t)xti[0] > reference_type.size()) Rcpp::stop("references do not match"); - std::string tmp = "(xti[0])] + - "\" />"; + if ((size_t)xti[0] > reference_type.size()) + Rcpp::stop("references do not match"); + std::string tmp = "(xti[0])] + "\" />"; xtis.push_back(tmp); } break; } - case BrtEndExternals: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndExternals: { + if (debug) + Rcpp::Rcout << "" << std::endl; if (!first_extern_sheet) out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtFRTBegin: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtFRTBegin: { + if (debug) + Rcpp::Rcout << "" << std::endl; ProductVersion(bin, swapit, debug); break; } - case BrtWorkBookPr15: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtWorkBookPr15: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); // uint8_t fChartTrackingRefBased = 0; // uint32_t FRTHeader = 0; // FRTHeader = readbin(FRTHeader, bin, swapit); - // fChartTrackingRefBased = readbin(fChartTrackingRefBased, bin, 0) & 0x01; + // fChartTrackingRefBased = readbin(fChartTrackingRefBased, bin, 0) & + // 0x01; break; } - case BrtBeginCalcFeatures: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginCalcFeatures: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtCalcFeature: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtCalcFeature: { + if (debug) + Rcpp::Rcout << "" << std::endl; // bin.seekg(size, bin.cur); uint32_t FRTHeader = 0; - FRTHeader = readbin(FRTHeader, bin, swapit); + FRTHeader = readbin(FRTHeader, bin, swapit); std::string szName = XLWideString(bin, swapit); - if (debug) Rcpp::Rcout << FRTHeader << ": " << szName << std::endl; + if (debug) + Rcpp::Rcout << FRTHeader << ": " << szName << std::endl; break; } - case BrtEndCalcFeatures: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndCalcFeatures: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtFRTEnd: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtFRTEnd: { + if (debug) + Rcpp::Rcout << "" << std::endl; break; } - case BrtWbFactoid: - { // ??? - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtWbFactoid: { // ??? + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtFileRecover: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtFileRecover: { + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndBook: - { + case BrtEndBook: { end_of_workbook = true; if (defNams.size() > 1) { @@ -2071,7 +2122,8 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { xtis.push_back(""); for (size_t i = 0; i < xtis.size(); ++i) { - if (debug) Rcpp::Rcout << xtis[i] << std::endl; + if (debug) + Rcpp::Rcout << xtis[i] << std::endl; out << xtis[i] << std::endl; } } @@ -2086,38 +2138,37 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { out << "" << std::endl; } - - if (debug) Rcpp::Rcout << "" << std::endl; + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } case BrtRRChgCell: - case BrtRRDefName: - { + case BrtRRDefName: { has_revision_record = true; - // -- have not seen this yet. if it appears, treat it as if a revision record was found -- - // rgce.rgce or rgceOld.rgce in BrtRRDefName - if (debug) Rcpp::Rcout << "BrtRRChgCell or BrtRRDefName" << std::endl; + // -- have not seen this yet. if it appears, treat it as if a revision + // record was found -- rgce.rgce or rgceOld.rgce in BrtRRDefName + if (debug) + Rcpp::Rcout << "BrtRRChgCell or BrtRRDefName" << std::endl; Rcpp::warning("Assuming revision record."); bin.seekg(size, bin.cur); break; } - default: - { + default: { if (debug) { - Rcpp::Rcout << std::to_string(x) << - ": " << std::to_string(size) << - " @ " << bin.tellg() << std::endl; + Rcpp::Rcout << std::to_string(x) << ": " << std::to_string(size) << " @ " << bin.tellg() + << std::endl; } bin.seekg(size, bin.cur); break; } } - if (debug) Rcpp::Rcout << "wb-loop: " << x << ": " << size << ": " << bin.tellg() << std::endl; + if (debug) + Rcpp::Rcout << "wb-loop: " << x << ": " << size << ": " << bin.tellg() << std::endl; } out.close(); @@ -2126,11 +2177,8 @@ int32_t workbook_bin(std::string filePath, std::string outPath, bool debug) { } else { return -1; }; - } - - // [[Rcpp::export]] int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath, bool debug) { @@ -2143,59 +2191,61 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (bin) { bin.seekg(0, std::ios_base::beg); - bool first_row = true; - bool in_sheet_data = false; - bool end_of_worksheet = false; - bool has_revision_record = false; + bool first_row = true; + bool in_sheet_data = false; + bool end_of_worksheet = false; + bool has_revision_record = false; std::string fml_type; - int32_t row = 0; - int32_t col = 0; + int32_t row = 0; + int32_t col = 0; std::vector hlinks; hlinks.push_back(""); // its a bit funny that this is the structure we now use to read from the // xlsb file and save this as xml only to read it back into this structure // with the xlsx reader :) - std::vector colvec; + std::vector colvec; std::unordered_map shared_cells; - int32_t shared_cell_cntr = 0; + int32_t shared_cell_cntr = 0; // auto itr = 0; - while(!end_of_worksheet) { + while (!end_of_worksheet) { Rcpp::checkUserInterrupt(); // uint8_t unk = 0, high = 0, low = 0; // uint16_t tmp = 0; int32_t x = 0, size = 0; - if (debug) Rcpp::Rcout << "." << std::endl; + if (debug) + Rcpp::Rcout << "." << std::endl; RECORD(x, size, bin, swapit); - if (debug) Rcpp::Rcout << x << ": " << size << std::endl; + if (debug) + Rcpp::Rcout << x << ": " << size << std::endl; - switch(x) { + switch (x) { - case BrtBeginSheet: - { + case BrtBeginSheet: { if (chartsheet) out << "" << std::endl; else out << "" << std::endl; - if (debug) Rcpp::Rcout << "Begin of : " << bin.tellg() << std::endl; + if (debug) + Rcpp::Rcout << "Begin of : " << bin.tellg() << std::endl; break; } - case BrtCsProp: - { - if (debug) Rcpp::Rcout << "CsProp: " << bin.tellg() << std::endl; + case BrtCsProp: { + if (debug) + Rcpp::Rcout << "CsProp: " << bin.tellg() << std::endl; uint16_t A = 0; - A = readbin(A, bin, swapit); + A = readbin(A, bin, swapit); - std::vector color = brtColor(bin, swapit); - std::string strName = XLWideString(bin, swapit); + std::vector color = brtColor(bin, swapit); + std::string strName = XLWideString(bin, swapit); // for now we only handle color in sheetPR if (color[0] >= 1 && color[0] <= 3) { @@ -2206,11 +2256,13 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } if (color[0] == 0x02) { - out << "" << std::endl; + out << "" + << std::endl; } if (color[0] == 0x03) { - out << "" << std::endl; // << "\" tint=\""<< color[2] + out << "" + << std::endl; // << "\" tint=\""<< color[2] } out << "" << std::endl; @@ -2219,12 +2271,12 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtWsProp: - { - if (debug) Rcpp::Rcout << "WsProp: " << bin.tellg() << std::endl; + case BrtWsProp: { + if (debug) + Rcpp::Rcout << "WsProp: " << bin.tellg() << std::endl; // read uint24_t as 16 + 8 - uint8_t brtwsprop_sec = 0; + uint8_t brtwsprop_sec = 0; uint16_t brtwsprop_fst = 0; uint32_t rwSync = 0, colSync = 0; @@ -2234,9 +2286,9 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath // BrtWsPropFields2 *fields2 = (BrtWsPropFields2 *)&brtwsprop_sec; std::vector color = brtColor(bin, swapit); - rwSync = readbin(rwSync, bin, swapit); - colSync = readbin(colSync, bin, swapit); - std::string strName = XLWideString(bin, swapit); + rwSync = readbin(rwSync, bin, swapit); + colSync = readbin(colSync, bin, swapit); + std::string strName = XLWideString(bin, swapit); if (debug) { Rcpp::Rcout << "sheetPr tabColor:" << std::endl; @@ -2252,11 +2304,13 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } if (color[0] == 0x02) { - out << "" << std::endl; + out << "" + << std::endl; } if (color[0] == 0x03) { - out << "" << std::endl; // << "\" tint=\""<< color[2] + out << "" + << std::endl; // << "\" tint=\""<< color[2] } out << "" << std::endl; @@ -2265,9 +2319,9 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtWsDim: - { - if (debug) Rcpp::Rcout << "WsDim: " << bin.tellg() << std::endl; + case BrtWsDim: { + if (debug) + Rcpp::Rcout << "WsDim: " << bin.tellg() << std::endl; // 16 bit std::vector dims; @@ -2286,7 +2340,7 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (lref.compare(rref) == 0) { ref = lref; } else { - ref = lref + ":" + rref; + ref = lref + ":" + rref; } out << "" << std::endl; @@ -2295,24 +2349,24 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } case BrtBeginCsViews: - case BrtBeginWsViews: - { - if (debug) Rcpp::Rcout << ": " << bin.tellg() << std::endl; + case BrtBeginWsViews: { + if (debug) + Rcpp::Rcout << ": " << bin.tellg() << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginCsView: - { - if (debug) Rcpp::Rcout << ": " << bin.tellg() << std::endl; - bool fSelected = false; - uint16_t flags = 0; + case BrtBeginCsView: { + if (debug) + Rcpp::Rcout << ": " << bin.tellg() << std::endl; + bool fSelected = false; + uint16_t flags = 0; uint32_t wScale = 0, iWbkView = 0; - flags = readbin(flags, bin, swapit); - wScale = readbin(wScale, bin, swapit); + flags = readbin(flags, bin, swapit); + wScale = readbin(wScale, bin, swapit); iWbkView = readbin(iWbkView, bin, swapit); fSelected = flags & 0x8000; @@ -2331,30 +2385,34 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtPane: - { - if (debug) Rcpp::Rcout << "BrtPane: " << std::endl; - uint8_t flags = 0; - int32_t rwTop = 0, colLeft = 0; - uint32_t pnnAct = 0; - double xnumXSplit = 0.0, xnumYSplit = 0.0; + case BrtPane: { + if (debug) + Rcpp::Rcout << "BrtPane: " << std::endl; + uint8_t flags = 0; + int32_t rwTop = 0, colLeft = 0; + uint32_t pnnAct = 0; + double xnumXSplit = 0.0, xnumYSplit = 0.0; xnumXSplit = Xnum(bin, swapit); xnumYSplit = Xnum(bin, swapit); - rwTop = UncheckedRw(bin, swapit); - colLeft = UncheckedCol(bin, swapit); - pnnAct = readbin(pnnAct, bin, swapit); - flags = readbin(flags, bin, swapit); + rwTop = UncheckedRw(bin, swapit); + colLeft = UncheckedCol(bin, swapit); + pnnAct = readbin(pnnAct, bin, swapit); + flags = readbin(flags, bin, swapit); std::string topLeft = int_to_col(colLeft + 1) + std::to_string(rwTop + 1); std::string pnn; - if (pnnAct == 0x00000000) pnn = "bottomRight"; - if (pnnAct == 0x00000001) pnn = "topRight"; - if (pnnAct == 0x00000002) pnn = "bottomLeft"; - if (pnnAct == 0x00000003) pnn = "topLeft"; - - bool fFrozen = flags & 0x01; + if (pnnAct == 0x00000000) + pnn = "bottomRight"; + if (pnnAct == 0x00000001) + pnn = "topRight"; + if (pnnAct == 0x00000002) + pnn = "bottomLeft"; + if (pnnAct == 0x00000003) + pnn = "topLeft"; + + bool fFrozen = flags & 0x01; bool fFrozenNoSplit = (flags >> 1) & 0x01; // Rprintf("Frozen: %d / %d / %d\n", fFrozen, fFrozenNoSplit, flags); @@ -2378,30 +2436,30 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtBeginWsView: - { - if (debug) Rcpp::Rcout << ": " << bin.tellg() << std::endl; + case BrtBeginWsView: { + if (debug) + Rcpp::Rcout << ": " << bin.tellg() << std::endl; // out << "" << std::endl; // bin.seekg(size, bin.cur); - uint8_t icvHdr = 0, reserved2 = 0; - uint16_t flags = 0, reserved3 = 0, wScale = 0, wScaleNormal = 0, wScaleSLV = 0, wScalePLV = 0; + uint8_t icvHdr = 0, reserved2 = 0; + uint16_t flags = 0, reserved3 = 0, wScale = 0, wScaleNormal = 0, wScaleSLV = 0, + wScalePLV = 0; uint32_t xlView = 0, iWbkView = 0; - int32_t rwTop = 0, colLeft = 0; - - flags = readbin(flags, bin, swapit); - xlView = readbin(xlView, bin, swapit); - rwTop = UncheckedRw(bin, swapit); - colLeft = UncheckedCol(bin, swapit); - icvHdr = readbin(icvHdr, bin, swapit); - reserved2 = readbin(reserved2, bin, swapit); - reserved3 = readbin(reserved3, bin, swapit); - wScale = readbin(wScale, bin, swapit); + int32_t rwTop = 0, colLeft = 0; + + flags = readbin(flags, bin, swapit); + xlView = readbin(xlView, bin, swapit); + rwTop = UncheckedRw(bin, swapit); + colLeft = UncheckedCol(bin, swapit); + icvHdr = readbin(icvHdr, bin, swapit); + reserved2 = readbin(reserved2, bin, swapit); + reserved3 = readbin(reserved3, bin, swapit); + wScale = readbin(wScale, bin, swapit); wScaleNormal = readbin(wScaleNormal, bin, swapit); - wScaleSLV = readbin(wScaleSLV, bin, swapit); - wScalePLV = readbin(wScalePLV, bin, swapit); - iWbkView = readbin(iWbkView, bin, swapit); - + wScaleSLV = readbin(wScaleSLV, bin, swapit); + wScalePLV = readbin(wScalePLV, bin, swapit); + iWbkView = readbin(iWbkView, bin, swapit); BrtBeginWsViewFields *fields = (BrtBeginWsViewFields *)&flags; @@ -2443,30 +2501,31 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (wScaleNormal) out << " zoomScaleNormal=\"" << wScaleNormal << "\""; if (wScalePLV) - out << " zoomScalePageLayoutView=\"" << wScalePLV<< "\""; + out << " zoomScalePageLayoutView=\"" << wScalePLV << "\""; if (wScaleSLV) - out << " zoomScaleSheetLayoutView=\"" << wScaleSLV<< "\""; + out << " zoomScaleSheetLayoutView=\"" << wScaleSLV << "\""; out << ">" << std::endl; break; } - case BrtPageSetup: - { - if (debug) Rcpp::Rcout << "BrtPageSetup: " << std::endl; - uint16_t flags = 0; - uint32_t iPaperSize = 0, iScale = 0, iRes = 0, iVRes = 0, iCopies = 0, iPageStart = 0, iFitWidth = 0, iFitHeight = 0; + case BrtPageSetup: { + if (debug) + Rcpp::Rcout << "BrtPageSetup: " << std::endl; + uint16_t flags = 0; + uint32_t iPaperSize = 0, iScale = 0, iRes = 0, iVRes = 0, iCopies = 0, iPageStart = 0, + iFitWidth = 0, iFitHeight = 0; iPaperSize = readbin(iPaperSize, bin, swapit); - iScale = readbin(iScale, bin, swapit); - iRes = readbin(iRes, bin, swapit); - iVRes = readbin(iVRes, bin, swapit); - iCopies = readbin(iCopies, bin, swapit); + iScale = readbin(iScale, bin, swapit); + iRes = readbin(iRes, bin, swapit); + iVRes = readbin(iVRes, bin, swapit); + iCopies = readbin(iCopies, bin, swapit); iPageStart = readbin(iPageStart, bin, swapit); - iFitWidth = readbin(iFitWidth, bin, swapit); + iFitWidth = readbin(iFitWidth, bin, swapit); iFitHeight = readbin(iFitHeight, bin, swapit); - flags = readbin(flags, bin, swapit); + flags = readbin(flags, bin, swapit); std::string szRelId = XLNullableWideString(bin, swapit); @@ -2474,34 +2533,31 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath // "\" blackAndWhite=\"" << << // "\" draft=\""<< << // "\" cellComments=\""<< << - " copies=\""<< iCopies << + " copies=\"" << iCopies << // "\" errors=\""<< << - "\" firstPageNumber=\""<< iPageStart << - "\" fitToHeight=\""<< iFitHeight << - "\" fitToWidth=\""<< iFitWidth << - "\" horizontalDpi=\""<< iRes << + "\" firstPageNumber=\"" << iPageStart << "\" fitToHeight=\"" << iFitHeight + << "\" fitToWidth=\"" << iFitWidth << "\" horizontalDpi=\"" << iRes << // "\" orientation=\""<< << // "\" pageOrder=\""<< << // "\" paperHeight=\""<< << - "\" paperSize=\""<< iPaperSize << + "\" paperSize=\"" << iPaperSize << // "\" paperWidth=\""<< << - "\" scale=\""<< iScale << + "\" scale=\"" << iScale << // "\" useFirstPageNumber=\""<< << // "\" usePrinterDefaults=\""<< << - "\" verticalDpi=\"" << iVRes << - "\" />" << std::endl; + "\" verticalDpi=\"" << iVRes << "\" />" << std::endl; break; } - case BrtPhoneticInfo: - { - if (debug) Rcpp::Rcout << "BrtPhoneticInfo: " << std::endl; - uint16_t iFnt = 0; + case BrtPhoneticInfo: { + if (debug) + Rcpp::Rcout << "BrtPhoneticInfo: " << std::endl; + uint16_t iFnt = 0; uint32_t phType = 0, phAll = 0; - iFnt = readbin(iFnt, bin, swapit); + iFnt = readbin(iFnt, bin, swapit); phType = readbin(phType, bin, swapit); - phAll = readbin(phAll, bin, swapit); + phAll = readbin(phAll, bin, swapit); if (debug) Rprintf("phnetic: %d, %d, %d", iFnt, phType, phAll); @@ -2509,66 +2565,75 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtBeginHeaderFooter: - { - if (debug) Rcpp::Rcout << "BrtBeginHeaderFooter: " << std::endl; + case BrtBeginHeaderFooter: { + if (debug) + Rcpp::Rcout << "BrtBeginHeaderFooter: " << std::endl; uint16_t flags = 0; - flags = readbin(flags, bin, swapit); // unused + flags = readbin(flags, bin, swapit); // unused - std::string stHeader = XLNullableWideString(bin, swapit); - std::string stFooter = XLNullableWideString(bin, swapit); - std::string stHeaderEven = XLNullableWideString(bin, swapit); - std::string stFooterEven = XLNullableWideString(bin, swapit); + std::string stHeader = XLNullableWideString(bin, swapit); + std::string stFooter = XLNullableWideString(bin, swapit); + std::string stHeaderEven = XLNullableWideString(bin, swapit); + std::string stFooterEven = XLNullableWideString(bin, swapit); std::string stHeaderFirst = XLNullableWideString(bin, swapit); std::string stFooterFirst = XLNullableWideString(bin, swapit); BrtBeginHeaderFooterFields *fields = (BrtBeginHeaderFooterFields *)&flags; if (debug) - Rcpp::Rcout << stHeader<< ": " << stFooter << ": " << - stHeaderEven << ": " << stFooterEven << ": " << - stHeaderFirst << ": " << stFooterFirst << std::endl; + Rcpp::Rcout << stHeader << ": " << stFooter << ": " << stHeaderEven << ": " + << stFooterEven << ": " << stHeaderFirst << ": " << stFooterFirst + << std::endl; out << "fHFDiffOddEven) out << " differentOddEven=\"" << fields->fHFDiffOddEven << "\"" << std::endl; - if (fields->fHFDiffFirst) out << " differentFirst=\"" << fields->fHFDiffFirst << "\"" << std::endl; - if (fields->fHFScaleWithDoc) out << " scaleWithDoc=\"" << fields->fHFScaleWithDoc << "\"" << std::endl; - if (fields->fHFAlignMargins) out << " alignWithMargins=\"" << fields->fHFAlignMargins << "\"" << std::endl; + if (fields->fHFDiffOddEven) + out << " differentOddEven=\"" << fields->fHFDiffOddEven << "\"" << std::endl; + if (fields->fHFDiffFirst) + out << " differentFirst=\"" << fields->fHFDiffFirst << "\"" << std::endl; + if (fields->fHFScaleWithDoc) + out << " scaleWithDoc=\"" << fields->fHFScaleWithDoc << "\"" << std::endl; + if (fields->fHFAlignMargins) + out << " alignWithMargins=\"" << fields->fHFAlignMargins << "\"" << std::endl; out << ">" << std::endl; - if (!stHeader.empty()) out << "" << stHeader <<"" << std::endl; - if (!stFooter.empty()) out << "" << stFooter <<"" << std::endl; - if (!stHeaderEven.empty()) out << "" << stHeaderEven <<"" << std::endl; - if (!stFooterEven.empty()) out << "" << stFooterEven <<"" << std::endl; - if (!stHeaderFirst.empty()) out << "" << stHeaderFirst <<"" << std::endl; - if (!stFooterFirst.empty()) out << "" << stFooterFirst <<"" << std::endl; + if (!stHeader.empty()) + out << "" << stHeader << "" << std::endl; + if (!stFooter.empty()) + out << "" << stFooter << "" << std::endl; + if (!stHeaderEven.empty()) + out << "" << stHeaderEven << "" << std::endl; + if (!stFooterEven.empty()) + out << "" << stFooterEven << "" << std::endl; + if (!stHeaderFirst.empty()) + out << "" << stHeaderFirst << "" << std::endl; + if (!stFooterFirst.empty()) + out << "" << stFooterFirst << "" << std::endl; out << "" << std::endl; break; } - case BrtEndHeaderFooter: - { + case BrtEndHeaderFooter: { bin.seekg(size, bin.cur); break; } // whatever this is - case BrtSel: - { - if (debug) Rcpp::Rcout << "BrtSel: " << bin.tellg() << std::endl; - uint32_t pnn = 0, rwAct = 0, colAct = 0, dwRfxAct = 0; + case BrtSel: { + if (debug) + Rcpp::Rcout << "BrtSel: " << bin.tellg() << std::endl; + uint32_t pnn = 0, rwAct = 0, colAct = 0, dwRfxAct = 0; std::vector sqrfx; - pnn = readbin(pnn, bin, swapit); - rwAct = readbin(rwAct, bin, swapit); - colAct = readbin(colAct, bin, swapit); + pnn = readbin(pnn, bin, swapit); + rwAct = readbin(rwAct, bin, swapit); + colAct = readbin(colAct, bin, swapit); dwRfxAct = readbin(dwRfxAct, bin, swapit); // sqrfx[0] is the number of rfx following sqrfx = UncheckedSqRfX(bin, swapit); - std::string ac = int_to_col(colAct + 1) + std::to_string(rwAct + 1); + std::string ac = int_to_col(colAct + 1) + std::to_string(rwAct + 1); std::string lref = int_to_col(sqrfx[3] + 1) + std::to_string(sqrfx[1] + 1); std::string rref = int_to_col(sqrfx[4] + 1) + std::to_string(sqrfx[2] + 1); @@ -2576,101 +2641,106 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (lref.compare(rref) == 0) { sqref = lref; } else { - sqref = lref + ":" + rref; + sqref = lref + ":" + rref; } std::string spnn; - if (pnn == 0x00000000) spnn = "bottomRight"; - if (pnn == 0x00000001) spnn = "topRight"; - if (pnn == 0x00000002) spnn = "bottomLeft"; - if (pnn == 0x00000003) spnn = "topLeft"; + if (pnn == 0x00000000) + spnn = "bottomRight"; + if (pnn == 0x00000001) + spnn = "topRight"; + if (pnn == 0x00000002) + spnn = "bottomLeft"; + if (pnn == 0x00000003) + spnn = "topLeft"; - out << "" << std::endl; + out << "" << std::endl; break; } case BrtEndCsView: - case BrtEndWsView: - { - if (debug) Rcpp::Rcout << ": " << bin.tellg() << std::endl; + case BrtEndWsView: { + if (debug) + Rcpp::Rcout << ": " << bin.tellg() << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } case BrtEndCsViews: - case BrtEndWsViews: - { - if (debug) Rcpp::Rcout << ": " << bin.tellg() << std::endl; + case BrtEndWsViews: { + if (debug) + Rcpp::Rcout << ": " << bin.tellg() << std::endl; out << "" << std::endl; break; } - case BrtBeginColInfos: - { - if (debug) Rcpp::Rcout << ": " << bin.tellg() << std::endl; + case BrtBeginColInfos: { + if (debug) + Rcpp::Rcout << ": " << bin.tellg() << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtColInfo: - { - if (debug) Rcpp::Rcout << ": " << bin.tellg() << std::endl; + case BrtColInfo: { + if (debug) + Rcpp::Rcout << ": " << bin.tellg() << std::endl; uint16_t colinfo = 0; uint32_t coldx = 0, ixfe = 0; - int32_t colFirst = 0, colLast = 0; + int32_t colFirst = 0, colLast = 0; colFirst = UncheckedCol(bin, swapit) + 1; - colLast = UncheckedCol(bin, swapit) + 1; - coldx = readbin(coldx, bin, swapit); - ixfe = readbin(ixfe, bin, swapit); - colinfo = readbin(colinfo, bin, swapit); + colLast = UncheckedCol(bin, swapit) + 1; + coldx = readbin(coldx, bin, swapit); + ixfe = readbin(ixfe, bin, swapit); + colinfo = readbin(colinfo, bin, swapit); BrtColInfoFields *fields = (BrtColInfoFields *)&colinfo; out << " 0) - out << " style=\"" << ixfe << "\""; + out << " style=\"" << ixfe << "\""; - out << " width=\"" << (double)coldx/256 << "\""; + out << " width=\"" << (double)coldx / 256 << "\""; if (fields->fHidden) - out << " hidden=\"" << fields->fHidden << "\""; + out << " hidden=\"" << fields->fHidden << "\""; if (fields->fUserSet) - out << " customWidth=\"" << fields->fUserSet << "\""; + out << " customWidth=\"" << fields->fUserSet << "\""; if (fields->fBestFit) - out << " bestFit=\"" << fields->fBestFit << "\""; - if (fields->iOutLevel>0) - out << " outlineLevel=\"" << (uint16_t)fields->iOutLevel << "\""; + out << " bestFit=\"" << fields->fBestFit << "\""; + if (fields->iOutLevel > 0) + out << " outlineLevel=\"" << (uint16_t)fields->iOutLevel << "\""; if (fields->fCollapsed) - out << " collapsed=\"" << fields->fCollapsed << "\""; + out << " collapsed=\"" << fields->fCollapsed << "\""; out << " />" << std::endl; break; } - case BrtEndColInfos: - { - if (debug) Rcpp::Rcout << ": " << bin.tellg() << std::endl; + case BrtEndColInfos: { + if (debug) + Rcpp::Rcout << ": " << bin.tellg() << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginSheetData: - { - if (debug) Rcpp::Rcout << "" << bin.tellg() << std::endl; + case BrtBeginSheetData: { + if (debug) + Rcpp::Rcout << "" << bin.tellg() << std::endl; out << "" << std::endl; // << bin.tellg() in_sheet_data = true; break; } // prelude to row entry - case BrtACBegin: - { - if (debug) Rcpp::Rcout << "BrtACBegin: " << bin.tellg() << std::endl; + case BrtACBegin: { + if (debug) + Rcpp::Rcout << "BrtACBegin: " << bin.tellg() << std::endl; bin.seekg(size, bin.cur); // int16_t nversions, version; // nversions = readbin(nversions, bin , swapit); @@ -2686,66 +2756,69 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtWsFmtInfoEx14: - { - if (debug) Rcpp::Rcout << "BrtWsFmtInfoEx14: " << bin.tellg() << std::endl; + case BrtWsFmtInfoEx14: { + if (debug) + Rcpp::Rcout << "BrtWsFmtInfoEx14: " << bin.tellg() << std::endl; bin.seekg(size, bin.cur); break; } - case BrtACEnd: - { - if (debug) Rcpp::Rcout << "BrtACEnd: " << bin.tellg() << std::endl; + case BrtACEnd: { + if (debug) + Rcpp::Rcout << "BrtACEnd: " << bin.tellg() << std::endl; bin.seekg(size, bin.cur); break; } - case BrtWsFmtInfo: - { - if (debug) Rcpp::Rcout << "BrtWsFmtInfo: " << bin.tellg() << std::endl; + case BrtWsFmtInfo: { + if (debug) + Rcpp::Rcout << "BrtWsFmtInfo: " << bin.tellg() << std::endl; bin.seekg(size, bin.cur); break; } - case BrtRwDescent: - { - if (debug) Rcpp::Rcout << "BrtRwDescent: " << bin.tellg() << std::endl; + case BrtRwDescent: { + if (debug) + Rcpp::Rcout << "BrtRwDescent: " << bin.tellg() << std::endl; // bin.seekg(size, bin.cur); uint16_t dyDescent = 0; - dyDescent = readbin(dyDescent, bin, swapit); + dyDescent = readbin(dyDescent, bin, swapit); break; } - case BrtRowHdr: - { - if (debug) Rcpp::Rcout << ": " << bin.tellg() << std::endl; + case BrtRowHdr: { + if (debug) + Rcpp::Rcout << ": " << bin.tellg() << std::endl; - if (!in_sheet_data) bin.seekg(size, bin.cur); + if (!in_sheet_data) + bin.seekg(size, bin.cur); // close open rows if (!first_row) { for (size_t i = 0; i < colvec.size(); ++i) { - out << "" << std::endl; + out << "" << std::endl; out << "" << escape_xml(colvec[i].v) << "" << std::endl; - out << "" << colvec[i].f << "" << std::endl; + out << "" << colvec[i].f << "" + << std::endl; out << "" << std::endl; } colvec.clear(); - out << "" <" << std::endl; } else { first_row = false; } - uint8_t bits3 = 0, fExtraAsc = 0, fExtraDsc = 0, - fCollapsed = 0, fDyZero = 0, fUnsynced = 0, fGhostDirty = 0, - fReserved = 0, fPhShow = 0; + uint8_t bits3 = 0, fExtraAsc = 0, fExtraDsc = 0, fCollapsed = 0, fDyZero = 0, fUnsynced = 0, + fGhostDirty = 0, fReserved = 0, fPhShow = 0; uint16_t miyRw = 0; // uint24_t; - int32_t rw = 0, colMic = 0, colLast = 0; // uint32? + int32_t rw = 0, colMic = 0, colLast = 0; // uint32? uint32_t ixfe = 0, ccolspan = 0, unk32 = 0; rw = readbin(rw, bin, swapit); @@ -2754,163 +2827,172 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath Rcpp::stop("row either decreasing or to large"); } - ixfe = readbin(ixfe, bin, swapit); - miyRw = readbin(miyRw, bin, swapit); - - if (miyRw > 0x2000) Rcpp::stop("miyRw to big"); - - uint16_t rwoheaderfields = 0; - rwoheaderfields = readbin(rwoheaderfields, bin, swapit); - - BrtRowHdrFields *fields = (BrtRowHdrFields *)&rwoheaderfields; - - // fExtraAsc = 1 - // fExtraDsc = 1 - // reserved1 = 6 - // iOutLevel = 3 - // fCollapsed = 1 - // fDyZero = 1 - // fUnsynced = 1 - // fGhostDirty = 1 - // fReserved = 1 - - bits3 = readbin(bits3, bin, swapit); - // fPhShow = 1 - // fReserved = 7 - - ccolspan = readbin(ccolspan, bin, swapit); - if (ccolspan > 16) Rcpp::stop("ccolspan to large"); - std::string spans; - - std::vector spans_int; - if (ccolspan) { - // has number of rgBrtColspan elements. For now take max and min value. - // there are other types of spans (1:1 1024:16384), but unsure how this is - // supposed to be handled. It's possible to have elements like spans = - // "1:1 16384:16384" which we will read as spans = "1:16384" - for (uint8_t clpn = 0; clpn < ccolspan; ++clpn) { - colMic = readbin(colMic, bin, swapit); - colLast = readbin(colLast, bin, swapit); + ixfe = readbin(ixfe, bin, swapit); + miyRw = readbin(miyRw, bin, swapit); + + if (miyRw > 0x2000) + Rcpp::stop("miyRw to big"); + + uint16_t rwoheaderfields = 0; + rwoheaderfields = readbin(rwoheaderfields, bin, swapit); + + BrtRowHdrFields *fields = (BrtRowHdrFields *)&rwoheaderfields; + + // fExtraAsc = 1 + // fExtraDsc = 1 + // reserved1 = 6 + // iOutLevel = 3 + // fCollapsed = 1 + // fDyZero = 1 + // fUnsynced = 1 + // fGhostDirty = 1 + // fReserved = 1 + + bits3 = readbin(bits3, bin, swapit); + // fPhShow = 1 + // fReserved = 7 + + ccolspan = readbin(ccolspan, bin, swapit); + if (ccolspan > 16) + Rcpp::stop("ccolspan to large"); + std::string spans; + + std::vector spans_int; + if (ccolspan) { + // has number of rgBrtColspan elements. For now take max and min + // value. there are other types of spans (1:1 1024:16384), but unsure + // how this is supposed to be handled. It's possible to have elements + // like spans = "1:1 16384:16384" which we will read as spans = + // "1:16384" + for (uint8_t clpn = 0; clpn < ccolspan; ++clpn) { + colMic = readbin(colMic, bin, swapit); + colLast = readbin(colLast, bin, swapit); + + if (debug) { + spans = std::to_string(colMic + 1) + ":" + std::to_string(colLast + 1); + Rcpp::Rcout << (int32_t)clpn << ": " << spans << std::endl; + } - if (debug) { - spans = std::to_string(colMic + 1) + ":" + std::to_string(colLast + 1); - Rcpp::Rcout << (int32_t)clpn << ": " << spans << std::endl; + spans_int.push_back(colMic); + spans_int.push_back(colLast); } - spans_int.push_back(colMic); - spans_int.push_back(colLast); - } - - int32_t min_span = *std::min_element(spans_int.begin(), spans_int.end()); - int32_t max_span = *std::max_element(spans_int.begin(), spans_int.end()); + int32_t min_span = *std::min_element(spans_int.begin(), spans_int.end()); + int32_t max_span = *std::max_element(spans_int.begin(), spans_int.end()); - spans = std::to_string(min_span + 1) + ":" + std::to_string(max_span + 1); - } + spans = std::to_string(min_span + 1) + ":" + std::to_string(max_span + 1); + } - out << "fUnsynced != 0) { - // Rcpp::Rcout << " ht=\"" << miyRw/20 << "\"" << std::endl; - out << " ht=\"" << miyRw/20 << "\""; - out << " customHeight=\"" << fields->fUnsynced << "\""; - } + if (fields->fUnsynced != 0) { + // Rcpp::Rcout << " ht=\"" << miyRw/20 << "\"" << std::endl; + out << " ht=\"" << miyRw / 20 << "\""; + out << " customHeight=\"" << fields->fUnsynced << "\""; + } - if (ccolspan) - out << " spans=\"" << spans << "\""; + if (ccolspan) + out << " spans=\"" << spans << "\""; - if (fields->iOutLevel > 0) { - out << " outlineLevel=\"" << (uint16_t)fields->iOutLevel << "\""; - } + if (fields->iOutLevel > 0) { + out << " outlineLevel=\"" << (uint16_t)fields->iOutLevel << "\""; + } - if (fields->fCollapsed) { - out << " collapsed=\"" << fields->fCollapsed << "\""; - } + if (fields->fCollapsed) { + out << " collapsed=\"" << fields->fCollapsed << "\""; + } - if (fields->fDyZero) { - out << " hidden=\"" << fields->fDyZero << "\""; - } + if (fields->fDyZero) { + out << " hidden=\"" << fields->fDyZero << "\""; + } - if (fields->fGhostDirty) { - out << " customFormat=\"" << fields->fGhostDirty << "\""; - } + if (fields->fGhostDirty) { + out << " customFormat=\"" << fields->fGhostDirty << "\""; + } - if (ixfe > 0) { - out << " s=\"" << ixfe << "\""; - } + if (ixfe > 0) { + out << " s=\"" << ixfe << "\""; + } - out << ">" << std::endl; + out << ">" << std::endl; - row = rw; + row = rw; - if (debug) - Rcpp::Rcout << "ROW:" << (rw +1) << " : " << ixfe << " : " << miyRw << " : " << (int32_t)fExtraAsc << " : " << - (int32_t)fExtraDsc << " : " << unk32 << " : " << (int32_t)fCollapsed << " : " << (int32_t)fDyZero << " : " << - (int32_t)fUnsynced << " : " << (int32_t)fGhostDirty << " : " << (int32_t)fReserved << " : " << - (int32_t)fPhShow << " : " << ccolspan << "; " << bin.tellg() << std::endl; + if (debug) + Rcpp::Rcout << "ROW:" << (rw + 1) << " : " << ixfe << " : " << miyRw << " : " + << (int32_t)fExtraAsc << " : " << (int32_t)fExtraDsc << " : " << unk32 + << " : " << (int32_t)fCollapsed << " : " << (int32_t)fDyZero << " : " + << (int32_t)fUnsynced << " : " << (int32_t)fGhostDirty << " : " + << (int32_t)fReserved << " : " << (int32_t)fPhShow << " : " << ccolspan + << "; " << bin.tellg() << std::endl; - break; + break; } - case BrtCellIsst: - { // shared string - if (debug) Rcpp::Rcout << "BrtCellIsst: " << bin.tellg() << std::endl; + case BrtCellIsst: { // shared string + if (debug) + Rcpp::Rcout << "BrtCellIsst: " << bin.tellg() << std::endl; int32_t val1 = 0, val2 = 0, val3 = 0; val1 = readbin(val1, bin, swapit); - if (debug) Rcpp::Rcout << val1 << std::endl; + if (debug) + Rcpp::Rcout << val1 << std::endl; val2 = readbin(val2, bin, swapit); - if (debug) Rcpp::Rcout << val2 << std::endl; + if (debug) + Rcpp::Rcout << val2 << std::endl; val3 = readbin(val3, bin, swapit); - if (debug) Rcpp::Rcout << val3 << std::endl; + if (debug) + Rcpp::Rcout << val3 << std::endl; xml_col column; - column.v = std::to_string(val3); + column.v = std::to_string(val3); column.c_t = "s"; - if (val2) column.c_s = std::to_string(val2); + if (val2) + column.c_s = std::to_string(val2); column.c_r = int_to_col(val1 + 1) + std::to_string(row + 1); colvec.push_back(column); - // out << "" << std::endl; - // out << "" << val3 << "" << std::endl; - // out << "" << std::endl; + // out << "" << std::endl; out << "" << val3 << + // "" << std::endl; out << "" << std::endl; break; } - case BrtCellBool: - { // bool - if (debug) Rcpp::Rcout << "BrtCellBool: " << bin.tellg() << std::endl; + case BrtCellBool: { // bool + if (debug) + Rcpp::Rcout << "BrtCellBool: " << bin.tellg() << std::endl; int32_t val1 = 0, val2 = 0; uint8_t val3 = 0; - val1 = readbin(val1, bin, swapit); + val1 = readbin(val1, bin, swapit); // out << val1 << std::endl; val2 = readbin(val2, bin, swapit); // out << val2 << std::endl; val3 = readbin(val3, bin, swapit); // out << val3 << std::endl; - xml_col column; - column.v = std::to_string((int32_t)val3); + column.v = std::to_string((int32_t)val3); column.c_t = "b"; - if (val2) column.c_s = std::to_string(val2); + if (val2) + column.c_s = std::to_string(val2); column.c_r = int_to_col(val1 + 1) + std::to_string(row + 1); colvec.push_back(column); - // out << "" << std::endl; - // out << "" << (int32_t)val3 << "" << std::endl; - // out << "" << std::endl; + // out << "" << std::endl; out << "" << + // (int32_t)val3 << "" << std::endl; out << "" << std::endl; break; } - case BrtCellRk: - { // integer? - if (debug) Rcpp::Rcout << "BrtCellRk: " << bin.tellg() << std::endl; + case BrtCellRk: { // integer? + if (debug) + Rcpp::Rcout << "BrtCellRk: " << bin.tellg() << std::endl; - int32_t val1 = 0, val2= 0, val3= 0; + int32_t val1 = 0, val2 = 0, val3 = 0; val1 = readbin(val1, bin, swapit); // Rcpp::Rcout << val << std::endl; val2 = readbin(val2, bin, swapit); @@ -2924,29 +3006,30 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath xml_col column; column.v = stream.str(); - if (val2) column.c_s = std::to_string(val2); + if (val2) + column.c_s = std::to_string(val2); column.c_r = int_to_col(val1 + 1) + std::to_string(row + 1); colvec.push_back(column); - // out << "" << std::endl; - // out << "" << std::setprecision(16) << RkNumber(val3) << "" << std::endl; - // out << "" << std::endl; + // out << "" << std::endl; out << "" << + // std::setprecision(16) << RkNumber(val3) << "" << std::endl; out + // << "" << std::endl; break; } - - case BrtCellReal: - { - if (debug) Rcpp::Rcout << "BrtCellReal: " << bin.tellg() << std::endl; - int32_t val1= 0, val2= 0; + case BrtCellReal: { + if (debug) + Rcpp::Rcout << "BrtCellReal: " << bin.tellg() << std::endl; + int32_t val1 = 0, val2 = 0; val1 = readbin(val1, bin, swapit); // Rcpp::Rcout << val << std::endl; val2 = readbin(val2, bin, swapit); // Rcpp::Rcout << val << std::endl; double dbl = 0.0; - dbl = readbin(dbl, bin, swapit); + dbl = readbin(dbl, bin, swapit); // Rcpp::Rcout << dbl << std::endl; std::stringstream stream; @@ -2954,44 +3037,48 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath xml_col column; column.v = stream.str(); - if (val2) column.c_s = std::to_string(val2); + if (val2) + column.c_s = std::to_string(val2); column.c_r = int_to_col(val1 + 1) + std::to_string(row + 1); colvec.push_back(column); - // out << "" << std::endl; - // out << "" << std::setprecision(16) << dbl << "" << std::endl; // << std::fixed + // out << "" << std::endl; out << "" << + // std::setprecision(16) << dbl << "" << std::endl; // << std::fixed // out << "" << std::endl; break; } // 0 ? - case BrtCellBlank: - { - if (debug) Rcpp::Rcout << "BrtCellBlank: " << bin.tellg() << std::endl; + case BrtCellBlank: { + if (debug) + Rcpp::Rcout << "BrtCellBlank: " << bin.tellg() << std::endl; std::vector blank = Cell(bin, swapit); - col = blank[0]; - if (debug) Rf_PrintValue(Rcpp::wrap(blank)); - + col = blank[0]; + if (debug) + Rf_PrintValue(Rcpp::wrap(blank)); xml_col column; - if (blank[1]) column.c_s = std::to_string(blank[1]); + if (blank[1]) + column.c_s = std::to_string(blank[1]); column.c_r = int_to_col(blank[0] + 1) + std::to_string(row + 1); colvec.push_back(column); - // out << "" << std::endl; + // out << "" << std::endl; break; } - case BrtCellError: - { // t="e" & #NUM! - if (debug) Rcpp::Rcout << "BrtCellError: " << bin.tellg() << std::endl; + case BrtCellError: { // t="e" & #NUM! + if (debug) + Rcpp::Rcout << "BrtCellError: " << bin.tellg() << std::endl; // uint8_t val8= 0; - int32_t val1= 0, val2= 0; + int32_t val1 = 0, val2 = 0; val1 = readbin(val1, bin, swapit); // out << val << std::endl; val2 = readbin(val2, bin, swapit); @@ -2999,53 +3086,56 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath xml_col column; column.v = BErr(bin, swapit); - if (val2) column.c_s = std::to_string(val2); + if (val2) + column.c_s = std::to_string(val2); column.c_t = "e"; column.c_r = int_to_col(val1 + 1) + std::to_string(row + 1); colvec.push_back(column); - // out << "" << std::endl; - // out << "" << BErr(bin, swapit) << "" << std::endl; - // out << "" << std::endl; + // out << "" << std::endl; out << "" << + // BErr(bin, swapit) << "" << std::endl; out << "" << std::endl; break; } - case BrtCellMeta: - { - if (debug) Rcpp::Rcout << "BrtCellMeta: " << bin.tellg() << std::endl; + case BrtCellMeta: { + if (debug) + Rcpp::Rcout << "BrtCellMeta: " << bin.tellg() << std::endl; uint32_t icmb = 0; - icmb = readbin(icmb, bin, swapit); + icmb = readbin(icmb, bin, swapit); if (debug) - Rcpp::Rcout << "cell contains unhandled cell metadata entry" << - icmb << std::endl; + Rcpp::Rcout << "cell contains unhandled cell metadata entry" << icmb << std::endl; break; } - case BrtFmlaBool: - { - if (debug) Rcpp::Rcout << "BrtFmlaBool: " << bin.tellg() << std::endl; + case BrtFmlaBool: { + if (debug) + Rcpp::Rcout << "BrtFmlaBool: " << bin.tellg() << std::endl; // bin.seekg(size, bin.cur); int32_t is_shared_formula = false; std::vector cell; cell = Cell(bin, swapit); - col = cell[0]; - if (debug) Rf_PrintValue(Rcpp::wrap(cell)); + col = cell[0]; + if (debug) + Rf_PrintValue(Rcpp::wrap(cell)); bool val = 0; - val = readbin(val, bin, swapit); - if (debug) Rcpp::Rcout << val << std::endl; + val = readbin(val, bin, swapit); + if (debug) + Rcpp::Rcout << val << std::endl; uint16_t grbitFlags = 0; - grbitFlags = readbin(grbitFlags, bin, swapit); + grbitFlags = readbin(grbitFlags, bin, swapit); GrbitFmlaFields *fields = (GrbitFmlaFields *)&grbitFlags; // GrbitFmlaFields *fields = (GrbitFmlaFields *)&grbitFlags; - std::string fml = CellParsedFormula(bin, swapit, debug, 0, row, is_shared_formula, has_revision_record); + std::string fml = + CellParsedFormula(bin, swapit, debug, 0, row, is_shared_formula, has_revision_record); xml_col column; column.v = std::to_string((int32_t)val); @@ -3053,7 +3143,7 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath std::string a0 = int_to_col(cell[0] + 1) + std::to_string(row); std::string a1 = int_to_col(cell[0] + 1) + std::to_string(row + 1); - auto sfml = shared_cells.find(fml); + auto sfml = shared_cells.find(fml); auto sfml1 = shared_cells.find(a0); if ((fml.empty() || sfml != shared_cells.end()) && sfml1 != shared_cells.end()) { column.f_t = fml_type; @@ -3064,38 +3154,42 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } else { column.f = fml; } - if (cell[1]) column.c_s = std::to_string(cell[1]); + if (cell[1]) + column.c_s = std::to_string(cell[1]); column.c_t = "b"; column.c_r = a1; - if (fields->fAlwaysCalc) column.f_ca = std::to_string(fields->fAlwaysCalc); + if (fields->fAlwaysCalc) + column.f_ca = std::to_string(fields->fAlwaysCalc); colvec.push_back(column); break; } - case BrtFmlaError: - { // t="e" & - if (debug) Rcpp::Rcout << "BrtFmlaError: " << bin.tellg() << std::endl; + case BrtFmlaError: { // t="e" & + if (debug) + Rcpp::Rcout << "BrtFmlaError: " << bin.tellg() << std::endl; // bin.seekg(size, bin.cur); int32_t is_shared_formula = false; std::vector cell; cell = Cell(bin, swapit); - col = cell[0]; - if (debug) Rf_PrintValue(Rcpp::wrap(cell)); + col = cell[0]; + if (debug) + Rf_PrintValue(Rcpp::wrap(cell)); std::string fErr; fErr = BErr(bin, swapit); uint16_t grbitFlags = 0; - grbitFlags = readbin(grbitFlags, bin, swapit); + grbitFlags = readbin(grbitFlags, bin, swapit); GrbitFmlaFields *fields = (GrbitFmlaFields *)&grbitFlags; // int32_t len = size - 4 * 32 - 2 * 8; // std::string fml(len, '\0'); - std::string fml = CellParsedFormula(bin, swapit, debug, 0, row, is_shared_formula, has_revision_record); + std::string fml = + CellParsedFormula(bin, swapit, debug, 0, row, is_shared_formula, has_revision_record); xml_col column; column.v = fErr; @@ -3103,7 +3197,7 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath std::string a0 = int_to_col(cell[0] + 1) + std::to_string(row); std::string a1 = int_to_col(cell[0] + 1) + std::to_string(row + 1); - auto sfml = shared_cells.find(fml); + auto sfml = shared_cells.find(fml); auto sfml1 = shared_cells.find(a0); if ((fml.empty() || sfml != shared_cells.end()) && sfml1 != shared_cells.end()) { column.f_t = fml_type; @@ -3114,31 +3208,35 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } else { column.f = fml; } - if (cell[1]) column.c_s = std::to_string(cell[1]); + if (cell[1]) + column.c_s = std::to_string(cell[1]); column.c_t = "e"; column.c_r = a1; - if (fields->fAlwaysCalc) column.f_ca = std::to_string(fields->fAlwaysCalc); + if (fields->fAlwaysCalc) + column.f_ca = std::to_string(fields->fAlwaysCalc); colvec.push_back(column); break; } - case BrtFmlaNum: - { - if (debug) Rcpp::Rcout << "BrtFmlaNum: " << bin.tellg() << std::endl; + case BrtFmlaNum: { + if (debug) + Rcpp::Rcout << "BrtFmlaNum: " << bin.tellg() << std::endl; // bin.seekg(size, bin.cur); int32_t is_shared_formula = false; std::vector cell; cell = Cell(bin, swapit); - col = cell[0]; - if (debug) Rf_PrintValue(Rcpp::wrap(cell)); + col = cell[0]; + if (debug) + Rf_PrintValue(Rcpp::wrap(cell)); double xnum = Xnum(bin, swapit); - if (debug) Rcpp::Rcout << xnum << std::endl; + if (debug) + Rcpp::Rcout << xnum << std::endl; uint16_t grbitFlags = 0; - grbitFlags = readbin(grbitFlags, bin, swapit); + grbitFlags = readbin(grbitFlags, bin, swapit); GrbitFmlaFields *fields = (GrbitFmlaFields *)&grbitFlags; @@ -3147,7 +3245,8 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath // fields->fAlwaysCalc, // fields->unused); - std::string fml = CellParsedFormula(bin, swapit, debug, 0, row, is_shared_formula, has_revision_record); + std::string fml = + CellParsedFormula(bin, swapit, debug, 0, row, is_shared_formula, has_revision_record); std::stringstream stream; stream << std::setprecision(16) << xnum; @@ -3159,7 +3258,7 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath // fml is a reference to another cell in shared formula case? - auto sfml = shared_cells.find(fml); + auto sfml = shared_cells.find(fml); auto sfml1 = shared_cells.find(a0); if ((fml.empty() || sfml != shared_cells.end()) && sfml1 != shared_cells.end()) { column.f_t = fml_type; @@ -3170,47 +3269,51 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } else { column.f = fml; } - if (cell[1]) column.c_s = std::to_string(cell[1]); + if (cell[1]) + column.c_s = std::to_string(cell[1]); // column.c_t = "e"; column.c_r = a1; - if (fields->fAlwaysCalc) column.f_ca = std::to_string(fields->fAlwaysCalc); + if (fields->fAlwaysCalc) + column.f_ca = std::to_string(fields->fAlwaysCalc); colvec.push_back(column); break; } - case BrtFmlaString: - { - if (debug) Rcpp::Rcout << "BrtFmlaString: " << bin.tellg() << std::endl; + case BrtFmlaString: { + if (debug) + Rcpp::Rcout << "BrtFmlaString: " << bin.tellg() << std::endl; // bin.seekg(size, bin.cur); int32_t is_shared_formula = false; std::vector cell; cell = Cell(bin, swapit); - col = cell[0]; - if (debug) Rf_PrintValue(Rcpp::wrap(cell)); + col = cell[0]; + if (debug) + Rf_PrintValue(Rcpp::wrap(cell)); std::string val = XLWideString(bin, swapit); - if (debug) Rcpp::Rcout << val << std::endl; + if (debug) + Rcpp::Rcout << val << std::endl; uint16_t grbitFlags = 0; - grbitFlags = readbin(grbitFlags, bin, swapit); + grbitFlags = readbin(grbitFlags, bin, swapit); GrbitFmlaFields *fields = (GrbitFmlaFields *)&grbitFlags; - std::string fml = CellParsedFormula(bin, swapit, debug, 0, row, is_shared_formula, has_revision_record); + std::string fml = + CellParsedFormula(bin, swapit, debug, 0, row, is_shared_formula, has_revision_record); // if (is_shared_formula) { // Rcpp::Rcout << fml << std::endl; // } - std::string a0 = int_to_col(cell[0] + 1) + std::to_string(row); std::string a1 = int_to_col(cell[0] + 1) + std::to_string(row + 1); xml_col column; - auto sfml = shared_cells.find(fml); + auto sfml = shared_cells.find(fml); auto sfml1 = shared_cells.find(a0); if ((fml.empty() || sfml != shared_cells.end()) && sfml1 != shared_cells.end()) { column.f_t = fml_type; @@ -3222,26 +3325,28 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath column.f = fml; } column.v = val; - if (cell[1]) column.c_s = std::to_string(cell[1]); + if (cell[1]) + column.c_s = std::to_string(cell[1]); column.c_t = "str"; column.c_r = a1; - if (fields->fAlwaysCalc) column.f_ca = std::to_string(fields->fAlwaysCalc); + if (fields->fAlwaysCalc) + column.f_ca = std::to_string(fields->fAlwaysCalc); colvec.push_back(column); break; } - case BrtArrFmla: - { - if (debug) Rcpp::Rcout << "BrtArrFmla: " << bin.tellg() << std::endl; + case BrtArrFmla: { + if (debug) + Rcpp::Rcout << "BrtArrFmla: " << bin.tellg() << std::endl; int32_t is_shared_formula = false; - uint8_t flags = 0; + uint8_t flags = 0; int32_t rwFirst = 0, rwLast = 0, colFirst = 0, colLast = 0; - rwFirst = UncheckedRw(bin, swapit) +1; - rwLast = UncheckedRw(bin, swapit) +1; - colFirst = UncheckedCol(bin, swapit) +1; - colLast = UncheckedCol(bin, swapit) +1; + rwFirst = UncheckedRw(bin, swapit) + 1; + rwLast = UncheckedRw(bin, swapit) + 1; + colFirst = UncheckedCol(bin, swapit) + 1; + colLast = UncheckedCol(bin, swapit) + 1; std::string lref = int_to_col(colFirst) + std::to_string(rwFirst); std::string rref = int_to_col(colLast) + std::to_string(rwLast); @@ -3250,36 +3355,39 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (lref.compare(rref) == 0) { ref = lref; } else { - ref = lref + ":" + rref; + ref = lref + ":" + rref; } - if (debug) Rcpp::Rcout << "ref: " << ref << std::endl; + if (debug) + Rcpp::Rcout << "ref: " << ref << std::endl; flags = readbin(flags, bin, 0); - std::string fml = CellParsedFormula(bin, swapit, debug, col, row, is_shared_formula, has_revision_record); - if (debug) Rcpp::Rcout << "BrtArrFmla: " << fml << std::endl; + std::string fml = + CellParsedFormula(bin, swapit, debug, col, row, is_shared_formula, has_revision_record); + if (debug) + Rcpp::Rcout << "BrtArrFmla: " << fml << std::endl; // add to the last colvec element - auto last = colvec.size() - 1L; - colvec[last].f = fml; - colvec[last].f_t = "array"; + auto last = colvec.size() - 1L; + colvec[last].f = fml; + colvec[last].f_t = "array"; colvec[last].f_ref = ref; - colvec[last].f_si = ""; + colvec[last].f_si = ""; break; } - case BrtShrFmla: - { - if (debug) Rcpp::Rcout << "BrtShrFmla: " << bin.tellg() << std::endl; + case BrtShrFmla: { + if (debug) + Rcpp::Rcout << "BrtShrFmla: " << bin.tellg() << std::endl; int32_t is_shared_formula = false; int32_t rwFirst = 0, rwLast = 0, colFirst = 0, colLast = 0; rwFirst = UncheckedRw(bin, swapit); // +1 rwLast = UncheckedRw(bin, swapit); // +1 - colFirst = UncheckedCol(bin, swapit) +1; - colLast = UncheckedCol(bin, swapit) +1; + colFirst = UncheckedCol(bin, swapit) + 1; + colLast = UncheckedCol(bin, swapit) + 1; std::vector cells = dims_to_cells(rwFirst, rwLast, colFirst, colLast); @@ -3297,39 +3405,45 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (lref.compare(rref) == 0) { ref = lref; } else { - ref = lref + ":" + rref; + ref = lref + ":" + rref; } - if (debug) Rcpp::Rcout << "ref: " << ref << std::endl; + if (debug) + Rcpp::Rcout << "ref: " << ref << std::endl; - std::string fml = CellParsedFormula(bin, swapit, debug, col, row, is_shared_formula, has_revision_record); - if (debug) Rcpp::Rcout << "BrtShrFmla: " << fml << std::endl; + std::string fml = + CellParsedFormula(bin, swapit, debug, col, row, is_shared_formula, has_revision_record); + if (debug) + Rcpp::Rcout << "BrtShrFmla: " << fml << std::endl; fml_type = "shared"; // add to the last colvec element - auto last = colvec.size() - 1L; - colvec[last].f = fml; - colvec[last].f_t = fml_type; // not sure how many cells share array type + auto last = colvec.size() - 1L; + colvec[last].f = fml; + colvec[last].f_t = fml_type; // not sure how many cells share array type colvec[last].f_ref = ref; - colvec[last].f_si = std::to_string(shared_cell_cntr); + colvec[last].f_si = std::to_string(shared_cell_cntr); ++shared_cell_cntr; break; } - case BrtEndSheetData: - { - if (debug) Rcpp::Rcout << "" << bin.tellg() << std::endl; + case BrtEndSheetData: { + if (debug) + Rcpp::Rcout << "" << bin.tellg() << std::endl; if (!first_row) { // should be the last row for (size_t i = 0; i < colvec.size(); ++i) { - out << "" << std::endl; + out << "" << std::endl; out << "" << escape_xml(colvec[i].v) << "" << std::endl; - out << "" << colvec[i].f << "" << std::endl; + out << "" << colvec[i].f << "" + << std::endl; out << "" << std::endl; } @@ -3347,27 +3461,28 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtSheetProtection: - { - if (debug) Rcpp::Rcout << "BrtSheetProtection: " << bin.tellg() << std::endl; + case BrtSheetProtection: { + if (debug) + Rcpp::Rcout << "BrtSheetProtection: " << bin.tellg() << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginMergeCells: - { - if (debug) Rcpp::Rcout << "BrtBeginMergeCells: " << bin.tellg() << std::endl; + case BrtBeginMergeCells: { + if (debug) + Rcpp::Rcout << "BrtBeginMergeCells: " << bin.tellg() << std::endl; uint32_t cmcs = 0; - cmcs = readbin(cmcs, bin, swapit); - if (debug) Rcpp::Rcout << "count: " << cmcs << std::endl; + cmcs = readbin(cmcs, bin, swapit); + if (debug) + Rcpp::Rcout << "count: " << cmcs << std::endl; - out << ""<< std::endl; - break; + out << "" << std::endl; + break; } - case BrtMergeCell: - { - if (debug) Rcpp::Rcout << "BrtMergeCell: " << bin.tellg() << std::endl; + case BrtMergeCell: { + if (debug) + Rcpp::Rcout << "BrtMergeCell: " << bin.tellg() << std::endl; int32_t rwFirst = 0, rwLast = 0, colFirst = 0, colLast = 0; @@ -3377,104 +3492,103 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath colLast = UncheckedCol(bin, swapit) + 1L; if (debug) - Rprintf("MergeCell: %d %d %d %d\n", - rwFirst, rwLast, colFirst, colLast); + Rprintf("MergeCell: %d %d %d %d\n", rwFirst, rwLast, colFirst, colLast); - out << "" << std::endl; + out << "" << std::endl; break; } - case BrtEndMergeCells: - { - if (debug) Rcpp::Rcout << "BrtEndMergeCells: " << bin.tellg() << std::endl; + case BrtEndMergeCells: { + if (debug) + Rcpp::Rcout << "BrtEndMergeCells: " << bin.tellg() << std::endl; out << "" << std::endl; break; } - case BrtPrintOptions: - { - if (debug) Rcpp::Rcout << "BrtPrintOptions: " << bin.tellg() << std::endl; + case BrtPrintOptions: { + if (debug) + Rcpp::Rcout << "BrtPrintOptions: " << bin.tellg() << std::endl; uint16_t flags = 0; - flags = readbin(flags, bin, swapit); - break; - } - - case BrtMargins: - { - if (debug) Rcpp::Rcout << "BrtMargins: " << bin.tellg() << std::endl; - - double xnumLeft = 0, xnumRight = 0, xnumTop = 0, xnumBottom = 0, xnumHeader = 0, xnumFooter = 0; - xnumLeft = Xnum(bin, swapit); - xnumRight = Xnum(bin, swapit); - xnumTop = Xnum(bin, swapit); - xnumBottom = Xnum(bin, swapit); - xnumHeader = Xnum(bin, swapit); - xnumFooter = Xnum(bin, swapit); - - if (xnumLeft < 0 || xnumLeft > 49) Rcpp::stop("xnumLeft size out of bounds"); - if (xnumRight < 0 || xnumRight > 49) Rcpp::stop("xnumRight size out of bounds"); - if (xnumTop < 0 || xnumTop > 49) Rcpp::stop("xnumTop size out of bounds"); - if (xnumBottom < 0 || xnumBottom > 49) Rcpp::stop("xnumBottom size out of bounds"); - if (xnumHeader < 0 || xnumHeader > 49) Rcpp::stop("xnumHeader size out of bounds"); - if (xnumFooter < 0 || xnumFooter > 49) Rcpp::stop("xnumFooter size out of bounds"); - - out << "" << std::endl; - + flags = readbin(flags, bin, swapit); break; } - case BrtUID: - { - if (debug) Rcpp::Rcout << "BrtUID: " << bin.tellg() << std::endl; + case BrtMargins: { + if (debug) + Rcpp::Rcout << "BrtMargins: " << bin.tellg() << std::endl; + + double xnumLeft = 0, xnumRight = 0, xnumTop = 0, xnumBottom = 0, xnumHeader = 0, + xnumFooter = 0; + xnumLeft = Xnum(bin, swapit); + xnumRight = Xnum(bin, swapit); + xnumTop = Xnum(bin, swapit); + xnumBottom = Xnum(bin, swapit); + xnumHeader = Xnum(bin, swapit); + xnumFooter = Xnum(bin, swapit); + + if (xnumLeft < 0 || xnumLeft > 49) + Rcpp::stop("xnumLeft size out of bounds"); + if (xnumRight < 0 || xnumRight > 49) + Rcpp::stop("xnumRight size out of bounds"); + if (xnumTop < 0 || xnumTop > 49) + Rcpp::stop("xnumTop size out of bounds"); + if (xnumBottom < 0 || xnumBottom > 49) + Rcpp::stop("xnumBottom size out of bounds"); + if (xnumHeader < 0 || xnumHeader > 49) + Rcpp::stop("xnumHeader size out of bounds"); + if (xnumFooter < 0 || xnumFooter > 49) + Rcpp::stop("xnumFooter size out of bounds"); + + out << "" << std::endl; + + break; + } + + case BrtUID: { + if (debug) + Rcpp::Rcout << "BrtUID: " << bin.tellg() << std::endl; bin.seekg(size, bin.cur); break; } - case BrtDrawing: - { - if (debug) Rcpp::Rcout << "BrtDrawing" << std::endl; + case BrtDrawing: { + if (debug) + Rcpp::Rcout << "BrtDrawing" << std::endl; std::string stRelId = XLNullableWideString(bin, swapit); out << "" << std::endl; break; } - case BrtLegacyDrawing: - { - if (debug) Rcpp::Rcout << "BrtLegacyDrawing" << std::endl; + case BrtLegacyDrawing: { + if (debug) + Rcpp::Rcout << "BrtLegacyDrawing" << std::endl; std::string stRelId = XLNullableWideString(bin, swapit); out << "" << std::endl; break; } - case BrtLegacyDrawingHF: - { - if (debug) Rcpp::Rcout << "BrtLegacyDrawingHF" << std::endl; + case BrtLegacyDrawingHF: { + if (debug) + Rcpp::Rcout << "BrtLegacyDrawingHF" << std::endl; std::string stRelId = XLNullableWideString(bin, swapit); out << "" << std::endl; break; } - case BrtHLink: - { - if (debug) Rcpp::Rcout << "BrtHLink" << std::endl; - - std::vector rfx = UncheckedRfX(bin, swapit); - std::string relId = XLNullableWideString(bin, swapit); - std::string location = XLWideString(bin, swapit); - std::string tooltip = XLWideString(bin, swapit); - std::string display = XLWideString(bin, swapit); + case BrtHLink: { + if (debug) + Rcpp::Rcout << "BrtHLink" << std::endl; + std::vector rfx = UncheckedRfX(bin, swapit); + std::string relId = XLNullableWideString(bin, swapit); + std::string location = XLWideString(bin, swapit); + std::string tooltip = XLWideString(bin, swapit); + std::string display = XLWideString(bin, swapit); std::string lref = int_to_col(rfx[2] + 1) + std::to_string(rfx[0] + 1); std::string rref = int_to_col(rfx[3] + 1) + std::to_string(rfx[1] + 1); @@ -3483,18 +3597,20 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (lref.compare(rref) == 0) { ref = lref; } else { - ref = lref + ":" + rref; + ref = lref + ":" + rref; } - std::string hlink = ""; + std::string hlink = ""; hlinks.push_back(hlink); break; } - case BrtBeginAFilter: - { - if (debug) Rcpp::Rcout << "BrtBeginAFilter" << std::endl; + case BrtBeginAFilter: { + if (debug) + Rcpp::Rcout << "BrtBeginAFilter" << std::endl; std::vector rfx = UncheckedRfX(bin, swapit); std::string lref = int_to_col(rfx[2] + 1) + std::to_string(rfx[0] + 1); @@ -3504,7 +3620,7 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (lref.compare(rref) == 0) { ref = lref; } else { - ref = lref + ":" + rref; + ref = lref + ":" + rref; } // ignoring filterColumn for now @@ -3515,88 +3631,88 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtBeginFilterColumn: - { - if (debug) Rcpp::Rcout << "BrtBeginFilterColumn" << std::endl; + case BrtBeginFilterColumn: { + if (debug) + Rcpp::Rcout << "BrtBeginFilterColumn" << std::endl; uint16_t flags = 0; uint32_t dwCol = 0; - dwCol = readbin(dwCol, bin, swapit); - flags = readbin(flags, bin, swapit); + dwCol = readbin(dwCol, bin, swapit); + flags = readbin(flags, bin, swapit); // fHideArrow // fNoBtn - out << "" << std::endl; + out << "" << std::endl; break; } - case BrtBeginFilters: - { - if (debug) Rcpp::Rcout << "BrtBeginFilters" << std::endl; + case BrtBeginFilters: { + if (debug) + Rcpp::Rcout << "BrtBeginFilters" << std::endl; // bin.seekg(size, bin.cur); uint32_t fBlank = 0, unused = 0; - fBlank = readbin(fBlank, bin, swapit); // a 32bit flag, after all ... why not? + fBlank = readbin(fBlank, bin, + swapit); // a 32bit flag, after all ... why not? unused = readbin(unused, bin, swapit); // maybe calendarType? - out << "" << std::endl; + out << "" << std::endl; break; } - case BrtFilter: - { - if (debug) Rcpp::Rcout << "BrtFilter" << std::endl; + case BrtFilter: { + if (debug) + Rcpp::Rcout << "BrtFilter" << std::endl; std::string rgch = XLWideString(bin, swapit); out << "" << std::endl; // bin.seekg(size, bin.cur); break; } - case BrtEndFilters: - { - if (debug) Rcpp::Rcout << "BrtEndFilters" << std::endl; + case BrtEndFilters: { + if (debug) + Rcpp::Rcout << "BrtEndFilters" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtColorFilter: - { - if (debug) Rcpp::Rcout << "BrtColorFilter" << std::endl; + case BrtColorFilter: { + if (debug) + Rcpp::Rcout << "BrtColorFilter" << std::endl; uint32_t dxfid = 0, fCellColor = 0; - dxfid = readbin(dxfid, bin, swapit); + dxfid = readbin(dxfid, bin, swapit); fCellColor = readbin(fCellColor, bin, swapit); - out << "" << std::endl; + out << "" + << std::endl; break; } - case BrtBeginCustomFilters: case BrtBeginCustomFilters14: - case BrtBeginCustomRichFilters: - { + case BrtBeginCustomRichFilters: { int32_t fAnd = 0; // in xlsb it is flipped fAnd = readbin(fAnd, bin, swapit) ^ 1; out << ""; break; } case BrtCustomFilter: - case BrtCustomFilter14: - { - int8_t vts = 0, grbitSgn = 0; - double union_val = 0; + case BrtCustomFilter14: { + int8_t vts = 0, grbitSgn = 0; + double union_val = 0; std::string vtsStringXls; - vts = readbin(vts, bin, swapit); + vts = readbin(vts, bin, swapit); grbitSgn = readbin(grbitSgn, bin, swapit); if (vts == 4) { @@ -3605,8 +3721,8 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } else if (vts == 8) { // a bool int8_t boolean = 0; - boolean = readbin(boolean, bin, swapit); - union_val = static_cast(readbin(boolean, bin, swapit)); + boolean = readbin(boolean, bin, swapit); + union_val = static_cast(readbin(boolean, bin, swapit)); for (int8_t blk = 0; blk < 7; ++blk) { readbin(boolean, bin, swapit); } @@ -3631,8 +3747,7 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } case BrtEndCustomFilters: - case BrtEndCustomRichFilters: - { + case BrtEndCustomRichFilters: { out << "" << std::endl; @@ -3640,16 +3755,16 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } case BrtBeginUserCsViews: - case BrtBeginUserShViews: - { - if (debug) Rcpp::Rcout << "BrtBeginUserXXViews" << std::endl; + case BrtBeginUserShViews: { + if (debug) + Rcpp::Rcout << "BrtBeginUserXXViews" << std::endl; out << "" << std::endl; break; } - case BrtBeginUserCsView: - { - if (debug) Rcpp::Rcout << "BrtBeginUserCsView" << std::endl; + case BrtBeginUserCsView: { + if (debug) + Rcpp::Rcout << "BrtBeginUserCsView" << std::endl; int32_t guid0 = 0, guid1 = 0, guid2 = 0, guid3 = 0, iTabId = 0, dwScale = 0, flags = 0; @@ -3672,7 +3787,7 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath // fZoomToFit out << "" << std::endl; @@ -3680,11 +3795,12 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtBeginUserShView: - { - if (debug) Rcpp::Rcout << "BrtBeginUserShView" << std::endl; + case BrtBeginUserShView: { + if (debug) + Rcpp::Rcout << "BrtBeginUserShView" << std::endl; - int32_t guid0 = 0, guid1 = 0, guid2 = 0, guid3 = 0, iTabId = 0, dwScale = 0, icv = 0, flags = 0; + int32_t guid0 = 0, guid1 = 0, guid2 = 0, guid3 = 0, iTabId = 0, dwScale = 0, icv = 0, + flags = 0; std::vector guids(4); guids[0] = readbin(guid0, bin, 0); @@ -3712,7 +3828,7 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath BrtBeginUserShViewFields *fields = (BrtBeginUserShViewFields *)&flags; out << "" << std::endl; break; } case BrtEndUserCsViews: - case BrtEndUserShViews: - { - if (debug) Rcpp::Rcout << "BrtEndUserXXViews" << std::endl; + case BrtEndUserShViews: { + if (debug) + Rcpp::Rcout << "BrtEndUserXXViews" << std::endl; out << "" << std::endl; break; } - case BrtDynamicFilter: - { - if (debug) Rcpp::Rcout << "BrtDynamicFilter" << std::endl; + case BrtDynamicFilter: { + if (debug) + Rcpp::Rcout << "BrtDynamicFilter" << std::endl; Rcpp::warning("Dynamic Filter found. This is not handled."); bin.seekg(size, bin.cur); break; } case BrtIconFilter: - case BrtIconFilter14: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtIconFilter14: { + if (debug) + Rcpp::Rcout << "" << std::endl; uint32_t iIconSet = 0, iIcon = 0; iIconSet = readbin(iIconSet, bin, swapit); - iIcon = readbin(iIcon, bin, swapit); + iIcon = readbin(iIcon, bin, swapit); std::string iconSet; - if (iIconSet) iconSet = to_iconset(iIconSet); + if (iIconSet) + iconSet = to_iconset(iIconSet); - out << "" << std::endl; + out << "" + << std::endl; break; } - case BrtEndFilterColumn: - { - if (debug) Rcpp::Rcout << "BrtEndFilterColumn" << std::endl; + case BrtEndFilterColumn: { + if (debug) + Rcpp::Rcout << "BrtEndFilterColumn" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndAFilter: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndAFilter: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginListParts: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginListParts: { + if (debug) + Rcpp::Rcout << "" << std::endl; uint32_t cParts = 0; - cParts = readbin(cParts, bin, swapit); + cParts = readbin(cParts, bin, swapit); out << "" << std::endl; break; } - case BrtListPart: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtListPart: { + if (debug) + Rcpp::Rcout << "" << std::endl; std::string stRelID = XLNullableWideString(bin, swapit); out << "" << std::endl; break; } - case BrtEndListParts: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndListParts: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; break; } - case BrtBeginOleObjects: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginOleObjects: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; break; } - case BrtOleObject: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtOleObject: { + if (debug) + Rcpp::Rcout << "" << std::endl; - uint16_t flags = 0; + uint16_t flags = 0; uint32_t dwAspect = 0, dwOleUpdate = 0, shapeId = 0; - dwAspect = readbin(dwAspect, bin, swapit); - dwOleUpdate = readbin(dwOleUpdate, bin, swapit); - shapeId = readbin(shapeId, bin, swapit); - flags = readbin(flags, bin, swapit); + dwAspect = readbin(dwAspect, bin, swapit); + dwOleUpdate = readbin(dwOleUpdate, bin, swapit); + shapeId = readbin(shapeId, bin, swapit); + flags = readbin(flags, bin, swapit); bool fLinked = (flags & 0x8000) != 0; std::string strProgID = XLNullableWideString(bin, swapit); int32_t sharedFormula = false; - if (fLinked) std::string link = CellParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); + if (fLinked) + std::string link = + CellParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); std::string stRelID = XLNullableWideString(bin, swapit); - out << "" << std::endl; + out << "" << std::endl; break; } - case BrtEndOleObjects: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndOleObjects: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; break; } - case BrtBeginDVals: - { - if (debug) Rcpp::Rcout << "BrtBeginDVals" << std::endl; + case BrtBeginDVals: { + if (debug) + Rcpp::Rcout << "BrtBeginDVals" << std::endl; uint16_t flags = 0; uint32_t xLeft = 0, yTop = 0, unused3 = 0, idvMac = 0; @@ -3906,20 +4027,20 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath unused3 = readbin(unused3, bin, swapit); idvMac = readbin(idvMac, bin, swapit); - if (idvMac > 65534) Rcpp::stop("idvMac to big"); + if (idvMac > 65534) + Rcpp::stop("idvMac to big"); out << "" << std::endl; break; } + case BrtDVal: { + if (debug) + Rcpp::Rcout << "BrtDVal" << std::endl; - case BrtDVal: - { - if (debug) Rcpp::Rcout << "BrtDVal" << std::endl; - - uint32_t flags = 0; + uint32_t flags = 0; std::vector sqrfx; - std::string strErrorTitle = "", strError = "", strPromptTitle = "", strPrompt = ""; + std::string strErrorTitle = "", strError = "", strPromptTitle = "", strPrompt = ""; flags = readbin(flags, bin, swapit); @@ -3931,9 +4052,11 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath strPromptTitle = XLNullableWideString(bin, swapit); strPrompt = XLNullableWideString(bin, swapit); - int32_t sharedFormula = false; - std::string formula1 = CellParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); - std::string formula2 = CellParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); + int32_t sharedFormula = false; + std::string formula1 = + CellParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); + std::string formula2 = + CellParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); std::string lref = int_to_col(sqrfx[3] + 1) + std::to_string(sqrfx[1] + 1); std::string rref = int_to_col(sqrfx[4] + 1) + std::to_string(sqrfx[2] + 1); @@ -3942,25 +4065,22 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (lref.compare(rref) == 0) { sqref = lref; } else { - sqref = lref + ":" + rref; + sqref = lref + ":" + rref; } - out << "valType) << "\" " << - "operator=\"" << typOperator(fields->typOperator) << "\" " << - "allowBlank=\"" << (bool)fields->fAllowBlank << "\" " << - "showInputMessage=\"" << (bool)fields->fShowInputMsg << "\" " << - "showErrorMessage=\"" << (bool)fields->fShowErrorMsg << "\" " << - "sqref=\"" << sqref << "\" >" << - "" << formula1 << "" << - "" << formula2 << "" << - "" << std::endl; + out << "valType) << "\" " + << "operator=\"" << typOperator(fields->typOperator) << "\" " << "allowBlank=\"" + << (bool)fields->fAllowBlank << "\" " + << "showInputMessage=\"" << (bool)fields->fShowInputMsg << "\" " + << "showErrorMessage=\"" << (bool)fields->fShowErrorMsg << "\" " + << "sqref=\"" << sqref << "\" >" << "" << formula1 << "" + << "" << formula2 << "" + << "" << std::endl; break; } - case BrtDValList: - { + case BrtDValList: { Rcpp::Rcout << "BrtDValList" << std::endl; std::string strDvalList = XLWideString(bin, swapit); @@ -3969,22 +4089,22 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath break; } - case BrtEndDVals: - { - if (debug) Rcpp::Rcout << "BrtEndDVals" << std::endl; + case BrtEndDVals: { + if (debug) + Rcpp::Rcout << "BrtEndDVals" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginDVals14: - { - if (debug) Rcpp::Rcout << "BrtBeginDVals14" << std::endl; + case BrtBeginDVals14: { + if (debug) + Rcpp::Rcout << "BrtBeginDVals14" << std::endl; // Rcpp::warning("Worksheet contains unhandled data validation."); // FRT blank uint32_t reserved = 0; - reserved = readbin(reserved, bin, swapit); + reserved = readbin(reserved, bin, swapit); // Dvals uint16_t flags = 0; @@ -3997,22 +4117,25 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath unused3 = readbin(unused3, bin, swapit); idvMac = readbin(idvMac, bin, swapit); - if (idvMac > 65534) Rcpp::stop("idvMac to big"); + if (idvMac > 65534) + Rcpp::stop("idvMac to big"); - out << "" << std::endl; + out << "" + << std::endl; break; } - case BrtDVal14: - { - if (debug) Rcpp::Rcout << "BrtDVal14" << std::endl; + case BrtDVal14: { + if (debug) + Rcpp::Rcout << "BrtDVal14" << std::endl; // Start FRTHeader - uint32_t flags_frt = 0; + uint32_t flags_frt = 0; std::vector frt_sqrefs; std::vector frt_fmls; @@ -4023,26 +4146,25 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (fields_frt->fRef) { // but must be 0 // Rcpp::Rcout << "fRef" << std::endl; uint32_t cref = 0; - cref = readbin(cref, bin, swapit); + cref = readbin(cref, bin, swapit); // Rcpp::Rcout << "Refs: " << cref << std::endl; for (uint32_t crf = 0; crf < cref; ++crf) { - uint32_t flags_cref = 0; - flags_cref = readbin(flags_cref, bin, swapit); + uint32_t flags_cref = 0; + flags_cref = readbin(flags_cref, bin, swapit); std::vector rfx_cref = UncheckedRfX(bin, swapit); } - } if (fields_frt->fSqref) { // must be 1 // Rcpp::Rcout << "fSqref" << std::endl; uint32_t csqref = 0; - csqref = readbin(csqref, bin, swapit); + csqref = readbin(csqref, bin, swapit); // Rcpp::Rcout << "Sqrefs: " << csqref << std::endl; for (uint32_t csqrf = 0; csqrf < csqref; ++csqrf) { uint32_t flags_csqrf = 0; - flags_csqrf = readbin(flags_csqrf, bin, swapit); + flags_csqrf = readbin(flags_csqrf, bin, swapit); /* beg move this to function -------------------------------------*/ std::vector rfx_csqrfx = UncheckedSqRfX(bin, swapit); @@ -4054,31 +4176,29 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (lref.compare(rref) == 0) { sqref = lref; } else { - sqref = lref + ":" + rref; + sqref = lref + ":" + rref; } /* end move this to function -------------------------------------*/ frt_sqrefs.push_back(sqref); - } - } if (fields_frt->fFormula) { // 0 or 1 // Rcpp::Rcout << "fFormula" << std::endl; uint32_t cformula = 0; - cformula = readbin(cformula, bin, swapit); + cformula = readbin(cformula, bin, swapit); // Rcpp::Rcout << "Formulas: " << cformula << std::endl; for (uint32_t cfml = 0; cfml < cformula; ++cfml) { - uint32_t flags_cfml = 0; - flags_cfml = readbin(flags_cfml, bin, swapit); - int32_t sharedFormula = false; - std::string frt_fml = FRTParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); + uint32_t flags_cfml = 0; + flags_cfml = readbin(flags_cfml, bin, swapit); + int32_t sharedFormula = false; + std::string frt_fml = + FRTParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); frt_fmls.push_back(frt_fml); // Rcpp::Rcout << frt_fmls[cfml] << std::endl; } - } if (fields_frt->fRelID) { // 0 @@ -4087,14 +4207,13 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } // End FRTHeader - uint32_t flags = 0; + uint32_t flags = 0; std::string strErrorTitle = "", strError = "", strPromptTitle = "", strPrompt = ""; flags = readbin(flags, bin, swapit); BrtDValFields *fields = (BrtDValFields *)&flags; - // if (debug) // Rprintf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", // (uint32_t)fields->valType, @@ -4115,76 +4234,68 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath strPromptTitle = XLNullableWideString(bin, swapit); strPrompt = XLNullableWideString(bin, swapit); - out << "valType) << "\" " << - "operator=\"" << typOperator(fields->typOperator) << "\" " << - "allowBlank=\"" << (bool)fields->fAllowBlank << "\" " << - "showInputMessage=\"" << (bool)fields->fShowInputMsg << "\" " << - "showErrorMessage=\"" << (bool)fields->fShowErrorMsg << "\" " << - // "xr:uid=\"{00000000-0002-0000-0200-000000000000}\" " << - ">"; + out << "valType) << "\" " + << "operator=\"" << typOperator(fields->typOperator) << "\" " << "allowBlank=\"" + << (bool)fields->fAllowBlank << "\" " + << "showInputMessage=\"" << (bool)fields->fShowInputMsg << "\" " + << "showErrorMessage=\"" << (bool)fields->fShowErrorMsg << "\" " << + // "xr:uid=\"{00000000-0002-0000-0200-000000000000}\" " << + ">"; for (size_t len = 0; len < frt_fmls.size(); ++len) { - out << - "" << - "" << - frt_fmls[len] << - "" << - ""; + out << "" << "" << frt_fmls[len] + << "" + << ""; } for (size_t len = 0; len < frt_fmls.size(); ++len) { - out << - "" << - frt_sqrefs[len] << - ""; + out << "" << frt_sqrefs[len] << ""; } - out << "" << std::endl; + out << "" << std::endl; break; } - case BrtEndDVals14: - { - if (debug) Rcpp::Rcout << "BrtEndDVals14" << std::endl; + case BrtEndDVals14: { + if (debug) + Rcpp::Rcout << "BrtEndDVals14" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtBeginDCon: - case BrtEndDCon: - { - if (debug) Rcpp::Rcout << "BrtBegin/EndDCon" << std::endl; + case BrtEndDCon: { + if (debug) + Rcpp::Rcout << "BrtBegin/EndDCon" << std::endl; bin.seekg(size, bin.cur); break; } case BrtBeginConditionalFormattings: - case BrtBeginConditionalFormatting14: - { - if (debug) Rcpp::Rcout << "BrtBegin/EndDCon" << std::endl; + case BrtBeginConditionalFormatting14: { + if (debug) + Rcpp::Rcout << "BrtBegin/EndDCon" << std::endl; Rcpp::warning("Worksheet contains unhandled conditional formatting."); bin.seekg(size, bin.cur); break; } - case BrtBeginConditionalFormatting: - { + case BrtBeginConditionalFormatting: { - if (debug) Rcpp::Rcout << "" << std::endl; + if (debug) + Rcpp::Rcout << "" << std::endl; - uint32_t ccf = 0, fPivot = 0; + uint32_t ccf = 0, fPivot = 0; std::vector sqrfx; - ccf = readbin(ccf, bin, swapit); // not needed? + ccf = readbin(ccf, bin, swapit); // not needed? fPivot = readbin(fPivot, bin, swapit); - sqrfx = UncheckedSqRfX(bin, swapit); + sqrfx = UncheckedSqRfX(bin, swapit); std::string lref = int_to_col(sqrfx[3] + 1) + std::to_string(sqrfx[1] + 1); std::string rref = int_to_col(sqrfx[4] + 1) + std::to_string(sqrfx[2] + 1); @@ -4192,40 +4303,42 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath if (lref.compare(rref) == 0) { sqref = lref; } else { - sqref = lref + ":" + rref; + sqref = lref + ":" + rref; } out << "" << std::endl; break; } - case BrtBeginCFRule: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBeginCFRule: { + if (debug) + Rcpp::Rcout << "" << std::endl; uint16_t flags = 0; - uint32_t iType = 0, iTemplate = 0, dxfId = 0, iPri = 0, iParam = 0, reserved1 = 0, reserved2 = 0; + uint32_t iType = 0, iTemplate = 0, dxfId = 0, iPri = 0, iParam = 0, reserved1 = 0, + reserved2 = 0; uint32_t cbFmla1 = 0, cbFmla2 = 0, cbFmla3 = 0; - iType = readbin(iType, bin, swapit); + iType = readbin(iType, bin, swapit); iTemplate = readbin(iTemplate, bin, swapit); - dxfId = readbin(dxfId, bin, swapit); - iPri = readbin(iPri, bin, swapit); - iParam = readbin(iParam, bin, swapit); + dxfId = readbin(dxfId, bin, swapit); + iPri = readbin(iPri, bin, swapit); + iParam = readbin(iParam, bin, swapit); reserved1 = readbin(reserved1, bin, swapit); reserved2 = readbin(reserved2, bin, swapit); - flags = readbin(flags, bin, swapit); - cbFmla1 = readbin(cbFmla1, bin, swapit); - cbFmla2 = readbin(cbFmla2, bin, swapit); - cbFmla3 = readbin(cbFmla3, bin, swapit); + flags = readbin(flags, bin, swapit); + cbFmla1 = readbin(cbFmla1, bin, swapit); + cbFmla2 = readbin(cbFmla2, bin, swapit); + cbFmla3 = readbin(cbFmla3, bin, swapit); std::string strParam = XLNullableWideString(bin, swapit); - int32_t sharedFormula = false; + int32_t sharedFormula = false; std::string rgce1, rgce2, rgce3; if (cbFmla1 != 0x00000000) { rgce1 = CellParsedFormula(bin, swapit, debug, 0, 0, sharedFormula, has_revision_record); @@ -4270,68 +4383,68 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath case BrtEndConditionalFormatting14: case BrtBeginCFRule14: - case BrtEndCFRule14: - { - if (debug) Rcpp::Rcout << "BrtBegin/EndDCon 14" << std::endl; + case BrtEndCFRule14: { + if (debug) + Rcpp::Rcout << "BrtBegin/EndDCon 14" << std::endl; bin.seekg(size, bin.cur); break; } - // dxf styles for conditional formatting can be (or is always?) embedded in the worksheet - // the xlsx conversion creates + // dxf styles for conditional formatting can be (or is always?) embedded + // in the worksheet the xlsx conversion creates case BrtBeginDXFs: case BrtDXF: - case BrtEndDXFs: - { - if (debug) Rcpp::Rcout << "BrtBegin/EndDXFs in worksheet (?)" << std::endl; + case BrtEndDXFs: { + if (debug) + Rcpp::Rcout << "BrtBegin/EndDXFs in worksheet (?)" << std::endl; bin.seekg(size, bin.cur); break; } + case BrtEndCFRule: { - case BrtEndCFRule: - { - - if (debug) Rcpp::Rcout << "" << std::endl; + if (debug) + Rcpp::Rcout << "" << std::endl; // Rcpp::Rcout << "" << std::endl; break; } - case BrtEndConditionalFormatting: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtEndConditionalFormatting: { + if (debug) + Rcpp::Rcout << "" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndConditionalFormattings: - { + case BrtEndConditionalFormattings: { // UNHANDLED - if (debug) Rcpp::Rcout << "" << std::endl; + if (debug) + Rcpp::Rcout << "" << std::endl; bin.seekg(size, bin.cur); break; } // unhandled page breaks. differentiates in column and row breaks case BrtBeginColBrk: - case BrtBeginRwBrk: - { + case BrtBeginRwBrk: { - if (debug) Rcpp::Rcout << "" << std::endl; + if (debug) + Rcpp::Rcout << "" << std::endl; uint32_t ibrkMac = 0, ibrkManMac = 0; ibrkMac = readbin(ibrkMac, bin, swapit); - if (ibrkMac > 1024) Rcpp::stop("ibrkMac to big"); + if (ibrkMac > 1024) + Rcpp::stop("ibrkMac to big"); ibrkManMac = readbin(ibrkManMac, bin, swapit); break; } - case BrtBrk: - { - if (debug) Rcpp::Rcout << "" << std::endl; + case BrtBrk: { + if (debug) + Rcpp::Rcout << "" << std::endl; uint32_t unRwCol = 0, unColRwStrt = 0, unColRwEnd = 0, fMan = 0, fPivot = 0; @@ -4345,79 +4458,82 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } case BrtEndColBrk: - case BrtEndRwBrk: - { + case BrtEndRwBrk: { - if (debug) Rcpp::Rcout << "" << std::endl; + if (debug) + Rcpp::Rcout << "" << std::endl; break; } - // end unhandled page breaks + // end unhandled page breaks - case BrtFRTBegin: - { - if (debug) Rcpp::Rcout << "BrtFRTBegin" << std::endl; + case BrtFRTBegin: { + if (debug) + Rcpp::Rcout << "BrtFRTBegin" << std::endl; // we only handle this for data validation lists. - out << "" << - "" << - std::endl; + out << "" + << "" + << std::endl; ProductVersion(bin, swapit, debug); break; } - case BrtFRTEnd: - { - if (debug) Rcpp::Rcout << "BrtFRTEnd" << std::endl; + case BrtFRTEnd: { + if (debug) + Rcpp::Rcout << "BrtFRTEnd" << std::endl; out << "" << std::endl; bin.seekg(size, bin.cur); break; } - case BrtEndSheet: - { + case BrtEndSheet: { if (hlinks.size() > 1) { // did not see BrtBeginHL or BrtEndHL, likely I'm just blind hlinks.push_back(""); for (size_t i = 0; i < hlinks.size(); ++i) { - if (debug) Rcpp::Rcout << hlinks[i] << std::endl; + if (debug) + Rcpp::Rcout << hlinks[i] << std::endl; out << hlinks[i] << std::endl; } } - if (debug) Rcpp::Rcout << "" << bin.tellg() << std::endl; + if (debug) + Rcpp::Rcout << "" << bin.tellg() << std::endl; if (chartsheet) out << "" << std::endl; else out << "" << std::endl; end_of_worksheet = true; - row = 0; + row = 0; break; } // ignore error section case BrtBeginCellIgnoreECs: case BrtCellIgnoreEC: - case BrtEndCellIgnoreECs: - { - if (debug) Rcpp::Rcout << "BrtBeginCell" << std::endl; + case BrtEndCellIgnoreECs: { + if (debug) + Rcpp::Rcout << "BrtBeginCell" << std::endl; // Rcpp::warning("Worksheet contains unhandled data validation."); bin.seekg(size, bin.cur); break; } case BrtRRChgCell: - case BrtRRDefName: - { + case BrtRRDefName: { has_revision_record = true; - // -- have not seen this yet. if it appears, treat it as if a revision record was found -- - // rgce.rgce or rgceOld.rgce in BrtRRDefName - if (debug) Rcpp::Rcout << "BrtRRChgCell or BrtRRDefName" << std::endl; + // -- have not seen this yet. if it appears, treat it as if a revision + // record was found -- rgce.rgce or rgceOld.rgce in BrtRRDefName + if (debug) + Rcpp::Rcout << "BrtRRChgCell or BrtRRDefName" << std::endl; Rcpp::warning("Assuming revision record."); bin.seekg(size, bin.cur); break; @@ -4426,39 +4542,38 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath case BrtBeginSortState: case BrtEndSortState: case BrtBeginSortCond: - case BrtEndSortCond: - { - if (debug) Rcpp::warning("Worksheet contains unhandled sorting."); + case BrtEndSortCond: { + if (debug) + Rcpp::warning("Worksheet contains unhandled sorting."); bin.seekg(size, bin.cur); break; } - case BrtValueMeta: - { - if (debug) Rcpp::Rcout << "BrtValueMeta" << std::endl; + case BrtValueMeta: { + if (debug) + Rcpp::Rcout << "BrtValueMeta" << std::endl; int32_t ivmb = 0; - ivmb = readbin(ivmb, bin, swapit); + ivmb = readbin(ivmb, bin, swapit); break; } case BrtSheetProtectionIso: - case BrtCsProtection: - { - if (debug) Rcpp::Rcout << "protection" << std::endl; + case BrtCsProtection: { + if (debug) + Rcpp::Rcout << "protection" << std::endl; // uint16_t protpwd = 0; // uint32_t fLocked = 0, fObjects = 0; // unhandled - if (debug) Rcpp::warning("Worksheet contains unhandled protection."); + if (debug) + Rcpp::warning("Worksheet contains unhandled protection."); bin.seekg(size, bin.cur); break; } - default: - { + default: { // if (debug) { - Rcpp::Rcout << "Unhandled: " << std::to_string(x) << - ": " << std::to_string(size) << - " @ " << bin.tellg() << std::endl; + Rcpp::Rcout << "Unhandled: " << std::to_string(x) << ": " << std::to_string(size) << " @ " + << bin.tellg() << std::endl; // } bin.seekg(size, bin.cur); break; @@ -4477,5 +4592,4 @@ int32_t worksheet_bin(std::string filePath, bool chartsheet, std::string outPath } else { return -1; }; - }