1

我有一个excel文件:test_excel.xls

我想阅读里面的内容。

我所做的:

1)从客户端上传文件

2) 解析为 Base64 字符串(使用 javascript)

3)从Base64转换为字节

4) 上传字节串到服务器

5)我卡在这里,我不知道如何获取数据,我尝试了很多方法(Apache POI,转换为FileInputStream..)

有人对这个问题有想法吗?

4

1 回答 1

1

上传文件,像这样从中获取字节[]:

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你可能想清理代码,我只是抓住了我记得的第一件事,据我所见,它可以使用一些清理微笑

于 2013-09-10T07:31:58.453 回答