// 監査ログ.xls CSV変換スクリプト
@Grab('org.apache.poi:poi-ooxml:3.7')
import org.apache.poi.ss.usermodel.WorkbookFactory

//def inputFile = new File(arg[0])
def inputFile = new File("c:/アプリケーション一覧20111024.xls")
def book = WorkbookFactory.create(new FileInputStream(inputFile))
def sheet = book.getSheetAt(0)
def cell = { col, row ->
    sheet.getRow(row)?.getCell((short)col)
}

def list = []
for(int i in 1..65535) {
    if(!cell(0, i)?.stringCellValue) break;

    variable = [:]
    variable.username = cell(0, i)?.stringCellValue
    variable.pcname = cell(1, i)?.stringCellValue
	variable.user = cell(2, i)?.stringCellValue
	variable.post1 = cell(3, i)?.stringCellValue
	variable.post2 = cell(4, i)?.stringCellValue
	variable.post3 = cell(5, i)?.stringCellValue
	variable.application = cell(6, i)?.stringCellValue
	variable.version = cell(7, i)?.stringCellValue
	variable.path = cell(8,i)?.stringCellValue
    list.add(variable)
}

//new File(arg[1]).withWriter { writer ->
new File("C:/Users/ryota/Desktop/groovyTest.csv").withWriter("SJIS") { writer ->
    list.each {
        writer.println("${it.username},${it.pcname},${it.user},${it.post1},${it.post2},${it.post3},${it.application},${it.version},${it.path}")
    }
}