⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 excelimport.java

📁 Java源代码,使用JBulider开发的上传类,可以上传图片,铃声.
💻 JAVA
字号:
package com.owner.demo;

import java.io.*;
import java.util.*;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class Excelimport {

  private static ArrayList subdata = new ArrayList();
  private static String tablename = "";
  private static String filePath = "";

  public Excelimport() {
  }

  /**
  *
  * @author Administrator
  * @param data
  * 读取Excel中的数据的数组.
  * @deprecated:将读取Excel中的数据插入到对应的数据库表中.
  * 此方法在调用前需要先调用setFilePath(String)这个方法.
  */
 public void DataImport() throws Exception {
  try
  {
    ArrayList al = readExcel(getFilePath());
  }
  catch (Exception e)
  {
    e.printStackTrace();
  }
 }

 /**
  *
  * @author Administrator
  * @param filePath 文件路径.
  * @deprecated:读取Excel中的数据将它放入到ArrayList数组中(此为三维数组).
  */
 public static ArrayList readExcel(String filePath) {
  try
  {
    InputStream is = new FileInputStream(filePath);
    Workbook rwb = Workbook.getWorkbook(is);
    // Sheet st = rwb.getSheet(0);
    //这里有两种方法获取sheet表,1为名字,而为下标,从0开始.注意很多地方把0加上""了这样是不正确的.
    // Sheet st = rwb.getSheet("Book1");// Excel中第一页的页名称.
    Sheet st[] = rwb.getSheets(); // 得到所有Excel中页的列表.
    for (int a = 0; a < st.length; a++) {
      ArrayList alList = new ArrayList();
      ArrayList tablenames = new ArrayList();
      ArrayList tableAndContents = new ArrayList();
      tablename = st[a].getName().trim();
      int b = 0;
      for (int i = 1; i < st[a].getRows(); i++) {
        ArrayList al = new ArrayList();
        for (int j = 0; j < st[a].getColumns(); j++) {
          Cell c00 = st[a].getCell(j, i);
          // 通用的获取cell值的方式,返回字符串
          //String strc00 = StringUtil.toISO(c00.getContents().trim());
          // 获得cell具体类型值的方式得到内容.
          //al.add(j, strc00);
        }
        alList.add(b, al);
        b++;
      }
      tablenames.add(tablename);
      tableAndContents.add(0, tablenames);
      tableAndContents.add(1, alList);
      subdata.add(a, tableAndContents);
    }
    rwb.close();
    // 关闭
    //System.out.println(subdata);// 输出
  }
  catch (Exception e) {
    e.printStackTrace();
  }
  return subdata;
 }

 public static String getFilePath() {
  return filePath;
 }

 public static void setFilePath(String filePath) {
  Excelimport.filePath = filePath;
 }


  public static void main(String[] args) {
    Excelimport excelimport1 = new Excelimport();
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -