从Excel里面读出数据并将数据存入数据库
package com.hzm.sample; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.sql.Connection; import java.sql.SQLException; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import com.mocenter.db.ODBHandler; public class ReadExcel { private static String path = "c:/book1.xls"; double util[][] = new double[10][10]; // 表(sheet)--->行(row)-->行里面的存储格(cell) public void readExcel(String excelPath) { excelPath = path; try { // 创建对Excel工作簿文件的引用 FileInputStream finput = new FileInputStream(excelPath); POIFSFileSystem fs = new POIFSFileSystem(finput); HSSFWorkbook wb = new HSSFWorkbook(fs);//HSSFWorkbook对象代表一个Excel文档 HSSFRow row = null;// 宣告一行 HSSFCell cell = null;// 宣告一个储存格 int num = wb.getNumberOfSheets();// 工作表sheet的数量 System.out.println("当前工作表数量是:" + num); int i = 0; short y = 0; for (int sheetNum = 0; sheetNum
用户评论