forked from SophieKoshkareva/RParserForTable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableInColumnsForExcel.R
68 lines (61 loc) · 1.86 KB
/
TableInColumnsForExcel.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
c <- data.frame()
data.frame.names <- colnames(file_in@table_in)
for (i in 1:ncol(file_in@table_in))
{
a <- table(file_in@table_in[[i]])
unique_sum <- length(a)
a <- as.data.frame(a)
a <- t.data.frame(a)
a <- as.data.frame.matrix(a, stringsAsFactors = FALSE)
if (unique_sum > 10) a <- a[,1:10]
c <- rbind.fill(c,a)
}
c[1,] <- c("Only first ten values", rep(NA, ncol(c)-1))
for(j in 1:length(data.frame.names))
{
for (i in seq(2, nrow(c) + length(data.frame.names), by=3))
{
#print(c[seq(i+1,nrow(c)+1),])
c[seq(i + 1,nrow(c) + 1),] <- c[seq(i,nrow(c)),]
c[i,] <- c(data.frame.names[j], rep(NA, ncol(c) - 1))
j <- j + 1
}
break
}
for(i in 1:ncol(c))
{
ind <- which(grepl("^(\\d)+([,.](\\d)+)?$", c[[i]]), arr.ind = T, useNames = F)
c[[i]] <- gsub("[,]|[-/]", ".", c[[i]])
c[[i]][ind]<- as.numeric(c[[i]][ind])
}
require("xlsx")
wb <- createWorkbook(type = "xlsx")
sheet <- createSheet(wb, "sheet1")
ALL_CELLS_STYLE <- CellStyle(wb) +
Border(position = c("BOTTOM", "LEFT", "TOP", "RIGHT")) +
Alignment(wrapText = TRUE, horizontal = "ALIGN_CENTER")
TITLE_STYLE <- ALL_CELLS_STYLE +
Font(wb, isBold = TRUE)
addDataFrame(c,
sheet,
row.names = FALSE,
startRow = 1,
startColumn = 1, col.names = FALSE)
allrows <- getRows(sheet, rowIndex = 1:nrow(c))
allcells <- getCells(allrows, colIndex = 1:ncol(c))
title_rows <- allrows[seq(1, length(allrows), 3)]
title_cells <- getCells(title_rows, colIndex = 1:ncol(c))
for (i in 1:length(allcells))
{
setCellStyle(allcells[[i]], ALL_CELLS_STYLE)
}
for (i in seq(1, nrow(c), 3))
{
addMergedRegion(sheet, i, i, 1, 10)
}
for(i in 1:length(title_cells))
{
setCellStyle(title_cells[[i]], TITLE_STYLE)
}
autoSizeColumn(sheet, colIndex = c(1:ncol(c)))
saveWorkbook(wb, "D:/Diploma/r_project/1.xlsx" )