码迷,mamicode.com
首页 > 数据库 > 详细

读取excel数据到数据库里

时间:2019-11-09 17:57:55      阅读:92      评论:0      收藏:0      [点我收藏+]

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

用的是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   工作   

原文地址:https://www.cnblogs.com/CipherLab/p/11826616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!