Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / table / ExcelDir2XMLMacro.groovy @ 3058

History | View | Annotate | Download (2.8 kB)

1
package org.txm.macro.table
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.usermodel.WorkbookFactory
15
import org.apache.poi.ss.util.*
16

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

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

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

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

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

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

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

    
38
@Field @Option(name="EmbedInTEI", usage="text columns list separated by comma", widget="Boolean", required=false, def="false")
39
def EmbedInTEI
40

    
41
if (!ParametersDialog.open(this)) return
42

    
43
if (!inputDirectory.exists()) {
44
        println "** ExcelDir2XML: no '"+inputDirectory.name+"' directory found. Aborting."
45
        return false
46
}
47

    
48
if (!inputDirectory.canRead()) {
49
        println "** ExcelDir2XML: '"+inputDirectory.name+"' directory not readable. Aborting."
50
        return false
51
}
52

    
53
def f = []
54
inputDirectory.eachFileMatch(~/.*xlsx/) { f << it }
55

    
56
if (f.size() == 0) {
57
        println "** ExcelDir2XML: no .xlsx file found. Aborting."
58
        return false
59
}
60

    
61
try {
62

    
63
f.sort { it.name }.each { inputFile ->
64

    
65
        res = gse.run(Excel2XMLMacro, ["args":[
66

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

    
84
} catch (Exception e) {
85
        println "** ExcelDir2XML: unable to read input files. Aborting."
86
        println e.getLocalizedMessage()
87
        println e.printStackTrace()
88
        return false
89
}
90

    
91
return true