// 監査ログ.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
    list.add(variable)
}

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