createCellStyle-methods(XLConnect)
createCellStyle-methods()所属R语言包:XLConnect
Creating custom named and anonymous cell styles
创建自定义的命名和匿名的单元格样式
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Creates a custom named or anonymous cellstyle.
创建一个自定义命名或匿名cellstyle。
用法----------Usage----------
## S4 method for signature 'workbook,character'
createCellStyle(object,name)
参数----------Arguments----------
参数:object
The workbook to use
workbook使用
参数:name
The name of the new cellstyle to create. Omit to create an anonymous cellstyle.
新的cellstyle创建的名称。省略创建一个匿名cellstyle。
Details
详细信息----------Details----------
Creates a named cellstyle with the specified name. Named cell styles may be used in conjunction with the name prefix style action (see setStyleAction) or may also be used directly with the method setCellStyle. Named cell styles can easily be changed from within Excel using the cell styles menu.
创建一个名为cellstyle指定的name。提及的单元格样式可以使用一并以名称前缀式动作(见setStyleAction)或可能也可以直接使用的方法setCellStyle。可以很容易地改变命名的单元格样式在Excel中的单元格样式菜单。
If name is missing, an anonymous cell style is created. Anonymous cell styles can be used in conjunction with the setCellStyle method.
name如果丢失,创建一个匿名的单元格样式。匿名单元格样式,可以使用结合与setCellStyle的方法。
(作者)----------Author(s)----------
Martin Studer<br>
Mirai Solutions GmbH <a href="http://www.mirai-solutions.com">http://www.mirai-solutions.com</a>
参见----------See Also----------
workbook, cellstyle, setStyleAction, setStyleNamePrefix, setCellStyle, setDataFormat, setBorder, setFillBackgroundColor, setFillForegroundColor, setFillPattern, setWrapText
workbook,cellstyle,setStyleAction,setStyleNamePrefix,setCellStyle,setDataFormat,setBorder,setFillBackgroundColor,setFillForegroundColor,setFillPattern,setWrapText
实例----------Examples----------
# Load workbook (create if not existing)[负载工作簿(如果不存在创建)]
wb <- loadWorkbook("createCellstyles.xlsx", create = TRUE)
# We don't set a specific style action in this demo, so the [我们在本演示中没有设置特定风格的动作,所以]
# default 'XLConnect' will be used (XLC$"STYLE_ACTION.XLCONNECT")[将用于默认的“XLConnect”,(XLC的“STYLE_ACTION.XLCONNECT”)]
# 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!$C$4")
# Write built-in data set 'mtcars' to the above defined named region.[写内置的数据集mtcars上述定义的命名区域。]
# This will use the default style action 'XLConnect'.[这将使用默认的样式的行动“XLConnect”。]
writeNamedRegion(wb, mtcars, name = "mtcars")
# Now let's color all weight cells of cars with a weight > 3.5 in red[现在,让我们所有汽车的重量单元的颜色为红色,重量> 3.5]
# (mtcars$wt > 3.5)[(mtcars重量> 3.5)]
# First, create a corresponding (named) cell style[首先,创建一个对应的单元格样式(命名)]
heavyCar <- createCellStyle(wb, name = "HeavyCar")
# Specify the cell style to use a solid foreground color[指定的单元格样式,使用了坚实的前景色]
setFillPattern(heavyCar, fill = XLC$"FILL.SOLID_FOREGROUND")
# Specify the foreground color to be used[指定要使用的前景色]
setFillForegroundColor(heavyCar, color = XLC$"COLOR.RED")
# Which cars have a weight > 3.5 ?[该款车的重量> 3.5?]
rowIndex <- which(mtcars$wt > 3.5)
# NOTE: The mtcars data.frame has been written offset with [注意:mtcars的数据框已被写入偏移]
# top left cell C4 - and we have also written a header row![左上角的单元格C4 - 我们已经写了一个标题行!]
# So, let's take that into account appropriately. Obviously, [所以,让我们适当考虑到这一点。很显然,]
# the two steps could be combined directly into one ...[两个步骤可以被组合成一个直接...]
rowIndex <- rowIndex + 4
# The same holds for the column index[面临着同样的列索引]
colIndex <- which(names(mtcars) == "wt") + 2
# Set the 'HeavyCar' cell style for the corresponding cells.[设置“HeavyCar相应的单元格的单元格样式。]
# Note: the row and col arguments are vectorized![注:ROW和COL参数量化的!]
setCellStyle(wb, sheet = "mtcars", row = rowIndex, col = colIndex,
cellstyle = heavyCar)
# Save workbook (this actually writes the file to disk)[保存工作簿(这实际上是将文件写入到磁盘)]
saveWorkbook(wb)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|