package cn.appkit.cpm.importor;
import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ImportorXlsx {
public ImportorXlsx() {
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
String filepath = "C:\\Users\\Administrator\\Desktop\\看板\\权限分配情况.xlsx";
FileInputStream fis = new FileInputStream(filepath);
Workbook wb = new XSSFWorkbook(fis);
Sheet sheet = wb.getSheetAt(0);
int rowMax = sheet.getPhysicalNumberOfRows();
for (int i = 1; i < rowMax; i++) {
Row row = sheet.getRow(i);
int columnMax = row.getPhysicalNumberOfCells();
for (int j = 0; j < columnMax; j++) {
Cell cell = row.getCell(j);
Object cellValue = null;
if (null != cell) {
switch (cell.getCellType()) {
case NUMERIC:
cellValue = String.valueOf((int) cell.getNumericCellValue());
break;
case STRING:
cellValue = String.valueOf(cell.getStringCellValue());
break;
}
}
System.out.print("\t" + cellValue.toString());
}
System.out.println();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}