/**
* 描述:根据源Excel文件,创建新的Excel文件
* @param excelFile
* @throws CheckException
*/
public static void createExcelFile(File excelFile) throws CheckException{
checkExcelFile(excelFile);
WritableWorkbook nameWorkbook=null;
WritableSheet namesheet=null;
File nameFile=new File(excelFile.getParent()+"\\name.xls");
try{
//新建Excel文件
nameWorkbook = jxl.Workbook.createWorkbook(nameFile);
namesheet = nameWorkbook.createSheet("sheet1",0);
//读取源Excel文件
Workbook workbook=new HSSFWorkbook(new FileInputStream(excelFile));
Sheet sheet = workbook.getSheetAt(0); // 从工作区中取得页(Sheet)
int rowEnd = sheet.getLastRowNum();
for (int i = 0; i < rowEnd; i++) {//按 行 读取Excel文件内容
Row row = sheet.getRow(i);
row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
String xuhao = row.getCell(0).getStringCellValue();;//序号 列
String name= row.getCell(2).getStringCellValue();//姓名 列
//写新Excel文件 序号-姓名
Label xuhaoCell0 = new Label(0,i,xuhao);//添加序号
namesheet.addCell(xuhaoCell0);
Label nameCell = new Label(1,i,name);//添加姓名
namesheet.addCell(nameCell);
}
nameWorkbook.write();
nameWorkbook.close();
}catch (Exception e){
e.printStackTrace();
}
}