zoukankan      html  css  js  c++  java
  • 读取excel数据到数据库里

    用的是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();

    }

  • 相关阅读:
    C#中索引器的实现过程,是否只能根据数字进行索引?
    重载与覆盖的区别?
    C#中 property 与 attribute的区别?
    C#可否对内存进行直接的操作?
    在c#中using和new这两个关键字有什么意义?
    secs/gem协议
    框架2
    C#开发框架学习
    C#两种数据类型
    泛型参数
  • 原文地址:https://www.cnblogs.com/CipherLab/p/11826616.html
Copyright © 2011-2022 走看看