Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / text / ExcelDir2XMLMacro.groovy @ 2051

History | View | Annotate | Download (2.6 kB)

1
package org.txm.macro.text
2

    
3
import org.kohsuke.args4j.*
4
import groovy.transform.Field
5
import java.nio.charset.Charset
6
import org.txm.rcpapplication.swt.widget.parameters.*
7
import org.txm.utils.*
8
import javax.xml.stream.*
9
import java.net.URL
10

    
11
import org.apache.poi.ss.usermodel.*
12
import org.apache.poi.hssf.usermodel.*
13
import org.apache.poi.xssf.usermodel.*
14
import org.apache.poi.ss.util.*
15

    
16
@Field @Option(name="inputDirectory", usage="répertoire des fichiers Excel à traiter", widget="Folder", required=true, def="")
17
def inputDirectory
18

    
19
@Field @Option(name="sheetName", usage="sheet name (if no name is given the first sheet will be used)", widget="String", required=false, def="")
20
def sheetName
21

    
22
@Field @Option(name="rootTag", usage="Root tag name", widget="String", required=false, def="root")
23
def rootTag
24

    
25
@Field @Option(name="textTag", usage="Text tag name", widget="String", required=false, def="unit")
26
def textTag
27

    
28
@Field @Option(name="metadataColumnList", usage="metadataColumnList column list separated with comma", widget="String", required=false, def="meta1,meta2")
29
def metadataColumnList
30

    
31
@Field @Option(name="dateColumnList", usage="date columns list separated by comma", widget="String", required=false, def="meta1,meta2")
32
def dateColumnList
33

    
34
@Field @Option(name="textColumnList", usage="textColumnList column list separated with comma", widget="String", required=false, def="textColumnList1,textColumnList2")
35
def textColumnList
36

    
37
if (!ParametersDialog.open(this)) return
38

    
39
if (!inputDirectory.exists()) {
40
        println "** ExcelDir2XML: no '"+inputDirectory.name+"' directory found. Aborting."
41
        return false
42
}
43

    
44
if (!inputDirectory.canRead()) {
45
        println "** ExcelDir2XML: '"+inputDirectory.name+"' directory not readable. Aborting."
46
        return false
47
}
48

    
49
def f = []
50
inputDirectory.eachFileMatch(~/.*xlsx/) { f << it }
51

    
52
if (f.size() == 0) {
53
        println "** ExcelDir2XML: no .xlsx file found. Aborting."
54
        return false
55
}
56

    
57
try {
58

    
59
f.sort { it.name }.each { inputFile ->
60

    
61
        res = gse.run(Excel2XMLMacro, ["args":[
62

    
63
"inputFile":inputFile,
64
"sheetName":sheetName,
65
"metadataColumnList":metadataColumnList,
66
"dateColumnList":dateColumnList,
67
"textColumnList":textColumnList,
68
"rootTag":rootTag,
69
"textTag":textTag,
70
                        
71
                                "selection":selection,
72
                                "selections":selections,
73
                                "corpusViewSelection":corpusViewSelection,
74
                                "corpusViewSelections":corpusViewSelections,
75
                                "monitor":monitor]])
76
                        if (!res) println "** problem calling Excel2XMLMacro."
77
}
78

    
79
} catch (Exception e) {
80
        println "** ExcelDir2XML: unable to read input files. Aborting."
81
        println e.getLocalizedMessage()
82
        println e.printStackTrace()
83
        return false
84
}
85

    
86
return true