R Openxlsx多次验证会损坏输出文件
我正在尝试添加多个验证,并将公式添加到excel文件中。以下是我使用的代码:R Openxlsx多次验证会损坏输出文件,r,R,我正在尝试添加多个验证,并将公式添加到excel文件中。以下是我使用的代码: library(openxlsx) fileTemplate <- 'New01.xlsx' wbTemplate <- loadWorkbook(fileTemplate) addWorksheet(wbTemplate, "Sheet1") writeData(wbTemplate, "Sheet1", dataset) len <- NROW(dataset) dataValidation(wb
library(openxlsx)
fileTemplate <- 'New01.xlsx'
wbTemplate <- loadWorkbook(fileTemplate)
addWorksheet(wbTemplate, "Sheet1")
writeData(wbTemplate, "Sheet1", dataset)
len <- NROW(dataset)
dataValidation(wbTemplate, 2, col = 2, rows = 2:len, type = "list", value = "'Data Validation'!$A$2:$A$19")
dataValidation(wbTemplate, 2, col = 3, rows = 2:len, type = "list", value = "'Data Validation'!$B$2:$B$501")
dataValidation(wbTemplate, 2, col = 5, rows = 2:len, type = "list", value = "'Data Validation'!$C$2:$C$6")
openXL(wbTemplate)
库(openxlsx)
fileTemplate不幸的是,这看起来像是在中发现的错误
幸运的是。使用,您无需卸下和重新安装的CRAN版本即可安装该版本
#安装devtools包
安装程序包(pkgs=“devtools”)
#加载必要的包
图书馆(devtools)
#创建用于存储已安装软件包的新库。
开发模式(开=真)
#下载修复的PR请求
#数据验证错误
安装github(repo=“tkunstek/openxlsx”)
#加载库
库(openxlsx)
#创建工作簿
wb有一个开发版的openxlsx
解决了这个问题。有关如何将其导入的信息,请参见下文。感谢您提供的解决方案。我现在正在尝试,它抱怨:d>安装github(repo=“tkunstek/openxlsx”)下载github repo tkunstek/openxlsx@master从URL安装失败:找不到生成openxlsx d>所需的生成工具。。。。建议的解决方案似乎是安装Rtools,但它不适用于我,因为我在Mac上……好的,在安装fortran和xcode select——安装之后,我能够安装_github(repo=“tkunstek/openxlsx”)。但是现在我在.Call(“openxlsx_convert_to_excel_ref”、PACKAGE=“openxlsx”、:“openxlsx_convert_to_excel_ref”包的.Call()中出现了这个错误:d>dataValidation(wbTemplate,2,col=2,rows=2:len,type=“list”,value=“'Data Validation'!$A$2:$A$19”)@user1298416我在您的值参数中看到,您正在显式键入“'Data Validation'$A$2:$A$19”。根据,type=“list”
要求显式引用值参数内表参数中提供的表名。请改为尝试:值=“'Sheet1'$A$2:$A$19”
。最后的结果是什么-首先,我运行常规openxlsx对我的文件进行修改,输出并保存文件,然后使用aspiringurbandatascientist建议的代码(打开文件,进行验证,保存文件)。使用install\u github(“YPHS/openxlsx”)
它实际上对我有效!单元格引用很奇怪,它对我有效的格式有以下两种:工作表!$A$1:$A$2
和“工作表”!$A$1:$A$2
# install the devtools package
install.packages( pkgs = "devtools" )
# load necessary packages
library( devtools )
# create a new library for storing installed packages.
dev_mode(on = TRUE )
# download the PR request that fixes
# the dataValidation error
install_github( repo = "tkunstek/openxlsx" )
# load the library
library( openxlsx )
# create workbook
wb <- createWorkbook()
# initialize worksheet
addWorksheet( wb = wb, sheetName = "Sheet1" )
# add iris to Sheet1
writeData( wb = wb
, sheet = "Sheet1"
, x = iris
)
# add Excel data validation to cells
dataValidation( wb = wb
, sheet = "Sheet1"
, cols = 1:4
, rows = 2:( 1 + nrow( iris ) )
, type = "decimal"
, operator = "between"
, value = c( 0, 10 )
)
dataValidation( wb = wb
, sheet = "Sheet1"
, cols = 5
, rows = 2:( 1 + nrow( iris ) )
, type = "textLength"
, operator = "lessThanOrEqual"
, value = 10
)
# view the data in Excel
# notice that the file is no longer corrupt
openXL( file = wb )
# turn off dev_mode
dev_mode( on = FALSE ) # return to CRAN version of openxlsx
# end of script