//jar
importjava.io.BufferedReader;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.FileWriter;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.text.SimpleDateFormat;importjava.util.Date;importjava.util.List;importjava.util.logging.Logger;importorg.apache.poi.poifs.filesystem.POIFSFileSystem;importorg.apache.poi.ss.usermodel.WorkbookFactory;importorg.apache.poi.xssf.usermodel.XSSFCell;importorg.apache.poi.xssf.usermodel.XSSFRow;importorg.apache.poi.xssf.usermodel.XSSFSheet;importorg.apache.poi.xssf.usermodel.XSSFWorkbook;importorg.dom4j.Document;importorg.dom4j.DocumentException;importorg.dom4j.DocumentHelper;importorg.dom4j.io.OutputFormat;importorg.dom4j.io.XMLWriter;importcom.xyzq.kettle.dao.KettleDao;importcom.xyzq.kettle.entity.KettleEntity;importcom.xyzq.pub.Pub;//实现方法
public void makeExcle(Listlist){
logger.info("生成excle:start");
String filepath= exl_sh_path+"/"+list.get(0).getSysName();
String filename= "P_gp_"+list.get(0).getSysName()+".xlsx";//判断文件夹是否存在,不存在则创建
try{
Pub.checkPath(filepath);
}catch(InterruptedException e1) {
e1.printStackTrace();
logger.info("文件夹创建异常:"+e1.toString());
}//判断文件是否存在,存在则追加,否则新增//todo:
File file = new File(filepath+"/"+filename);
XSSFWorkbook wb=null;
XSSFSheet sheet= null;
InputStream input= null;
FileOutputStream output=null;try{
wb= newXSSFWorkbook();
input= newFileInputStream(file);
wb=(XSSFWorkbook) WorkbookFactory.create(input);if(wb != null){//获取文件的指定工作表
sheet =wb.getSheet("job");
output= new FileOutputStream(filepath+"/"+filename,false);//获取最大行数//int rownum = sheet.getPhysicalNumberOfRows();
int index = sheet.getLastRowNum()+1;
logger.info("index>>>:"+index);
String cmdStr= "";if(list.size() > 0){for(int i = 0; i < list.size(); i++){
cmdStr= "";if("自然日".equals(list.get(i).getDataType())){
cmdStr= "sh "+pan_path+"/"+list.get(i).getSysName()+"/"+list.get(i).getPanName()+".sh -p${yes_date} -s${yes_date} -e${curr_date}";
}else if("交易日".equals(list.get(i).getDataType())){
cmdStr= "sh "+pan_path+"/"+list.get(i).getSysName()+"/"+list.get(i).getPanName()+".sh -p${start_date} -s${start_date} -e${end_date}";
}//插入excle
XSSFRow row = null;
row= sheet.createRow(index+i);
XSSFCell cell_flow= row.createCell(0);
XSSFCell cell_job= row.createCell(2);
XSSFCell cell_cmd= row.createCell(6);
cell_flow.setCellValue("F_gp_"+list.get(i).getSysName());
cell_job.setCellValue("J_gp_"+list.get(i).getTableName());
cell_cmd.setCellValue(cmdStr);
}
}else{
logger.info("待处理数据为空");
}
output.flush();
wb.write(output);if (input != null){
input.close();
}
output.close();
}
}catch(Exception e) {//TODO Auto-generated catch block
e.printStackTrace();
logger.info("makeExcle>获取exlce数据异常:"+e.toString());
}
logger.info("生成excle:end");
}