Created
December 12, 2012 12:06
-
-
Save taktos/4267279 to your computer and use it in GitHub Desktop.
DBFluteのload-data-reverseで出力したExcelを1テーブル1ファイルに分解するGroovyスクリプト
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 characters
@Grab('org.apache.poi:poi:3.9') | |
import org.apache.poi.hssf.usermodel.* | |
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}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment