package com.quark.auto;
import
java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.EncryptedDocumentException;
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.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class ExcelAccess {
public void readExcel(String fileIn){
try {
Workbook wb = WorkbookFactory.create(new File(fileIn));
Sheet sh0 = wb.getSheetAt(0);
for(int i=sh0.getFirstRowNum();i<=sh0.getLastRowNum();i++){
Row row = sh0.getRow(i);
Iterator<Cell> it = row.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
} catch (EncryptedDocumentException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void writeExcel(Workbook wb,String fileOut){
try {
FileOutputStream fileOutStr = new FileOutputStream(new File(fileOut));
wb.write(fileOutStr);
fileOutStr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}