Skip to content

Commit

Permalink
Extract sheet names
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Mar 16, 2015
1 parent 9530301 commit 6def875
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ xls_formats <- function(path) {
.Call('exell_xls_formats', PACKAGE = 'exell', path)
}

xls_sheets <- function(path) {
.Call('exell_xls_sheets', PACKAGE = 'exell', path)
}

11 changes: 11 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ BEGIN_RCPP
return __result;
END_RCPP
}
// xls_sheets
std::vector<std::string> xls_sheets(std::string path);
RcppExport SEXP exell_xls_sheets(SEXP pathSEXP) {
BEGIN_RCPP
Rcpp::RObject __result;
Rcpp::RNGScope __rngScope;
Rcpp::traits::input_parameter< std::string >::type path(pathSEXP);
__result = Rcpp::wrap(xls_sheets(path));
return __result;
END_RCPP
}
23 changes: 23 additions & 0 deletions src/h-xls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,26 @@ bool is_datetime(int id, formatMap formats) {
return false;
}


// [[Rcpp::export]]
std::vector<std::string> xls_sheets(std::string path) {
xls::xlsWorkBook* pWB = xls::xls_open(path.c_str(), "UTF8");

if (pWB == NULL)
Rcpp::stop("Failed to open %s", path);

int n = pWB->sheets.count;

std::vector<std::string> sheets;
sheets.reserve(n);

for (int i = 0; i < n; ++i) {
std::string name((char*) pWB->sheets.sheet[i].name);
sheets.push_back(name);
}

// Cleanup
xls_close(pWB);

return sheets;
}

0 comments on commit 6def875

Please sign in to comment.