如何把jxl excel 变成 poi的 excel excel的表样是固定的 求大神解答 怎么改 5C

public void downloadReport1(HttpServletResponse response,String time){
// File file = new File("/home/ydzxrpt/modelfile/86.xls");
File file = new File("H:\Desktop\86.xls");
// File file1 = new File("/home/ydzxrpt/modelfile/86write.xls");
File file1 = new File("H:\Desktop\86write.xls");
Date date = new Date(Long.valueOf(time));
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMM");
String formatDate = sdf.format(date);
String formatMonth = sdf1.format(date);
try {
Workbook workbook = Workbook.getWorkbook(file);
WritableWorkbook workbook1 = Workbook.createWorkbook(file1,workbook);
WritableSheet sheet1 = workbook1.getSheet(0);
Sheet sheet = workbook.getSheet(0);
String sql = "SELECT * FROM RPT_86HL_OPERATE_ZB_D where OP_TIME like '%"+formatDate+"%' or OP_TIME= '"+formatMonth+"' ORDER BY OP_TIME\n ";
List> maps = jdbcTemplate.queryForList(sql);
int firstXIndex = 2;
int firstYIndex = 1;
WritableFont wf = new WritableFont(WritableFont.ARIAL, 11, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE);
WritableCellFormat wcf = new WritableCellFormat(wf);
wcf.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
for (Map map : maps){
for (String key : map.keySet()) {
if(Objects.equals(key,"OP_TIME")){
String value = (String)map.get(key);
if(value.length() == 6){
String substring = value.substring(4,5);
if(Objects.equals(substring,"0")){
value = value.substring(5)+"月目标";
}else{
value = value.substring(4)+"月目标";
}
map.put(key,value);
}
if(value.length() == 8){//20180904
String substring = value.substring(4,5);
String value1 ="";
if(Objects.equals(substring,"0")){
value1 = value.substring(5,6)+"月";
}else{
value1 = value.substring(4,6)+"月";
}
String substring1 = value.substring(6,7);
if(Objects.equals(substring1,"0")){
value1 +=value.substring(7,8)+"日";
}else{
value1 +=value.substring(6,8)+"日";
}
value = value1;
map.put(key,value);
}
if(value.length() == 10){//2018090430
String substring = value.substring(4,5);
if(Objects.equals(substring,"0")){
value = value.substring(5,6)+"月累计";
}else{
value = value.substring(4,6)+"月累计";
}
map.put(key,value);
}
}
WritableCell wc = new Label(firstXIndex, firstYIndex, (String)map.get(key), wcf);
sheet1.addCell(wc);
firstYIndex++;
}
firstYIndex =1;
firstXIndex++;
}
workbook1.write();
workbook1.close();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file1));
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
HttpUtils.buildDownloadResponseHeader(response,"86热线运营指标日跟踪表.xls");
int length;
byte[] buf = new byte[1024];
while ((length = bis.read(buf)) > 0) {
bos.write(buf, 0, length);
}
bis.close();
bos.flush();
bos.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
0

1个回答

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!