展开全部
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
HttpSession hs = request.getSession();
String savedir = hs.getServletContext().getRealPath("")+"\\路径";
int maxPostSize =1 * 5 * 1024 * 1024 ;
MultipartRequest multi = new MultipartRequest(request, savedir, maxPostSize,"gb2312");
Enumeration files = multi.getFileNames();
if(files.hasMoreElements()){
String name = (String)files.nextElement();
File f = multi.getFile(name);
if(f!=null) {
String fileName = multi.getFilesystemName(name);
String lastFileName = savedir+"\\" + fileName;
String[] emp_num = "";
String[] adjust_type = "";
try {
// 创建对Excel工作簿文件的引用
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(lastFileName));
HSSFSheet sheet = workbook.getSheetAt(0);
int numberofrows = sheet.getPhysicalNumberOfRows();
for(int i=0;i
HSSFRow row = sheet.getRow(i);
int cellcount =row.getPhysicalNumberOfCells();
for(int j=0;j<2;j++) {
HSSFCell cell = row.getCell((short)j);
if(j=0)
emp_num[i] =cell.getStringCellValue();
if(j=1)
adjust_type[i] = cell.getStringCellValue();
}
}
}
catch(Exception e){
System.out.println("已运32313133353236313431303231363533e4b893e5b19e31333335303534行xlRead() : " + e.toString() );
}
}