关于java excel导出的问题,请大神们指教

问题描述

正常来说在wwb.write();wwb.close();这两个时候页面会弹出一个下载的页面但是现在wwb.close();执行之后没有弹出下载页面并且页面会出现页面无法显示后台报出这个错误这个应该如何解决网上修改连接数什么的方法都试过了ClientAbortException:java.net.SocketException:Connectionresetbypeer:socketwriteerroratorg.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)atorg.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:354)atorg.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381)atorg.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)atorg.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)atjxl.write.biff.MemoryDataOutput.writeData(MemoryDataOutput.java:107)atjxl.write.biff.CompoundFile.writeExcelData(CompoundFile.java:505)atjxl.write.biff.CompoundFile.write(CompoundFile.java:455)atjxl.write.biff.File.close(File.java:120)atjxl.write.biff.WritableWorkbookImpl.close(WritableWorkbookImpl.java:447)atcom.brainlong.psi.wanda.depot.depotmanage.ShowDepotManageForSGAction.exportShipmentItemListDetail(ShowDepotManageForSGAction.java:1748)atcom.brainlong.psi.wanda.depot.depotmanage.ShowDepotManageForSGAction.exportShipmentItemListDetail(ShowDepotManageForSGAction.java:496)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)atorg.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)atcom.brainlong.framework.struts.BaseDispatchAction.execute(BaseDispatchAction.java:97)atorg.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)atorg.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)atorg.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)atorg.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)atorg.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:617)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atcom.brainlong.psi.global.filter.LoginFilter.doFilter(LoginFilter.java:71)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atcom.brainlong.framework.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:39)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)atjava.lang.Thread.run(Thread.java:662)Causedby:java.net.SocketException:Connectionresetbypeer:socketwriteerroratjava.net.SocketOutputStream.socketWrite0(NativeMethod)atjava.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)atjava.net.SocketOutputStream.write(SocketOutputStream.java:136)atorg.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:740)atorg.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)atorg.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349)atorg.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:764)atorg.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:126)atorg.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:573)atorg.apache.coyote.Response.doWrite(Response.java:560)atorg.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:353)...43moreWritableWorkbookwwb=null;try{OutputStreamos=response.getOutputStream();//创建Excel工作表wwb=Workbook.createWorkbook(os);//创建sheetWritableSheetws=wwb.createSheet("出入库单据详情",0);//合并单元格(左列,左行,右列,右行)从第1行第1列到第2行第4列ws.mergeCells(0,0,17,1);Labelheader=newLabel(0,0,"出入库单据详情",ExportUtils.getHeader());ws.addCell(header);ws.mergeCells(0,2,17,2);Labell=newLabel(0,2,"导出时间:"+DateUtils.formatCurrentDate(DateUtils.DATE_PATTERN_YYYYMMDDHHmmss_2),ExportUtils.getTitle());//第3列ws.addCell(l);intk=0;l=newLabel(k++,3,"供货商名称",ExportUtils.getTitle());//第3行,第2列ws.addCell(l);......intres=0;ws.setColumnView(res++,30);ws.setColumnView(res++,15);//隐藏ws.setColumnView(res++,15);//隐藏......for(inti=0;i<list.size();i++){inth=0;ShipmentItemValueshipmentItemValue=list.get(i);if(shipmentItemValue!=null){l=newLabel(h++,i+4,shipmentItemValue.getSupplierName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getOutStore(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getOutFacility(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getInStore(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getInFacility(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getShipmentTypeName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);//l=newLabel(h++,i+4,shipmentItemValue.getShipmentId().toString(),ExportUtils.getNormolCell());//第2行,第6列l=newLabel(h++,i+4,shipmentItemValue.getSerialNumber().toString(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getDocumentDate().toString(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getEstimatedShipDate().toString(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getProductCategoryCode(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getProductCategoryName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getProductCode(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getProductName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,null==shipmentItemValue.getSpecification()?"":shipmentItemValue.getSpecification(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getUomTypeName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getQuantity().setScale(6,BigDecimal.ROUND_HALF_UP)+"",ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getUnitPrice().setScale(6,BigDecimal.ROUND_HALF_UP)+"",ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getAmount().setScale(6,BigDecimal.ROUND_HALF_UP)+"",ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);}}wwb.write();wwb.close();os.flush();os.close();}catch(Exceptione){e.printStackTrace();}

解决方案

解决方案二:
wwb.write();wwb.close();os.flush();os.close();

建议把close写在finally块里。而且你的顺序似乎也有问题,wwb在osflush之前就关掉了。。。
解决方案三:
一开始报错的原因找到了是因为导出过程中有点了一次导出按钮冲突造成的但是那个显示无法找到页面的原因还是存在就是代码执行到wwb.close();的时候不弹出下载页面
解决方案四:
一下午我也在解决这个问题,wwb.write();wwb.close();os.flush();os.close();事实证明wwb和os的先后顺序并不影响。我最初在j代码里直接写的window.location.href=“导出execl的执行路径”,如此是可以下载文件的,后来自己优化用ajax的JSON提交,开始抛出上述的错误,最终无奈又改了回去,不过有一个问题一直未解决,就是返回时的路径一直都报错(我用的是struts2的框架)。
解决方案五:
javaexcel导出不支持ajax提交的吧?貌似只能用location.href=
解决方案六:
不支持ajax提交,后台加上response.setContentType("application/vnd.ms-excel;charset=utf-8");
解决方案七:
wwb.write(os);os不关闭
解决方案八:
创建的work的时候读进来的应该是你的excel的模板,不应该是输出流,读取模板模板用输入流,最后wbb.write(out)

时间: 2024-07-28 16:50:06

关于java excel导出的问题,请大神们指教的相关文章

php-PHP转Java该怎么实现,请大神帮忙

问题描述 PHP转Java该怎么实现,请大神帮忙 protected function _postWithCookie($uri $data){ $fp = fsockopen('f.10086.cn' 80); fputs($fpPOST $uri HTTP/1.1rn""); fputs($fpHost: f.10086.cnrn""); fputs($fpCookie: {$this->_cookie}rn""); fputs($fp

数据转化-java的数据转换问题,请大神帮我看一下

问题描述 java的数据转换问题,请大神帮我看一下 今天看到书上讲到数据转化,我看不懂,拍给大家,请大家帮我解释一下,谢谢 解决方案 在用system.out.println时会自动转换,你也可以用(float)进行强制转换 解决方案二: java中,两个数运算时,如果类型不同,自动会转成类型相同,如果是int和float计算,则两个数都会转成float后再计算.第一张图a/b会有小数 第二张图 a,b都是整型,除法后a/b取整再转float.所以小数都是0,是因为是a/b除后舍去了小数. 解决

java单例模式写法的问题, 请大神!

问题描述 java单例模式写法的问题, 请大神! 第一种写法: public class LoginService{ private static LoginService instance; public static LoginService getInstance() { if (instance == null) { synchronized (LoginService.class) { if (instance == null) { instance = new LoginServic

麻将游戏-谁有麻将计算番数的java的代码?希望各位大神给予指教!!!谢谢

问题描述 谁有麻将计算番数的java的代码?希望各位大神给予指教!!!谢谢 谁有写过麻将游戏,用java写的,计算番数这块卡住了,希望各位能给予帮助,指点迷津!

求解决-c语言问题求解,请大神们指教

问题描述 c语言问题求解,请大神们指教 本题要求实现一个对数组进行循环右移的简单函数:一个数组aa中存有nn(>0>0)个整数,将每个整数循环向右移mm(ge 0≥0)个位置,即将aa中的数据由(a_0 a_1 cdots a_{n-1}a ?0 ?? a ?1 ?? ?a ?n?1 ?? )变换为(a_{n-m} cdots a_{n-1} a_0 a_1 cdots a_{n-m-1}a ?n?m ?? ?a ?n?1 ?? a ?0 ?? a ?1 ?? ?a ?n?m?1 ?? )(最

php dwt 写的jquery不执行回调,html可以执行回调,请大神们指教。

问题描述 php dwt 写的jquery不执行回调,html可以执行回调,请大神们指教. 模版文件dwt 写了如下js代码,为什么没有回调,写在html 里就可以回调 function getVal() { $.getJSON("bus_sel.php", { sf_id : $("#sf_id").val() }, function(json) { alert(1111); var ds_id = $("#ds_id"); $.each(js

c++-Lua和C++交互 请大神们指教下 在线等

问题描述 Lua和C++交互 请大神们指教下 在线等 在使用python genbindings.py进行Lua和C++的ini文件桥接时候类里面使用到一个虚函数的参数是另一个类的枚举值结果编译出现raise Exception("The namespace (%s) conversion wasn't set in 'ns_map' section of the conversions.yaml" % namespace_class_name) Exception: The name

android Toast编程遇到问题,请大神们指教

问题描述 提示错误:ThemethodmakeText(Context,CharSequence,int)inthetypeToastisnotapplicableforthearguments(newRunnable(){},String,int)部分代码:publicvoidonCreate(){super.onCreate();finalStringfirst0=newString(getTopActivity());newThread(newRunnable(){@Overridepub

关于java越界的问题。。。。请大神解答

问题描述 关于java越界的问题....请大神解答 public class Solution { public String getHint(String secret, String guess) { int bulls=0; int cows=0; char[] sec = secret.toCharArray(); char[] gue = guess.toCharArray(); int[] s=new int[10]; int[] g=new int[10]; for(int i=0