如何用Java读取XLS(Excel)中的文件数据,机器人 [英] How to read data from XLS (Excel) file in java, android

查看:214
本文介绍了如何用Java读取XLS(Excel)中的文件数据,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我寻觅计算器,但我没有找到一个明确的答案。我怎样才能读取特定行和XLS文件的列中的数据,以我的Andr​​oid应用程序?我怎样才能读取XLS文件?我不希望将其转换为CSV,因为我得到的错误,当我尝试将它们转换。

I have searched stackoverflow but I didn't find a clear answer. How can I read data from particular rows and columns of XLS file to my Android application? How can I read XLS file? I don't want to convert it to CSV because I get errors when I try to convert them.

也许我可以用这个<一href="http://www.andykhan.com/jexcelapi/tutorial.html#reading">http://www.andykhan.com/jexcelapi/tutorial.html#reading但我甚至不知道我怎么可能将其导入到我的项目。请大家帮帮忙。

Maybe I could use this http://www.andykhan.com/jexcelapi/tutorial.html#reading but I even don't know how could I import it into my project. Please help.

推荐答案

你只需要包括外部JXL罐子,你可以通过同样的教程,这将有助于你理解阅读Excel文件的过程。对于您的全球化志愿服务青年,我粘贴一些参考。 code读取Excel中的第一个表,并创建一个结果。

Hi you just need to include an external jxl jar and you can go through the same tutorial which will help you understand the process of reading excel files.. for your referance i am pasting some ref. code which reads very first sheet of excel and creates a resultset.

    public List<String> read(String key) throws IOException  {
    List<String> resultSet = new ArrayList<String>();

    File inputWorkbook = new File(inputFile);
    if(inputWorkbook.exists()){
        Workbook w;
        try {
            w = Workbook.getWorkbook(inputWorkbook);
            // Get the first sheet
            Sheet sheet = w.getSheet(0);
            // Loop over column and lines
            for (int j = 0; j < sheet.getRows(); j++) {
                Cell cell = sheet.getCell(0, j);
                if(cell.getContents().equalsIgnoreCase(key)){
                    for (int i = 0; i < sheet.getColumns(); i++) {
                        Cell cel = sheet.getCell(i, j);
                        resultSet.add(cel.getContents());
                    }
                }
                continue;
            }
        } catch (BiffException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    else
    {
        resultSet.add("File not found..!");
    }
    if(resultSet.size()==0){
        resultSet.add("Data not found..!");
    }
    return resultSet;
}

这篇关于如何用Java读取XLS(Excel)中的文件数据,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆