cell: General cell

Description Usage Arguments Details Value See Also Examples

Description

Creates a general cell.

Usage

1
2
3
cell(col, row, value, colspan = NULL, rowspan = NULL, comment = NULL,
  commentAuthor = NULL, numberFormat = NULL, fontname = NULL,
  bold = NULL, color = NULL, fill = NULL)

Arguments

col

integer, the column index

row

integer, the row index

value

cell value, a numeric or character scalar

colspan

integer, number of columns the cell spans

rowspan

integer, number of rows the cell spans

comment

cell comment, character

commentAuthor

author of the comment, character

numberFormat

number format; see Details

fontname

font name; see Details

bold

set TRUE for bold font

color

color name; see Details

fill

color name; see Details

Details

The number format can be a predefined format or a custom format, such as "yyyy-mm-dd;@". Predefined number formats are illustrated in the examples. The font name must be a name available in Excel, such as "Courier" or "Verdana". The color name must be a name among the ones returned by grDevices::colors(); see the example of json2xlsx or hwriteXLSX.

Value

A named list representing a cell.

See Also

cellDate to create a cell for a date.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
A1 <- cell(1, 1, 9.9, numberFormat="2Decimal")
B3 <- cell(2, 3, "abc", bold=TRUE, color="red", comment="this cell is red")
sheet <- list(Sheet1 = c(A1, B3))
# JSON string ready for json2xlsx
json <- jsonlite::toJSON(sheet, null="null", auto_unbox = TRUE)
json2xlsx(json, outfile="xlsx.xlsx")
# predefined number formats
numericFormats <-
  c(
    "General",
    "Zero",
    "2Decimal",
    "Max3Decimal",
    "ThousandSeparator2Decimal",
    "Percent",
    "Percent2Decimal",
    "Exponent2Decimal",
    "SingleSpacedFraction",
    "DoubleSpacedFraction",
    "ThousandsNegativeParens",
    "ThousandsNegativeRed",
    "Thousands2DecimalNegativeParens",
    "Tousands2DecimalNEgativeRed",
    "Exponent1Decimal",
    "TextPlaceHolder"
  )
dateFormats <-
  c(
    "MmSs",
    "OptHMmSs",
    "MmSs1Decimal",
    "MmDdYy",
    "DMmmYy",
    "DMmm",
    "MmmYy",
    "HMm12Hr",
    "HMmSs12Hr",
    "HMm",
    "HMmSs",
    "MdyHMm"
  )
A <- lapply(seq_along(numericFormats),
            function(i) cell(1, i, value=numericFormats[i]))
B <- lapply(seq_along(numericFormats),
            function(i) cell(2, i, value=-9999.1234,
                             numberFormat=numericFormats[i]))
sheet1 <- list(numericFormats = do.call(c, c(A,B)))
A <- lapply(seq_along(dateFormats),
            function(i) cell(1, i, value=dateFormats[i]))
B <- lapply(seq_along(dateFormats),
            function(i) cell(2, i, value=10000,
                             numberFormat=dateFormats[i]))
sheet2 <- list(dateFormats = do.call(c, c(A,B)))
json <- jsonlite::toJSON(c(sheet1, sheet2), null="null", auto_unbox = TRUE)
json2xlsx(json, outfile="numberFormats.xlsx")

stla/hwriteXLSX documentation built on May 7, 2019, 10:40 a.m.