怎样将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了
[解决办法]