通過xssf 讀寫Excel
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
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.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
XSSFWorkbook workbook = new XSSFWorkbook();
workbook = new XSSFWorkbook(new File("D:ILsaa.xlsx"));
Iterator<Sheet> sheetIterator = workbook.iterator();
Sheet sheet = null;
while(sheetIterator.hasNext()) {
sheet = sheetIterator.next();
Iterator<Row> rowIterator = sheet.iterator();
AtomicInteger index = new AtomicInteger();
while(rowIterator.hasNext()) {
System.out.println("line "+index.getAndIncrement());
Iterator<Cell> cellIterator = row.iterator();
while(cellIterator.hasNext()) {
// switch(cell.getCellType()){
// case NUMERIC:
// cell.setCellValue(232332);
// continue;
// case STRING:
// cell.setCellValue("test");
// continue;
// case BOOLEAN:
// cell.setCellValue(true);
// continue;
// case _NONE:
// continue;
// case BLANK:
// continue;
// case FORMULA:
// continue;
// case ERROR:
// continue;
// default:
// continue;
// }
}
}
}
FileOutputStream out = new FileOutputStream("E:\\ILbb.xlsx");
workbook.write(out);
out.close();
}
通過hssf 讀寫Excel
TODO