使用jexcel api和.xls文件的搜索功能?

时间:2018-09-02 20:17:45

标签: java

我正在寻找接受用户输入的最佳方法。特定列中的频道名称,然后使用.xls文件进行搜索。然后,我想将整行数据返回到控制台吗?任何帮助都会很棒。.

公共课菜单{     私有字符串inputFile;

    public void setInputFile(String inputfile) {
        this.inputFile = inputfile;
    }

    public void Read() throws IOException {
        File inputworkbook = new File(inputFile);
        Workbook w;
        try {
            w = Workbook.getWorkbook(inputworkbook);

            Sheet sheet = w.getSheet(0);

            for (int i = 0; i < sheet.getRows(); i++) {
                boolean rowEmpty = true;
                String currentRow = "";
                for (int j = 0; j < sheet.getColumns(); j++) {
                    Cell cell = sheet.getCell(j, i);
                    String con=cell.getContents();
                    if(con !=null && con.length()!=0){
                        rowEmpty = false;
                    }
                    currentRow +=  "|" + con ;
                }
                if(!rowEmpty) {
                    System.out.println("+---------------------------------------------------------------------------------------------------------------------------------------------------+");
                    System.out.printf("%-24s\n", (currentRow), "|");
                    System.out.println("+---------------------------------------------------------------------------------------------------------------------------------------------------+");
                }
                System.out.println("=====================================================================================================================================================");


            }   
    } catch (BiffException e) {
        e.printStackTrace();
    }

    }
public static void main(String[] args) throws IOException {
    Menu test = new Menu();
    test.setInputFile("test.xls");
    test.Read();

}
    }

0 个答案:

没有答案