Download poi-bin-3.10-FINAL-20140208.zip unzip
Copy
Poi-3.10-FINAL-20140208.jar
Poi-ooxml-3.10-FINAL-20140208.jar
Poi-ooxml-schemas-3.10-FINAL-20140208.jar
Ooxml-Lib \ dom4j-1.6.1.jar
Ooxml-Lib \ dom4j-1.6.1.jar
Ooxml-Lib \ xmlbeans-2.3.0.jar
To D: \ groovy-1.8.9 \ Lib \
The read_xlsx.groovy code is as follows:
import javax.swing.JFileChooserimport javax.swing.filechooser.FileFilterimport javax.swing.filechooser.FileNameExtensionFilterimport java.io.File;import org.apache.poi.xssf.usermodel.XSSFCell;import org.apache.poi.xssf.usermodel.XSSFRow;import org.apache.poi.xssf.usermodel.XSSFSheet;import org.apache.poi.xssf.usermodel.XSSFWorkbook;class ReadExcel {static void main(args) {def getFilename ={def initDir='D:/'def chooser=new JFileChooser(initDir)def filter = new FileNameExtensionFilter('Excel', 'xlsx')chooser.setFileFilter(filter)chooser.setDialogTitle("Open")if(chooser.showSaveDialog() == JFileChooser.APPROVE_OPTION)return chooser.getSelectedFile()else if(chooser.showSaveDialog() == JFileChooser.CANCEL_OPTION)return nullelsereturn null}def filename = getFilename() as Stringdef outfile = new File(filename.replace('xlsx','txt'));def fp = outfile.newPrintWriter();println filenameXSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(filename));(0..<wb.numberOfSheets).each{ XSSFSheet sheet = wb.getSheetAt(it) int rows = sheet.physicalNumberOfRows println " sheet:\"" + wb.getSheetName(it) + "\" has " + rows + " row(s)." (0..<rows).each{ r -> XSSFRow row = sheet.getRow(r) if (row != null) { int cells = row.physicalNumberOfCells // println "\nROW " + row.rowNum + " has " + cells + " cell(s)." (0..<cells).each{ c -> XSSFCell cell = row.getCell(c) if (cell == null) fp.print '\t'; else if (cell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) fp.print cell.getBooleanCellValue()+'\t'; else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) fp.print cell.getNumericCellValue()+'\t'; else fp.print cell.getStringCellValue()+'\t'; } fp.println ''; } } }fp.flush();fp.close();}}
GROOVY: poi read Excel XLSX