关于POI运用于WEBpoi导出excel 模板,出现文件格式或者文件扩展名无效

当前位置: >
> 运用poi导出excel的基本action操作
运用poi导出excel的基本action操作
xishairuankao & at
应用poi导出excel的基本action操作
  实体bean(SingleMonthData[set/get]):
   private long
private String classN private Date
lastUpdateT private String
lastUpdateU private long
month1; private long
month2; private long
month3; private long
month4; private long
month5; private long
month6; private long
month7; private long
month8; private long
month9; private long
month10; private long
month11; private long
month12; private TotalMonthData MonthD
  实体bean(KeyValue/set*/get*):private S private S
  public interface
Constract {  static final KeyValue [] EXCEL_COLUMN_NAME = {  new KeyValue("ClassName", "工单类型"),  new KeyValue("Month1", "1月"), //Month1...字段,1月,为标题  new KeyValue("Month2", "2月"),  new KeyValue("Month3", "3月"),  new KeyValue("Month4", "4月"),  new KeyValue("Month5", "5月"),  new KeyValue("Month6", "6月"),  new KeyValue("Month7", "7月"),  new KeyValue("Month8", "8月"),  new KeyValue("Month9", "9月"),  new KeyValue("Month10", "10月"),  new KeyValue("Month11", "11月"),  new KeyValue("Month12", "12月") };}
  ACTION:
  public void exportExcel(HttpServletRequest request,HttpServletResponse response) throws RemoteException,Exception{  
request.setCharacterEncoding("UTF-8");  
response.setContentType("text/chartset=UTF-8");  
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");  
String yearTime = request.getParameter("yearTime")==null sdf.format(new Date()):request.getParameter("yearTime");  String classId = request.getParameter("classId")==null "":request.getParameter("classId");  String opflag = request.getParameter("opflag")==null "":request.getParameter("opflag");  String excelFileName = "";  HSSFW  IFlowWorkplanStatisticsSV
statisticsValues = (IFlowWorkplanStatisticsSV)ServiceFactory.getService(IFlowWorkplanStatisticsSV.class);  //open|close  if("firstpage".equals(opflag)){//totalSum  IFlowWorkplanStatisticsValue[] fwsBeans = statisticsValues.queryFlowWorkplan(yearTime);  SingleMonthData[] monthDatas = this.initsMonthDatas(fwsBeans);  String tmp = yearTime+"年流程工单合计量.xls";  excelFileName = new String(tmp.getBytes(),"ISO-8859-1");  hwb = this.grenteExcel(monthDatas,excelFileName);  }else{  IFlowWorkplanTranStatisticsValue[] tranStatisticsValues = statisticsValues.queryFlowWorkplanTranStatistics(yearTime, classId);  IFlowWorkplanStatisticsValue[] fwsBeans = statisticsValues.queryFlowWorkplanGraph(yearTime, classId);  SingleMonthData[] monthDatas = this.initsMonthDatas(tranStatisticsValues);  String tmp = yearTime+"年流程"+fwsBeans[0].getClassName()+"工单量.xls";  excelFileName = new String(tmp.getBytes(),"ISO-8859-1");  hwb = this.grenteExcel(monthDatas,excelFileName);  }  response.reset();  response.setContentType("contentType=application/vnd.ms-excel");  response.setHeader("Content-Disposition", "filename=\"" + excelFileName + "\"");  hwb.write(response.getOutputStream());  response.flushBuffer(); 
  public SingleMonthData[] initsMonthDatas(Object[] obj){   SingleMonthData[] monthDatas = new SingleMonthData[obj.length];   if(obj instanceof IFlowWorkplanStatisticsValue[]){  
IFlowWorkplanStatisticsValue[] fwsBeans
(FlowWorkplanStatisticsBean[])
  for(int i=0;i&obj.i++){   SingleMonthData singleMonthData = new SingleMonthData();   singleMonthData.setClassName(fwsBeans[i].getClassName());   singleMonthData.setMonth1(fwsBeans[i].getMonth1());   singleMonthData.setMonth2(fwsBeans[i].getMonth2());   singleMonthData.setMonth3(fwsBeans[i].getMonth3());   singleMonthData.setMonth4(fwsBeans[i].getMonth4());   singleMonthData.setMonth5(fwsBeans[i].getMonth5());   singleMonthData.setMonth6(fwsBeans[i].getMonth6());   singleMonthData.setMonth7(fwsBeans[i].getMonth7());
  singleMonthData.setMonth8(fwsBeans[i].getMonth8());   singleMonthData.setMonth9(fwsBeans[i].getMonth9());   singleMonthData.setMonth10(fwsBeans[i].getMonth10());   singleMonthData.setMonth11(fwsBeans[i].getMonth11());   singleMonthData.setMonth12(fwsBeans[i].getMonth12());   monthDatas[i] = singleMonthD  }   }else if(obj instanceof IFlowWorkplanTranStatisticsValue[]){  
IFlowWorkplanTranStatisticsValue[] fwsBeans
(FlowWorkplanTranStatisticsBean[])  for(int i=0;i&obj.i++){   SingleMonthData singleMonthData = new SingleMonthData();   singleMonthData.setClassName(fwsBeans[i].getTypeName());   singleMonthData.setMonth1(fwsBeans[i].getMonth1());   singleMonthData.setMonth2(fwsBeans[i].getMonth2());   singleMonthData.setMonth3(fwsBeans[i].getMonth3());   singleMonthData.setMonth4(fwsBeans[i].getMonth4());   singleMonthData.setMonth5(fwsBeans[i].getMonth5());   singleMonthData.setMonth6(fwsBeans[i].getMonth6());   singleMonthData.setMonth7(fwsBeans[i].getMonth7());
  singleMonthData.setMonth8(fwsBeans[i].getMonth8());   singleMonthData.setMonth9(fwsBeans[i].getMonth9());   singleMonthData.setMonth10(fwsBeans[i].getMonth10());   singleMonthData.setMonth11(fwsBeans[i].getMonth11());   singleMonthData.setMonth12(fwsBeans[i].getMonth12());   monthDatas[i] = singleMonthD  }   }   return monthD 
  public
HSSFWorkbook grenteExcel(Object[] obj,String fileName){  ExcelHelper
excelHelper = new ExcelHelper();  HSSFWorkbook wbWorkbook = excelHelper.item2excel(obj, Constract.EXCEL_COLUMN_NAME,"流程工单量");  HSSFSheet sheet = wbWorkbook.getSheetAt(0);
  sheet.setColumnWidth((short)0, (short)7000);  sheet.setColumnWidth((short)1, (short)3000);  sheet.setColumnWidth((short)2, (short)3000);  sheet.setColumnWidth((short)3, (short)3000);  sheet.setColumnWidth((short)4, (short)3000);  sheet.setColumnWidth((short)5, (short)3000);  sheet.setColumnWidth((short)6, (short)3000);  sheet.setColumnWidth((short)7, (short)3000);  sheet.setColumnWidth((short)8, (short)3000);  sheet.setColumnWidth((short)9, (short)3000);  sheet.setColumnWidth((short)10, (short)3000);  sheet.setColumnWidth((short)11, (short)3000);  sheet.setColumnWidth((short)12, (short)3000);  return wbW  }
  function exportExcel(){ 
var opflag = $("#opflag").val(); var yearTime = $("#yearTime").val(); var classId = $("#classId").val(); window.location.href = path+"/business/com.*.statistics.web.action.StatisticsAction action=exportExcel&yearTime="+yearTime+"&classId="+classId+"&opflag="+}
  &a #" onclick="exportExcel();" class="excel"&导出成XLS&/a&
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&&&湘教QS2-164&&增值电信业务经营许可证湘B2-MVC导出Excel .xlsx提示文件格式或文件扩展名无效
[问题点数:20分]
MVC导出Excel .xlsx提示文件格式或文件扩展名无效
[问题点数:20分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
2012年 总版技术专家分年内排行榜第一
2013年 总版技术专家分年内排行榜第七2011年 总版技术专家分年内排行榜第五2009年 总版技术专家分年内排行榜第九
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。excel2012版的出现因文件格式或者文件扩展名无效,打不来怎么办_百度知道
excel2012版的出现因文件格式或者文件扩展名无效,打不来怎么办
/zhidao/pic/item/63d9f2d3fc5eef603c215.baidu.jpg" target="_blank" title="点击查看大图" class="ikqb_img_alink"><img class="ikqb_img" src="http.baidu.hiphotos://a<a href="/zhidao/wh%3D450%2C600/sign=4f0eeeb9acdfedb/63d9f2d3fc5eef603c215.hiphotos://a.com/zhidao/wh%3D600%2C800/sign=68ad857d6baaebd9f2d3fc5eef603c215://a.jpg" esrc="http.baidu
提问者采纳
把文件,后面的两个.xlsx 删除掉一个再打开试试
提问者评价
我试了还是不行,这个文件是损坏的打不开了 谢谢
其他类似问题
文件扩展名的相关知识
按默认排序
其他1条回答
两个扩展名是不识别的。
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}

我要回帖

更多关于 poi导出excel实例 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信