当前位置:Gxlcms > 数据库问题 > 读取excel数据到数据库里

读取excel数据到数据库里

时间:2021-07-01 10:21:17 帮助过:15人阅读

用的是jxlJar

/**

 * 读取excel数据到数据库里

 */

private void readExcelToDB() {

    new Thread(new Runnable() {

        @Override

        public void run() {

            try {

                String filePath = "/sdcard/";

                String fileName = "307322.xlsx";

                File file = new File(filePath, fileName);

                FileInputStream is = new FileInputStream(file);

                Workbook book = Workbook.getWorkbook(is);

                // 获取表页数

                final int bookPage = book.getNumberOfSheets();

                Log.e("bookPage", "bookPage = " + bookPage);

                // 获得第一个工作表对象

                Sheet sheet = book.getSheet(0);

                int Rows = sheet.getRows();

                for (int i = 1; i < Rows; ++i) {

                    String assetNumber = (sheet.getCell(0, i)).getContents();

                    String assetName = (sheet.getCell(3, i)).getContents();

                    String sTmp8 = sheet.getCell(8, i).getContents();

                    String sTmp9 = sheet.getCell(9, i).getContents();

                }

                book.close();

                runOnUiThread(new Runnable() {

                    @Override

                    public void run() {

                        Toast.makeText(ActivityMain.this, "导入成功", Toast.LENGTH_SHORT).show();

                    }

                });

            } catch (Exception e) {

                runOnUiThread(new Runnable() {

                    @Override

                    public void run() {

                        Toast.makeText(ActivityMain.this, "导入失败", Toast.LENGTH_SHORT).show();

                    }

                });

            }

        }

    }).start();

}

读取excel数据到数据库里

标签:getc   etc   excel   make   tst   length   book   gets   工作   

人气教程排行