tech_memo / groovy


tech_memo

Excel操作

読み込みサンプル

import org.apache.poi.xssf.usermodel.*

def filePath = "./test.xlsx"
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(filePath))
XSSFSheet sheet = workbook.getSheet("test");

for(i in sheet.getFirstRowNum()..sheet.getLastRowNum()) {
	XSSFRow row = sheet.getRow(i)
	XSSFCell idCell = row.getCell(0);
	XSSFCell nameCell = row.getCell(1);
	def id = idCell.getNumericCellValue() as int // ★Excelが数値を少数として認識していたので、整数に変換
	def name = nameCell.getStringCellValue()
	println "id = $id"
	println "name = $name"
}