日期:2014-05-20 浏览次数:20785 次
File sfile = new File(filename);
book = Workbook.getWorkbook(sfile);
Sheet sheet = book.getSheet(0);
int num = (int)(Math.random()*1000000)%studentnumber;
System.out.println(num);
String sname = "请输入"+sheet.getCell(0, num).getContents()+"同学的得分";
String score = JOptionPane.showInputDialog(RandPanel.this, sname);
WritableWorkbook wb = Workbook.createWorkbook(new File(filename), book);
WritableSheet sheet2 = wb.createSheet("sheet2", 1);
jxl.write.Label Lsocre = new jxl.write.Label(0,num,score);
try {
sheet2.addCell(Lsocre);
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wb.write();
book.close();
import java.io.File;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class SimpleExcelWrite {
/**
* 创建简单的Excel
* @throws Exception
*/
public static void createExcel() throws Exception {
File file = new File("test.xls");
WritableWorkbook workbook = Workbook.createWorkbook(file);// 设置文件
WritableSheet sheet = workbook.createSheet("test", 0);// 设置sheet名
WritableSheet sheet1 = workbook.createSheet("222222", 1);// 设置sheet名
Label xuexiao = new Label(0, 0, "学校");// 设置单元格
Label xuexiao1 = new Label(0, 0, "学校");// 设置单元格
sheet.addCell(xuexiao);// 追加单元格
sheet1.addCell(xuexiao1);// 追加单元格
Label zhuanye = new Label(1, 0, "专业");
sheet.addCell(zhuanye);
Label qinghua = new Label(0, 1, "清华");
sheet.addCell(qinghua);
Label jisuanji = new Label(1, 1, "计算机");
sheet.addCell(jisuanji);
Label qinghua1 = new Label(0, 2, "sichongqing");
sheet.addCell(qinghua1);
Label jisuanji1 = new Label(1, 2, "dahuaidan");
sheet.addCell(jisuanji1);
workbook.write();
workbook.close();
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
createExcel();
}
}