POI read write and save

 通過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 sheetIterator = workbook.iterator();
		Sheet sheet = null;
		while(sheetIterator.hasNext()) {
			sheet = sheetIterator.next();
			Iterator rowIterator = sheet.iterator();
			AtomicInteger index = new AtomicInteger();
			while(rowIterator.hasNext()) {
				System.out.println("line "+index.getAndIncrement());
				Iterator 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

你可能感兴趣的:(JDK,java,前端,服务器,POI)