Skip to content

Commit

Permalink
[xlsb] read PtgMemErr (#1049)
Browse files Browse the repository at this point in the history
* [xlsb] read PtgMemErr

* [xlsb] add PtgMemNoMem, PtgAttrSpaceSemi, PtgAttrBaxcel

* [xlsb] update test file
  • Loading branch information
JanMarvin authored Jun 13, 2024
1 parent 338115b commit ea27595
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/xlsb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3738,6 +3738,14 @@ int worksheet_bin(std::string filePath, bool chartsheet, std::string outPath, bo
break;
}

case BrtValueMeta:
{
if (debug) Rcpp::Rcout << "BrtValueMeta" << std::endl;
int32_t ivmb = 0;
ivmb = readbin(ivmb, bin, swapit);
break;
}

case BrtSheetProtectionIso:
case BrtCsProtection:
{
Expand Down
68 changes: 67 additions & 1 deletion src/xlsb_funs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@ std::string CellParsedFormula(std::istream& sas, bool swapit, bool debug, int co

if (((val2 >> 6) & 1) != 1) Rcpp::stop("wrong value");

// PtgAttrSpaceType
type = readbin(type, sas, swapit);
// 0-6 various different types where to add the whitespace
cch = readbin(cch, sas, swapit);
Expand All @@ -1264,6 +1265,17 @@ std::string CellParsedFormula(std::istream& sas, bool swapit, bool debug, int co
break;
}

case PtgAttrSpaceSemi:
{
// type: A PtgAttrSpaceType
uint8_t type = 0, cch = 0;
type = readbin(type, sas, swapit);
cch = readbin(cch, sas, swapit);

if (debug) Rprintf("PtgAttrSpaceSemi: %d %d\n", type, cch);
break;
}

case PtgAttrSum:
{
if (debug) Rcpp::Rcout << "PtgAttrSum" << std::endl;
Expand All @@ -1278,6 +1290,20 @@ std::string CellParsedFormula(std::istream& sas, bool swapit, bool debug, int co
break;
}

case PtgAttrBaxcel:
case PtgAttrBaxcel2:
{
// val1[8] == bitSemi if Rgce is volatile
// val2[1:4] == 0
// val2[5] == 1
// val2[6:8] == 0

uint16_t unused = 0;
unused = readbin(unused, sas, swapit);
Rcpp::warning("PtgAttrBaxcel: unhandled formula thing");
break;
}

default:{
Rprintf("Undefined Formula_TWO: %d %d\n", val1, val2);
break;
Expand Down Expand Up @@ -1874,7 +1900,47 @@ std::string CellParsedFormula(std::istream& sas, bool swapit, bool debug, int co
if (debug) Rcpp::Rcout << "PtgMemFunc" <<std::endl;

uint16_t cce = 0;
cce = readbin(cce, sas, swapit);
cce = readbin(cce, sas, swapit); // count of bytes in the binary reference expression
break;
}

case PtgMemErr:
case PtgMemErr2:
case PtgMemErr3:
{
if (debug) Rcpp::Rcout << "PtgMemErr" <<std::endl;

uint8_t unused1 = 0;
uint16_t unused2 = 0, cce = 0;

// Error txt is already in the value field
// fml_out += BErr(sas, swapit);
// fml_out += "\n";

std::string err_str = "";
err_str = BErr(sas, swapit);

if (debug) Rcpp::Rcout << "PtgMemErr: " << err_str << std::endl;

unused1 = readbin(unused1, sas, swapit);
unused2 = readbin(unused2, sas, swapit);
cce = readbin(cce, sas, swapit); // count of bytes in the binary reference expression

break;
}

case PtgMemNoMem:
case PtgMemNoMem2:
case PtgMemNoMem3:
{
if (debug) Rcpp::Rcout << "PtgMemNoMem" <<std::endl;

uint32_t unused = 0;
unused = readbin(unused, sas, swapit);

uint16_t cce = 0;
cce = readbin(cce, sas, swapit); // count of bytes in the binary reference expression

break;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-read_xlsb.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,17 @@ test_that("worksheets with real world formulas", {
expect_equal(exp, got)

})

test_that("xlsb formulas", {

fl <- testfile_path("formula_checks.xlsb")
wb <- wb_load(fl)

exp <- c("", "D2:E2", "A1,B1", "A1 A2", "1+1", "1-1", "1*1", "1/1",
"1%", "1^1", "1=1", "1&gt;1", "1&gt;=1", "1&lt;1", "1&lt;=1",
"1&lt;&gt;1", "+A3", "-R2", "(1)", "SUM(1, )", "1", "2.500000",
"\"a\"", "\"A\"&amp;\"B\"")
got <- unique(wb$worksheets[[1]]$sheet_data$cc$f)
expect_equal(exp, got)

})

0 comments on commit ea27595

Please sign in to comment.