#导出.xls
class="java">
//选择导出文件的保存路径
JFileChooser dlg = new JFileChooser();
dlg.setFileFilter(new ExcelFilter());
dlg.setDialogTitle(”保存文件”);
dlg.showSaveDialog(JFrame); //CatFishEnvironment.getInstance().getMainFrame()
if(dlg.getSelectedFile()==null) return;
File file = new File(dlg.getSelectedFile().getAbsolutePath() + “.xls”);
//新建对象
HSSFWorkbook wb = new HSSFWorkbook();
HSSFCell targetcell=null;
HSSFRow targetrow=null;
HSSFSheet targetsheet=null;
//创建sheet
targetsheet = wb.createSheet(headBean.getLotNo());
//创建Title
targetrow = targetsheet.createRow((short)0);
targetcell=targetrow.createCell((short)0);
targetcell.setCellType(HSSFCell.CELL_TYPE_STRING);
targetcell.setCellValue(”Title1″+ “\t”);
targetcell=targetrow.createCell((short)1);
targetcell.setCellType(HSSFCell.CELL_TYPE_STRING);
targetcell.setCellValue(”Title2″+ “\t”);
//插入记录
targetrow = targetsheet.createRow((targetsheet.getLastRowNum()+1));
targetcell=targetrow.createCell((short)0);
targetcell.setCellType(HSSFCell.CELL_TYPE_STRING);
targetrow.getCell(0).setCellValue(”Content1″ + “\t”);
targetcell=targetrow.createCell((short)1);
targetcell.setCellType(HSSFCell.CELL_TYPE_STRING);
targetrow.getCell(0).setCellValue(”Content2″ + “\t”);
//写文件
FileOutputStream fOut = new FileOutputStream(file,true);
wb.write(fOut);
fOut.flush();
fOut.close();
//文件导出成功
Runtime.getRuntime().exec(”cmd /c start \”\” \”" + file + “\”");
//附相关的jar:poi-3.6-20091214.jar