获取excel文件的数据 – JSF
我有一个Excel文件:test_excel.xls
我想阅读里面的内容。
我做的事:
1)从客户端上传文件
2)parsing到Base64string(使用JavaScript)
3)从Base64转换为字节
4)将字节串上传到服务器
5)我卡在这里,我不知道如何获取数据,我已经尝试了很多方法(Apache POI,转换为FileInputStream ..)
有没有人有这个问题的想法?
上传文件,像这样得到byte []:
public static byte[] getByteStream(File file) { byte[] b = new byte[(int) file.length()]; try { FileInputStream fileInputStream = new FileInputStream(file); fileInputStream.read(b); for (int i = 0; i < b.length; i++) { //System.out.print((char) b[i]); } } catch (FileNotFoundException e) { System.out.println("File Not Found."); e.printStackTrace(); } catch (IOException e1) { System.out.println("Error Reading The File."); e1.printStackTrace(); } return b; }
并将其与Apache POI或任何其他“excel”框架一起使用来读取其值。
PS你可能想清理代码,我只是抓住了我记得的第一件事,从我能看到它可以使用一些清洁的微笑