setCellFormula-methods(XLConnect)
setCellFormula-methods()所属R语言包:XLConnect
Setting cell formulas
设置单元格的公式
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Sets cell formulas for specific cells in a workbook.
设置单元格公式为特定的单元在workbook。
用法----------Usage----------
## S4 method for signature 'workbook,character'
setCellFormula(object,sheet,row,col,formula)
## S4 method for signature 'workbook,numeric'
setCellFormula(object,sheet,row,col,formula)
参数----------Arguments----------
参数:object
The workbook to use
workbook使用
参数:sheet
Name or index of the sheet the cell is on
在片材的名称或索引的单元是
参数:row
Row index of the cell to edit
的单元格的行索引编辑
参数:col
Column index of the cell to edit
的单元格的列索引编辑
参数:formula
The formula to apply to the cell, without the initial = character used in Excel
在Excel中使用公式来套用到小区,没有最初的=字符
Details
详细信息----------Details----------
Note that the arguments are vectorized such that multiple cells can be set with one method call.
注意的参数矢量,使得可以设置多个单元格的一个方法调用。
(作者)----------Author(s)----------
Martin Studer<br>
Mirai Solutions GmbH <a href="http://www.mirai-solutions.com">http://www.mirai-solutions.com</a>
参见----------See Also----------
workbook, getCellFormula,
workbook,getCellFormula,
实例----------Examples----------
# Load workbook (create if not existing)[负载工作簿(如果不存在创建)]
wb <- loadWorkbook("setCellFormula.xls", create = TRUE)
# Create a sheet named 'mtcars'[创建一张名为“mtcars”]
createSheet(wb, name = "mtcars")
# Create a named region called 'mtcars' referring to the sheet[创建一个命名区域被称为“mtcars”指的是纸张]
# called 'mtcars'[被称为“mtcars”]
createName(wb, name = "mtcars", formula = "mtcars!$A$1")
# Write built-in data set 'mtcars' to the above defined named region.[写内置的数据集mtcars上述定义的命名区域。]
writeNamedRegion(wb, mtcars, name = "mtcars")
# Now, let us get Excel to calculate average weights.[现在,让我们让Excel计算平均体重。]
# Where did we write the dataset?[我们写的数据集在哪里?]
corners <- getReferenceCoordinates(wb, "mtcars")
# Put the average under the wt column[的重量将平均在列]
colIndex <- which(names(mtcars) == "wt")
rowIndex <- corners[2,1] + 1
# Construct the input range & formula[构建的输入范围和公式]
input <- paste(idx2cref(c(corners[1,1], colIndex,
corners[2,1], colIndex)), collapse=":")
formula <- paste("AVERAGE(", input, ")", sep="")
setCellFormula(wb, "mtcars", rowIndex, colIndex, formula)
# Save workbook (this actually writes the file to disk)[保存工作簿(这实际上是将文件写入到磁盘)]
saveWorkbook(wb)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|