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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
| import org.apache.poi.hssf.usermodel.*
import org.apache.poi.poifs.filesystem.*
class Extentions {
static init = {
File.metaClass.lostFiles = { newdir ->
def thislist = []
def olddir = delegate
olddir.eachFileRecurse { thislist << it.path }
def newlist = []
newdir.eachFileRecurse { newlist << it.path }
newlist = newlist.collect {
it.replace(newdir.path, "")
}
thislist.findAll {
!newlist.contains(it.replace(olddir.path, ""))
}
}
File.metaClass.listEmptyDirs = {
def list = []
delegate.eachFileRecurse {
if (it.isDirectory() && it.listFiles().size() == 0) {
list << it
}
}
list
}
String.metaClass.padRightBytes = { count ->
delegate.padRight(count - (delegate.bytes.size() - delegate.size()))
}
String.metaClass.padLeftBytes = { count ->
delegate.padLeft(count - (delegate.bytes.size() - delegate.size()))
}
String.metaClass.toNarrowCase = {
def wideChars = ('A'..'Z') + ('a'..'z') + ('0'..'9') + (['?', 'ー', '*', '=', '!', '”', '$', '%', '&', '(', ')'])
def narrowChars = ('A'..'Z') + ('A'..'Z') + ('0'..'9') + (['-', 'ー', '*', '=', '!', '"', '$', '%', '&', '(', ')'])
assert wideChars.size() == narrowChars.size()
def text = delegate.toString()
for (i in 0..wideChars.size() - 1) {
text = text.replace(wideChars[i], narrowChars[i])
}
text
}
String.metaClass.toWideCase = {
def wideChars = ('A'..'Z') + ('a'..'z') + ('0'..'9') + (['?', 'ー', '*', '=', '!', '”', '$', '%', '&', '(', ')'])
def narrowChars = ('A'..'Z') + ('A'..'Z') + ('0'..'9') + (['-', 'ー', '*', '=', '!', '"', '$', '%', '&', '(', ')'])
assert wideChars.size() == narrowChars.size()
def text = delegate.toString()
for (i in 0..narrowChars.size() - 1) {
text = text.replace(narrowChars[i], wideChars[i])
}
text
}
HSSFWorkbook.metaClass.'static'.load = { file ->
new HSSFWorkbook(new POIFSFileSystem(new FileInputStream(file.path)));
}
HSSFWorkbook.metaClass.getSheets = {
def list = []
for (i in 0..delegate.getNumberOfSheets() - 1) {
def sheet = delegate.getSheetAt(i)
sheet.metaClass.parent = delegate
list << sheet
}
list
}
org.apache.poi.hssf.usermodel.HSSFSheet.metaClass.cell = {
row, col -> delegate.getRow(row)?.getCell((short) col)
}
org.apache.poi.hssf.usermodel.HSSFSheet.metaClass.cellValue = { row, col ->
def result = 0
//assert delegate.getRow(row):"行${row}がnullです。"
def cell = delegate.getRow(row)?.getCell((short) col)
switch (cell?.cellType) {
case org.apache.poi.hssf.usermodel.HSSFCell.CELL_TYPE_NUMERIC:
result = cell?.numericCellValue
break;
case org.apache.poi.hssf.usermodel.HSSFCell.CELL_TYPE_STRING:
result = cell?.stringCellValue
break;
case org.apache.poi.hssf.usermodel.HSSFCell.CELL_TYPE_BOOLEAN:
result = cell?.booleanCellValue
break;
case org.apache.poi.hssf.usermodel.HSSFCell.CELL_TYPE_FORMULA:
result = cell?.cellFormula
break;
default:
//assert false:"${row}, ${col}が不正"
result = null
break;
}
result
}
java.util.PropertyResourceBundle.metaClass.'static'.load = { file ->
new java.util.PropertyResourceBundle(new java.io.FileInputStream(file))
}
java.util.PropertyResourceBundle.metaClass.'static'.loadProject = {
java.util.PropertyResourceBundle.load(new File("project-ascii.properties"))
}
}
}
|