Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #266, credit to EagleR17 #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ buildCellList <- function(r, t, v) {
.Call(`_openxlsx_buildCellList`, r, t, v)
}

write_worksheet_xml_2 <- function(prior, post, sheet_data, row_heights, R_fileName) {
.Call(`_openxlsx_write_worksheet_xml_2`, prior, post, sheet_data, row_heights, R_fileName)
}

write_worksheet_xml <- function(prior, post, sheet_data, R_fileName) {
.Call(`_openxlsx_write_worksheet_xml`, prior, post, sheet_data, R_fileName)
}
Expand All @@ -133,7 +137,3 @@ build_table_xml <- function(table, tableStyleXML, ref, colNames, showColNames, w
.Call(`_openxlsx_build_table_xml`, table, tableStyleXML, ref, colNames, showColNames, withFilter)
}

write_worksheet_xml_2 <- function(prior, post, sheet_data, row_heights, R_fileName) {
.Call(`_openxlsx_write_worksheet_xml_2`, prior, post, sheet_data, row_heights, R_fileName)
}

35 changes: 13 additions & 22 deletions R/WorkbookClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -1514,33 +1514,24 @@ Workbook$methods(dataValidation = function(sheet, startRow, endRow, startCol, en



Workbook$methods(dataValidation_list = function(sheet, startRow, endRow, startCol, endCol, value, allowBlank, showInputMsg, showErrorMsg){

sheet = validateSheet(sheet)
sqref <- paste(getCellRefs(data.frame("x" = c(startRow, endRow), "y" = c(startCol, endCol))), collapse = ":")

header <- '<ext uri="{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main">
<x14:dataValidations count="1" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">'

data_val <- sprintf('<x14:dataValidation type="list" allowBlank="%s" showInputMessage="%s" showErrorMessage="%s">',
allowBlank, showInputMsg, showErrorMsg, sqref)

formula <- sprintf("<x14:formula1><xm:f>%s</xm:f></x14:formula1>", value)
sqref <- sprintf('<xm:sqref>%s</xm:sqref>', sqref)

xml <- paste0(header, data_val, formula, sqref, '</x14:dataValidation></x14:dataValidations></ext>')

worksheets[[sheet]]$extLst <<- c(worksheets[[sheet]]$extLst, xml)

invisible(0)
Workbook$methods(dataValidation_list = function(sheet, startRow, endRow, startCol, endCol, value, allowBlank, showInputMsg, showErrorMsg) {

sheet = validateSheet(sheet)
sqref <-paste(getCellRefs(data.frame("x" = c(startRow, endRow), "y" = c(startCol, endCol))), collapse = ":")
data_val <- sprintf('<x14:dataValidation type="list" allowBlank="%s" showInputMessage="%s" showErrorMessage="%s">',allowBlank,showInputMsg, showErrorMsg, sqref)

formula <- sprintf("<x14:formula1><xm:f>%s</xm:f></x14:formula1>", value)
sqref <- sprintf('<xm:sqref>%s</xm:sqref>', sqref)

xmlData <-paste0(data_val, formula, sqref, '</x14:dataValidation>')

worksheets[[sheet]]$extLst <<- c(worksheets[[sheet]]$extLst, xmlData)

invisible(0)
})






Workbook$methods(conditionalFormatting = function(sheet, startRow, endRow, startCol, endCol, dxfId, formula, type, values, params){

sheet = validateSheet(sheet)
Expand Down
11 changes: 6 additions & 5 deletions R/worksheet_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,13 @@ WorkSheet$methods(get_post_sheet_data = function(){
}


if(length(extLst) > 0)
xml <- paste0(xml, sprintf('<extLst>%s</extLst>', paste(extLst, collapse = "")), collapse = "")


if(length(extLst) > 0)
xml <- paste0(xml
, sprintf('<extLst><ext uri="{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"><x14:dataValidations count="%s" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">'
, length(extLst))
, paste0(pxml(extLst), '</x14:dataValidations></ext></extLst>'), collapse = "")

xml <- paste0(xml, "</worksheet>")
xml <- paste0(xml, "</worksheet>")

return(xml)

Expand Down
32 changes: 16 additions & 16 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,21 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// write_worksheet_xml_2
SEXP write_worksheet_xml_2(std::string prior, std::string post, Reference sheet_data, CharacterVector row_heights, std::string R_fileName);
RcppExport SEXP _openxlsx_write_worksheet_xml_2(SEXP priorSEXP, SEXP postSEXP, SEXP sheet_dataSEXP, SEXP row_heightsSEXP, SEXP R_fileNameSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< std::string >::type prior(priorSEXP);
Rcpp::traits::input_parameter< std::string >::type post(postSEXP);
Rcpp::traits::input_parameter< Reference >::type sheet_data(sheet_dataSEXP);
Rcpp::traits::input_parameter< CharacterVector >::type row_heights(row_heightsSEXP);
Rcpp::traits::input_parameter< std::string >::type R_fileName(R_fileNameSEXP);
rcpp_result_gen = Rcpp::wrap(write_worksheet_xml_2(prior, post, sheet_data, row_heights, R_fileName));
return rcpp_result_gen;
END_RCPP
}
// write_worksheet_xml
SEXP write_worksheet_xml(std::string prior, std::string post, Reference sheet_data, std::string R_fileName);
RcppExport SEXP _openxlsx_write_worksheet_xml(SEXP priorSEXP, SEXP postSEXP, SEXP sheet_dataSEXP, SEXP R_fileNameSEXP) {
Expand Down Expand Up @@ -428,21 +443,6 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// write_worksheet_xml_2
SEXP write_worksheet_xml_2(std::string prior, std::string post, Reference sheet_data, CharacterVector row_heights, std::string R_fileName);
RcppExport SEXP _openxlsx_write_worksheet_xml_2(SEXP priorSEXP, SEXP postSEXP, SEXP sheet_dataSEXP, SEXP row_heightsSEXP, SEXP R_fileNameSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< std::string >::type prior(priorSEXP);
Rcpp::traits::input_parameter< std::string >::type post(postSEXP);
Rcpp::traits::input_parameter< Reference >::type sheet_data(sheet_dataSEXP);
Rcpp::traits::input_parameter< CharacterVector >::type row_heights(row_heightsSEXP);
Rcpp::traits::input_parameter< std::string >::type R_fileName(R_fileNameSEXP);
rcpp_result_gen = Rcpp::wrap(write_worksheet_xml_2(prior, post, sheet_data, row_heights, R_fileName));
return rcpp_result_gen;
END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_openxlsx_calc_column_widths", (DL_FUNC) &_openxlsx_calc_column_widths, 7},
Expand Down Expand Up @@ -473,12 +473,12 @@ static const R_CallMethodDef CallEntries[] = {
{"_openxlsx_buildCellTypes", (DL_FUNC) &_openxlsx_buildCellTypes, 2},
{"_openxlsx_build_cell_merges", (DL_FUNC) &_openxlsx_build_cell_merges, 1},
{"_openxlsx_buildCellList", (DL_FUNC) &_openxlsx_buildCellList, 3},
{"_openxlsx_write_worksheet_xml_2", (DL_FUNC) &_openxlsx_write_worksheet_xml_2, 5},
{"_openxlsx_write_worksheet_xml", (DL_FUNC) &_openxlsx_write_worksheet_xml, 4},
{"_openxlsx_buildMatrixNumeric", (DL_FUNC) &_openxlsx_buildMatrixNumeric, 6},
{"_openxlsx_buildMatrixMixed", (DL_FUNC) &_openxlsx_buildMatrixMixed, 8},
{"_openxlsx_matrixRowInds", (DL_FUNC) &_openxlsx_matrixRowInds, 1},
{"_openxlsx_build_table_xml", (DL_FUNC) &_openxlsx_build_table_xml, 6},
{"_openxlsx_write_worksheet_xml_2", (DL_FUNC) &_openxlsx_write_worksheet_xml_2, 5},
{NULL, NULL, 0}
};

Expand Down