标签:string rgs obj 访问 new getc logs cell cep
所用Jar包
1. sqljdbc4.jar
连接数据库的Jar包(根据数据库的不同进行选择,我用的SqlServer2008)
2.Jxl.jar
访问Excel的Jar包
package xsl; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; public class Test { public static void main(String[] args) { //定义一维数组,存放Excel表里的每一行的各个列的数据 Object[] obj = null; //定义List集合,存放每一行的数据 ArrayList<Object[]> list = new ArrayList<Object[]>(); String filePath = "C:/Users/0223000320/Desktop/student.xls"; InputStream is = null; Workbook rwb = null; try { is = new FileInputStream(filePath);//定义文本输入流 } catch (FileNotFoundException e) { e.printStackTrace(); } try { rwb = Workbook.getWorkbook(is);//打开Workbook } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } //获取Excel表的Sheet1区域的数据 Sheet sht = rwb.getSheet("Sheet1"); int col = sht.getColumns(); //获得Excel列 int row = sht.getRows(); //获得Excel行 Cell c1 = null; //先将数据按行装入一个一维数组中, 然后将数组逐个加入到ArrayList for(int i=0; i < row; i++){ obj = new Object[col]; for(int j =0 ;j <col; j++){ c1 = sht.getCell(j,i); //add String contents = c1.getContents(); System.out.println(contents); obj[j] = c1.getContents(); } System.out.println("------------"); list.add(obj); } } }
标签:string rgs obj 访问 new getc logs cell cep
原文地址:http://www.cnblogs.com/Donnnnnn/p/7742368.html