Created
December 12, 2012 12:06
Revisions
-
taktos revised this gist
Dec 12, 2012 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ @Grab('org.apache.poi:poi:3.9') import org.apache.poi.hssf.usermodel.* def config = [ reverseDir : 'output/doc/data', -
taktos created this gist
Dec 12, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ @Grab('org.apache.poi:poi:3.9') import org.apache.poi.hssf.usermodel.* import org.apache.poi.hssf.usermodel.contrib.* def config = [ reverseDir : 'output/doc/data', dataDir : 'playsql/data/ut/xls', tableNameMap: 'tableNameMap.dataprop', ignoreTable : [ 'ignore_table_name', ], ] new File(config.reverseDir).eachFileMatch(~/.*\.xls/) { f -> def numbering = (f.name =~ /load-data-(\d+)\b/)[0][1] f.withInputStream { fin -> def book = new HSSFWorkbook(fin) def numOfSheets = book.numberOfSheets book.sheets.eachWithIndex { sheet, i -> println i + ' ' + sheet.sheetName if (config.ignoreTable.find { it == sheet.sheetName }) { println ' ... skip' return } f.withInputStream { pin -> def parted = new HSSFWorkbook(pin) parted.cloneSheet(i) for (s in numOfSheets - 1..0) { parted.removeSheetAt(s) } parted.setSheetName(0, sheet.sheetName) new File("${config.dataDir}/${numbering}-${i}-${sheet.sheetName}.xls").withOutputStream { parted.write(it) } } } } } new AntBuilder().copy(file: "${config.reverseDir}/${config.tableNameMap}", tofile: "${config.dataDir}/${config.tableNameMap}")