向exls表中写入数据

一、向exls表中写入数据

包:org.apache.poi.hssf.usermodel.HSSFRow;
        org.apache.poi.hssf.usermodel.HSSFCell;
        org.apache.poi.hssf.usermodel.HSSFSheet;
        org.apache.poi.hssf.usermodel.HSSFWorkbook;
        javax.servlet.ServletOutputStream;


/**以下是向excel模板中写项目记录**/
File f = new File(Project.root + "template/project.xls");
FileInputStream file = new FileInputStream(f);
HSSFWorkbook wbs = new HSSFWorkbook(file);
HSSFSheet sheet = wbs.getSheet("项目信息表");
/**日期格式器**/
SimpleDateFormat formater = new SimpleDateFormat("yyyy年MM月dd日");
String data = formater.format(new Date());
String fileName = "项目局点信息表" + data;
fileName = new String(fileName.getBytes("gbk"), "ISO-8859-1");
/**设置数据类型为CSV-excel**/
response.setContentType("text/csv; charset=GBK");
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "must-revalidate");
response.setDateHeader("Expires", 0);
response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xls");
/**开始构造excel表格的行并写数据**/
for(int i = 0 ; i < list.size() ; i ++){
ImportExportProjectRecord rowRecord = list.get(i);
HSSFRow row = sheet.createRow(i + 2);
HSSFCell cell = row.createCell(0);

/**项目名称列**/
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(rowRecord.getBur_project_name());

/**项目状态**/
cell = row.createCell(1);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(rowRecord.getBur_state());

/**所属域**/
cell = row.createCell(2);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(rowRecord.getBur_line());

/**所在地区**/
cell = row.createCell(3);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(rowRecord.getBur_area());

/**国家**/
cell = row.createCell(4);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(rowRecord.getBur_country());



/**运营商名称**/
cell = row.createCell(5);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(rowRecord.getBur_operator());


/**所属项目**/
cell = row.createCell(6);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(rowRecord.getProject());


/**项目重要性**/
cell = row.createCell(7);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(rowRecord.getBur_importence());
}
ServletOutputStream out = response.getOutputStream();
wbs.write(out);



二、读取oracle中Clob数据类型中的数据
String project_des = null;
Clob  clob = result.getClob("project_des");
Reader inStream = clob.getCharacterStream();
        char[] c = new char[(int) clob.length()];
        try {
inStream.read(c);
project_des = new String(c);
        inStream.close();
} catch (IOException e) {
e.printStackTrace();
} 


你可能感兴趣的:(oracle,c,Date,String,Excel,File)