怎样将xls文件数据导入并保存在session中!!!急。。。。。
怎样将xls文件(如:excel)数据导入并保存在session中!!!!!!!
我现在有个浏览按钮,点击选择excel文件,要取得文件里面所有数据并且保存在session中!!求解
急。。。。。
------解决方案--------------------字节流会用么?把文件内容读出来以任何(看你自己怎么方便)形式存储下来,再存入session就行了么
------解决方案--------------------public static boolean readword2(String filepath){//第二种方式  
  String FileFormat = "";
   System.out.println(filepath);
   FileFormat = filepath.substring(filepath.length()-4,filepath.length());
   System.out.println(FileFormat);
   if(FileFormat.equalsIgnoreCase(".doc"))
   {
       String DocFile = filepath ;
       System.out.println("word文件路径:"+DocFile);
       //word文件的完整路径
       String HtmlFile = DocFile.substring(0, (DocFile.length() - 4)) + ".htm";
       System.out.println("htm文件路径:"+HtmlFile);
       //html文件的完整路径
       ActiveXComponent app = new ActiveXComponent("Word.Application");
       //启动word
       try
       {
         app.setProperty("Visible", new Variant(false));
         //设置word程序非可视化运行
         Dispatch docs = app.getProperty("Documents").toDispatch();
         Dispatch doc = Dispatch.invoke(docs,"Open", Dispatch.Method, new Object[]{DocFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch();
         //打开word文件
         Dispatch.invoke(doc,"SaveAs",Dispatch.Method, new Object[]{HtmlFile,new Variant(8)}, new int[1]);
         //作为htm格式保存文件
         Dispatch.call(doc, "Close",new Variant(false));
         //关闭文件
       }
       catch (Exception e)
       {
         e.printStackTrace();
       }
       finally
       {
         app.invoke("Quit", new Variant[] {});
         //退出word程序
       }
       //转化完毕
       return true;
   }
   return false;  
}  
}
读取后的数据存到数据库就O了
------解决方案--------------------将xls中的数据解析出来,封装到一个容器中,然后将容器保存到SESSION中就OK了
------解决方案--------------------
------解决方案--------------------
这里简单介绍了一下操作
public List<User> analysis() throws 
IOException {
	File excel = new File("这里是你的文件的位置");  // 读取文件
	FileInputStream in = new FileInputStream(excel); // 转换为流
	HSSFWorkbook workbook = new HSSFWorkbook(in); // 加载excel的 工作目录
	HSSFSheet sheet = workbook.getSheetAt(0); // 获取工作的sheet页
	int rowIndex = 0; // 从第0行开始读取的,意思与数组一样
	HSSFRow prow = null;
	List<User> users = new ArrayList<User>();	
	while ((prow = sheet.getRow(rowIndex++)) != null) { // 存在信息,继续循环
		short cellIndex = 0;
		User user = new User();  // 你的会员实体类		
		// 把单元格里的信息封装到对象中
		user.setXXX(prow.getCell(cellIndex++));
		……		
		users.add(user);  // 放到集合里
	}	
	return users;  // 返回结果集,就可以了
}