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();

    }

  • 相关阅读:
    python学习笔记(二)
    python学习笔记(四)
    首个python程序,一个猜数字的小游戏 ^0^
    python生成随机数
    python生成随机数
    python学习笔记(四)
    我的书《编写高质量代码—Web前端开发修炼之道》面市了,请大家多多支持
    python学习笔记(三)
    EasyNVR纯H5摄像机直播解决方案前端解析之:RTSP安防监控实时直播的网页H5自动播放方案
    基于EasyNVR实现RTSP_Onvif监控摄像头Web无插件化直播监控
  • 原文地址:https://www.cnblogs.com/CipherLab/p/11826616.html
Copyright © 2011-2022 走看看