java swing 抽奖程序_java swing抽奖系统

这个Java程序展示了如何使用Swing和jxl库从Excel文件中读取数据。程序读取指定路径的Excel文件,从第一行开始,获取每一行的前两列内容并存入Vector对象中,适用于构建抽奖系统的数据准备部分。
摘要由CSDN通过智能技术生成

package youg;

import java.io.FileInputStream;

import java.io.InputStream;

import java.util.Vector;

import jxl.Cell;

import jxl.Sheet;

import jxl.Workbook;

public class ReadExcel {

//Vector v_identNumber = new Vector(); // 存放读取出来的号码

public Vector readExcel(String filePath) throws Exception {

Vector v = new Vector(); // 存放读取出来的姓名和电话

InputStream iStream = null;

Workbook workbook = null;

iStream = new FileInputStream(filePath);

workbook = Workbook.getWorkbook(iStream);

// sheet row column 下标都是从0开始的

Sheet sheet = workbook.getSheet(0);

int column = sheet.getColumns();

int rows = sheet.getRows();

System.out.println("共有" + rows + "行," + column + "列数据");

for (int i = 1; i < rows; i++) {

Cell[] cells = sheet.getRow(i);

//System.out.println(cells[0].getContents());

v.add(cells[0].getContents());

v.add(cells[1].getContents());

//System.out.println(cells[1].getContents());

//v_identNumber.add(cells[1].getContents());

//System.out.println(cells[2].getContents());

//System.out.println(cells[3].getContents());

}

// 操作完成时,关闭对象,释放占用的内存空间

if (iStream != null)

iStream.close();

if (workbook != null)

workbook.close();

return v;

}

/**

* @param args

* @throws Exception

*/

//public static void main(String[] args) throws Exception {

//String filePath = "D:\\testreadexcel.xls";

//ReadExcel readExcel = new ReadExcel();

//readExcel.readExcel(filePath).toString();

//

//}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值