-
Notifications
You must be signed in to change notification settings - Fork 1
/
SummaryTableFile.R
76 lines (64 loc) · 2.44 KB
/
SummaryTableFile.R
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require("plyr")
SummaryTableFile <- setClass("SummaryTableFile",
contains = "FileOut"
)
setGeneric(name = "ColumnsValuesSummaryTable",
def = function(theObject, myfile, only)
{
standardGeneric("ColumnsValuesSummaryTable")
}
)
setMethod(f = "ColumnsValuesSummaryTable",
signature = "SummaryTableFile",
definition = function(theObject, myfile, only)
{
#theObject@table_out[1, ] <- c("Only first ten values", rep(NA, ncol(10)-1))
table_in_names <- colnames(myfile@table_in)
for (i in 1:ncol(myfile@table_in))
{
tmp <- table(myfile@table_in[[i]])
unique_sum <- length(tmp)
tmp <- as.data.frame(tmp)
tmp <- t.data.frame(tmp)
tmp <- as.data.frame.matrix(tmp, stringsAsFactors = FALSE)
if (unique_sum > only) tmp <- tmp[,1:only]
theObject@table_out <- rbind.fill(theObject@table_out,tmp)
}
for(j in 1:length(table_in_names))
{
for (i in seq(1, nrow(theObject@table_out) + length(table_in_names), by = 3))
{
#print(theObject@table_out[seq(i+1,nrow(theObject@table_out)+1),])
theObject@table_out[seq(i + 1,nrow(theObject@table_out) + 1), ] <- theObject@table_out[seq(i,nrow(theObject@table_out)), ]
theObject@table_out[i,] <- c(table_in_names[j], rep(NA, ncol(theObject@table_out) - 1))
j <- j + 1
}
break
}
theObject <- CreateExcelWB(theObject, colnames = FALSE, startRow = 1)
ALL_CELLS_STYLE <- CellStyle(theObject@wb) +
Border(position = c("BOTTOM", "LEFT", "TOP", "RIGHT")) +
Alignment(wrapText = TRUE, horizontal = "ALIGN_CENTER")
TITLE_STYLE <- ALL_CELLS_STYLE +
Font(theObject@wb, isBold = TRUE)
allrows <- getRows(theObject@sheet, rowIndex = 1:nrow(theObject@table_out))
allcells <- getCells(allrows, colIndex = 1:ncol(theObject@table_out))
title_rows <- allrows[seq(1, length(allrows), 3)]
title_cells <- getCells(title_rows, colIndex = 1:ncol(theObject@table_out))
for (i in 1:length(allcells))
{
setCellStyle(allcells[[i]], ALL_CELLS_STYLE)
}
#addMergedRegion(theObject@sheet, 1, 1, 1, 10)
for (i in seq(1, nrow(theObject@table_out), 3))
{
addMergedRegion(theObject@sheet, i, i, 1, 10)
}
for(i in 1:length(title_cells))
{
setCellStyle(title_cells[[i]], TITLE_STYLE)
}
theObject <- SaveExcelWB(theObject)
return(theObject)
}
)