package pm;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
//无限录入学员信息
public class For_Sys_In {
public static void main(String[] args) throws RowsExceededException, WriteException, BiffException, IOException {
while(true)
{
Scanner sc = new Scanner(System.in);
System.out.println("name");
String name = sc.next();
System.out.println("math");
double math = sc.nextDouble();
System.out.println("chinese");
double chinese = sc.nextDouble();
System.out.println("english");
double english = sc.nextDouble();
File file = new File("d:\\dd.xls");
Workbook wb = Workbook.getWorkbook(file);
//创建一个副本
WritableWorkbook copyExcel = Workbook.createWorkbook(file,wb);
//获得一个sheet
WritableSheet sheet = copyExcel.getSheet(0);
//获得行数
int rows = sheet.getRows();
//添加一行信息
Label s0 = new Label(0,rows,name);
Label s1 = new Label(1,rows,math+"");
Label s2 = new Label(2,rows,chinese+"");
Label s3 = new Label(3,rows,english+"");
sheet.addCell(s0);
sheet.addCell(s1);
sheet.addCell(s2);
sheet.addCell(s3);
copyExcel.write();
copyExcel.close();
System.out.println("继续录入?1.继续循环 0.结束循环");
int flag = sc.nextInt();
if(flag!=1)
{
break;
}
}
System.out.println("程序结束!");
}
}
jxl实现信息的无限录入
最新推荐文章于 2022-04-18 15:55:07 发布