java读取excel中两列,先读完第一列然后读第二列,存入一维数组,求指导
3个回答
展开全部
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<numberofrows;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("已运行xlRead() : " + e.toString() );
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
BufferedReader buf = new BufferedReader(new FileReader(filename));
int count = 0;
String url = null;
while((url = buf.readLine())!= null)
{
//文件数据模型
URLData urlData = new URLData();
//过滤读取内容
String urls[] = url.split(",");
if(urls !=null)
{
count++;
//保存内容到URLData对象中
String[] content = url.split(",");
if(content != null && content.length>0)
{
urlData.setUrl(content[0]);
urlData.setVisitNum(content[1]);
//保存数据
urlDataList.add(urlData);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-01-16
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询