apache-poi导出excel中图片怎样才能不随单元格大小变化而变化

需求是在导出的excel中添加一张图片,图片的高度和excel第一行单元格的高度相同,宽度是这张图片根据高度变化等比例缩放后的结果。现在我是直接导入了一个带图片的excel模板,但是只要第一个列单元格宽度变化这张图片就会等比例变形。求问怎么才能解决?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
apache poi导出excel里的dataformat的格式怎么理解?

apache poi导出excel时,可能需要设计数据格式。 通过 CellStyle.setDataFormat(format.getFormat( 格式)); 来实现,但是这个格式里面的内容是什么意思,比如 [$¥-804]#,##0.00;[RED]-[$¥-804]#,##0.00 这个里面的各个字符都起什么作用,比如那个中括号,¥-804,#,还有井号中间的逗号。 我也见过类似 ¥#,##0.00这样的,说是保留两位货币格式,后面为什么要加0.00,前面的#,##又是代表什么意思。我发现写成#,#或者##,#都没什么区别。 望大佬能解决我的疑问,谢谢

POI导出excel的单元格合并是假合并怎么解决??

![图片说明](https://img-ask.csdn.net/upload/201508/24/1440410782_188927.png) 如同代码合并了Excel也能看出合并了,但是为什么计数就是不是1呢?怎么解决???

POI 生成Excel时,怎么限制 单元格输入长度的限制啊?

POI 生成Excel时,怎么限制 单元格输入长度的限制啊?

java poi导出excel文档 后台报下标越界 但文档正常导出且损坏

public static SXSSFWorkbook createCSVUtil2(int startRow, String sheetName, SXSSFWorkbook wb, Map<String, List<CellModel>> cellListMap, Integer cellRowNum, List<LinkedHashMap> exportData, int[] columnWidth, int totalcolumn, GgreportingtemplateDto ggreportingtemplateDto, int countRow) throws Exception { // 设置表格名称 SXSSFSheet sheet = (SXSSFSheet) wb.createSheet(sheetName); sheet.trackAllColumnsForAutoSizing(); // 设置表格标题 一般都是第一行第一个格子 // 标题样式 if (ggreportingtemplateDto.getTitle() != null) { XSSFCellStyle cellStyleTitle = (XSSFCellStyle) wb.createCellStyle(); cellStyleTitle.setWrapText(true); SXSSFRow rowTitle = (SXSSFRow) sheet.createRow(0); XSSFFont fontTitle = (XSSFFont) wb.createFont(); fontTitle.setFontHeightInPoints((short) 16); cellStyleTitle.setFont(fontTitle); // 合并标题单元格 sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, totalcolumn - 1)); for (int i = 0; i < totalcolumn; i++) { if (i == 0) { SXSSFCell cell = (SXSSFCell) rowTitle.createCell(0); cell.setCellValue(ggreportingtemplateDto.getTitle()); cell.setCellStyle(cellStyleTitle); } else { SXSSFCell cell = (SXSSFCell) rowTitle.createCell(i); cell.setCellStyle(cellStyleTitle); } } } if (ggreportingtemplateDto.getCondition() != null) { // 设置筛选条件格子 一般是第二行第一列 // 条件样式 XSSFCellStyle cellStyleCondition = (XSSFCellStyle) wb.createCellStyle(); cellStyleCondition.setWrapText(true); SXSSFRow rowCondition = (SXSSFRow) sheet.createRow(1); XSSFFont fontCondition = (XSSFFont) wb.createFont(); fontCondition.setFontHeightInPoints((short) 16); cellStyleCondition.setFont(fontCondition); // 合并条件单元格 sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 4)); for (int i = 0; i < 4; i++) { if (i == 0) { SXSSFCell cell = (SXSSFCell) rowCondition.createCell(0); cell.setCellValue(ggreportingtemplateDto.getCondition()); cell.setCellStyle(cellStyleCondition); } else { SXSSFCell cell = (SXSSFCell) rowCondition.createCell(i); cell.setCellStyle(cellStyleCondition); } } } // 设置表格通用样式 XSSFCellStyle cellStyle = (XSSFCellStyle) wb.createCellStyle(); // 设置边框 // 设置单元格内容水平对齐 cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 设置单元格内容垂直对齐 cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 设置自动换行 cellStyle.setWrapText(true); // 设置双边框 XSSFCellStyle cellStyleDouble = (XSSFCellStyle) wb.createCellStyle(); // 设置边框 // 设置单元格内容水平对齐 cellStyleDouble.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 设置单元格内容垂直对齐 cellStyleDouble.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 设置自动换行 cellStyleDouble.setWrapText(true); // 合并单元格 for (int t = 0; t < cellRowNum; t++) { SXSSFRow row = (SXSSFRow) sheet.createRow(t + startRow); List<CellModel> cellNameList = cellListMap.get(String.valueOf(t)); for (CellModel cellModel : cellNameList) { // 如果被合并的元素只占用了一个单元格则不进行合并 if (cellModel.getStartColumn() == cellModel.getEndColumn() && cellModel.getEndRow() == cellModel.getStartRow()) { continue; } sheet.addMergedRegion(new CellRangeAddress(cellModel.getStartRow(), cellModel.getEndRow(), cellModel.getStartColumn(), cellModel.getEndColumn())); } // create的cell Set<Integer> create = new HashSet<Integer>(); for (int i = 0; i < cellNameList.size(); i++) { CellModel cellModel = cellNameList.get(i); // 遍历插入表头 SXSSFCell cell = (SXSSFCell) row.createCell(cellModel.getStartColumn()); // 设置字体 XSSFFont font = (XSSFFont) wb.createFont(); font.setFontName("Times New Roman"); font.setFontHeightInPoints((short) 8); // 设置行高 if (i == 1) { row.setHeight((short) 500); } cellStyle.setFont(font); cell.setCellValue(cellModel.getCellName()); cell.setCellStyle(cellStyle); create.add(cellModel.getStartColumn()); } // 把所有没有create的cell都create for (int i = 0; i < totalcolumn; i++) { if (!(create.contains(i))) { // 设置字体 XSSFFont font = (XSSFFont) wb.createFont(); font.setFontName("Times New Roman"); font.setFontHeightInPoints((short) 8); cellStyle.setFont(font); SXSSFCell cell = (SXSSFCell) row.createCell(i); cell.setCellStyle(cellStyle); } } } for (LinkedHashMap hashMap : exportData) { SXSSFRow rowValue = (SXSSFRow) sheet.createRow(cellRowNum + startRow); Iterator<Map.Entry> iteratorRow = hashMap.entrySet().iterator(); while (iteratorRow.hasNext()) { Map.Entry entryRow = iteratorRow.next(); Integer key = Integer.valueOf(entryRow.getKey().toString()); String value = ""; if (entryRow.getValue() != null) { value = entryRow.getValue().toString(); } else { value = ""; } SXSSFCell cellValue = (SXSSFCell) rowValue.createCell(key - 1); // 设置字体 XSSFFont font = (XSSFFont) wb.createFont(); font.setFontName("Times New Roman"); font.setFontHeightInPoints((short) 8); cellValue.setCellValue(value); cellStyle.setFont(font); cellValue.setCellStyle(cellStyle); } cellRowNum++; } // 设置备注栏 List<String> reMarkList = ggreportingtemplateDto.getRemake(); if (reMarkList != null) { for (int i = 0; i < reMarkList.size() + 1; i++) { int rowNum = i + startRow + cellRowNum + 1; XSSFCellStyle cellStyleRemake = (XSSFCellStyle) wb.createCellStyle(); SXSSFRow rowRemake = (SXSSFRow) sheet.createRow(rowNum); XSSFFont fontRemake = (XSSFFont) wb.createFont(); fontRemake.setFontHeightInPoints((short) 8); cellStyleRemake.setFont(fontRemake); String cellValue = "Notes:"; // 合并条件单元格 if (i != 0) { sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 4)); cellValue = reMarkList.get(i - 1); SXSSFCell cell = (SXSSFCell) rowRemake.createCell(0); cell.setCellValue(cellValue); cell.setCellStyle(cellStyleRemake); } else { SXSSFCell cell = (SXSSFCell) rowRemake.createCell(0); cell.setCellValue(cellValue); cell.setCellStyle(cellStyleRemake); } } } // 设置列宽 if (columnWidth != null) { for (int i = 0; i < columnWidth.length; i++) { sheet.setColumnWidth(i, columnWidth[i]); } } return wb; } 以上是我生成sheet表的内容 //exceptional Rpt public SXSSFWorkbook exceptionalRpt (GgreportingtemplateDto ggreportingtemplateDto, String startInputDate,String endInputDate) throws Exception { // 设置最大数据行数 SXSSFWorkbook wb = new SXSSFWorkbook(5050);//这里之前看到是说能设置这个表格最多能含有多少数据 Map<String, List<CellModel>> map = new HashMap<String, List<CellModel>>(); // 设置数据 // 第一级表头 List<CellModel> firstRow = new ArrayList<CellModel>(); CellModel cellModel1 = new CellModel(); // 总占用1行 Integer cellRow = 1; cellModel1.setCellName("Member English Name"); cellModel1.setStartRow(0); cellModel1.setEndRow(0); cellModel1.setStartColumn(0); cellModel1.setEndColumn(0); CellModel cellModel2 = new CellModel(); cellModel2.setCellName("Member Chinese Name"); cellModel2.setStartRow(0); cellModel2.setEndRow(0); cellModel2.setStartColumn(1); cellModel2.setEndColumn(1); CellModel cellModel3 = new CellModel(); cellModel3.setCellName("Staff No."); cellModel3.setStartRow(0); cellModel3.setEndRow(0); cellModel3.setStartColumn(2); cellModel3.setEndColumn(2); CellModel cellModel4 = new CellModel(); cellModel4.setCellName("HKID/Passport No."); cellModel4.setStartRow(0); cellModel4.setEndRow(0); cellModel4.setStartColumn(3); cellModel4.setEndColumn(3); CellModel cellModel5 = new CellModel(); cellModel5.setCellName("Sex"); cellModel5.setStartRow(0); cellModel5.setEndRow(0); cellModel5.setStartColumn(4); cellModel5.setEndColumn(4); CellModel cellModel6 = new CellModel(); cellModel6.setCellName("Plan Code"); cellModel6.setStartRow(0); cellModel6.setEndRow(0); cellModel6.setStartColumn(5); cellModel6.setEndColumn(5); CellModel cellModel7 = new CellModel(); cellModel7.setCellName("Plan Description"); cellModel7.setStartRow(0); cellModel7.setEndRow(0); cellModel7.setStartColumn(6); cellModel7.setEndColumn(6); CellModel cellModel8 = new CellModel(); cellModel8.setCellName("Effective Date"); cellModel8.setStartRow(0); cellModel8.setEndRow(0); cellModel8.setStartColumn(7); cellModel8.setEndColumn(7); CellModel cellModel9 = new CellModel(); cellModel9.setCellName("Status"); cellModel9.setStartRow(0); cellModel9.setEndRow(0); cellModel9.setStartColumn(8); cellModel9.setEndColumn(8); firstRow.add(cellModel1); firstRow.add(cellModel2); firstRow.add(cellModel3); firstRow.add(cellModel4); firstRow.add(cellModel5); firstRow.add(cellModel6); firstRow.add(cellModel7); firstRow.add(cellModel8); firstRow.add(cellModel9); map.put("0", firstRow); // 业务数据 List<LinkedHashMap> exportData = new ArrayList<LinkedHashMap>(); GuPolicyCopyItemMedgMembDto guPolicyCopyItemMedgMembDto = new GuPolicyCopyItemMedgMembDto(); List<GuPolicyCopyItemMedgMembDto> list = ServiceManager.prpall.getGuPolicyCopyItemMedgMembService().findALL(guPolicyCopyItemMedgMembDto, null);//这里查询出来是295条 //增加数据 用这端代码增加5000条数据 /*for (int i = 0; i < 5000; i++) { list.add((GuPolicyCopyItemMedgMembDto)list.get(0)); }*/ int countRow = 0; for (int i = 0; i < list.size(); i++) { GuPolicyCopyItemMedgMembDto data = (GuPolicyCopyItemMedgMembDto) list.get(i); LinkedHashMap<String,String> row = new LinkedHashMap<String,String>(); String struts = ""; String ename = ""; String cname = ""; String idno = ""; String staffno = ""; String sex = ""; String rationType = ""; String rationName = ""; String entryDate = ""; String chineseName = ""; String hKIDandPassportNo = ""; if(data.getFlag()==null||data.getFlag().equals("I")) { struts = "Add"; }else if(data.getFlag().equals("U")){ struts = "Amendment"; }else if(data.getFlag().equals("D")){ struts = "Deletion"; }else if(data.getFlag().equals("B")){ struts = "Cancellation"; } if(data.getClientEName() != null&&!(data.getClientEName().equals(""))) { ename = data.getClientEName(); } if(data.getClientCName() != null&&!(data.getClientCName().equals(""))) { cname = data.getClientCName(); } if(data.getIdNo() != null&&!(data.getIdNo().equals(""))) { idno = data.getIdNo(); } if(data.getStaffNo() != null&&!(data.getStaffNo().equals(""))) { staffno = data.getStaffNo(); } if(data.getSex() != null&&!(data.getSex().equals(""))) { sex = data.getSex(); } if(data.getRationType() != null&&!(data.getRationType().equals(""))) { rationType = data.getRationType(); } if(data.getRationName() != null&&!(data.getRationName().equals(""))) { rationName = data.getRationName(); } if(data.getEntryDate() != null) { entryDate = sim.format(data.getEntryDate()); } /*row.put("1", ""+ename+""); row.put("2", ""+cname+""); row.put("3", ""+staffno+""); row.put("4", ""+idno+""); row.put("5", ""+sex+""); row.put("6", ""+rationType+""); row.put("7", ""+rationName+""); row.put("8", ""+entryDate+""); row.put("9", ""+struts+"");*/ row.put("1", "1"); row.put("2", "2"); row.put("3", "3"); row.put("4", "4"); row.put("5", "5"); row.put("6", "6"); row.put("7", "7"); row.put("8", "8"); row.put("9", "9"); exportData.add(row); countRow++; } // 用于写入文件 // 列宽数组 int[] columnWidth = { 10000, 7500, 5000, 7500, 5000, 7500, 10000, 5000, 5000 }; // 报表标题 ggreportingtemplateDto.setTitle(null); List<String> remakeList = null; // 报表备注 ggreportingtemplateDto.setRemake(remakeList); ggreportingtemplateDto.setCondition(null); //数据分页 if(exportData.size()>5000) { double size = exportData.size(); double divisor = size/5000; int forNumber = (new Double(Math.ceil(divisor))).intValue(); for (int i = 0; i < forNumber; i++) { if((i+1)==forNumber) { List<LinkedHashMap> exportDataTemp = exportData.subList(0+(i*5000), exportData.size()-1); wb = this.createCSVUtil2(0, "Exceptional Rpt"+(i+1), wb, map, cellRow, exportDataTemp, columnWidth, columnWidth.length, ggreportingtemplateDto, 0); }else { List<LinkedHashMap> exportDataTemp = exportData.subList(0+(i*5000), 5000+(i*5000 )); wb = this.createCSVUtil2(0, "Exceptional Rpt"+(i+1), wb, map, cellRow, exportDataTemp, columnWidth, columnWidth.length, ggreportingtemplateDto, 0); } } }else { wb = this.createCSVUtil2(0, "Exceptional Rpt", wb, map, cellRow, exportData, columnWidth, columnWidth.length, ggreportingtemplateDto, 0); } /*wb = this.createCSVUtil2(0, "Exceptional Rpt", wb, map, cellRow, exportData, columnWidth, columnWidth.length, ggreportingtemplateDto, 0);*/ return wb; } 一开始SXSSFWorkbook wb = new SXSSFWorkbook(5050)这里的值给的5000 ,然后当数据量大于5000时直接报错,文件不能正常导出,然后我把5000改成7000,会报错但是文件能导出,是损坏文件,一条数据都没有,后来修改成分页导出,自己测试的时候任然报了数组下标越界,且越界的下标为负值,文件能正常导出,但导出的文件显示已损坏,看不到数据。报错代码图片以上传,求大神解答,解答有效我微信转账请大神喝奶茶 java.lang.ArrayIndexOutOfBoundsException: -20527 at java.util.ArrayList.elementData(ArrayList.java:418) at java.util.ArrayList.get(ArrayList.java:431) at org.apache.poi.xssf.model.StylesTable.getFontAt(StylesTable.java:386) at org.apache.poi.xssf.usermodel.XSSFWorkbook.getFontAt(XSSFWorkbook.java:954) at org.apache.poi.xssf.streaming.SXSSFWorkbook.getFontAt(SXSSFWorkbook.java:857) at org.apache.poi.ss.util.SheetUtil.getCellWidth(SheetUtil.java:148) at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.updateColumnWidth(AutoSizeColumnTracker.java:367) at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.updateColumnWidths(AutoSizeColumnTracker.java:333) at org.apache.poi.xssf.streaming.SXSSFSheet.flushOneRow(SXSSFSheet.java:1892) at org.apache.poi.xssf.streaming.SXSSFSheet.flushRows(SXSSFSheet.java:1871) at org.apache.poi.xssf.streaming.SXSSFSheet.flushRows(SXSSFSheet.java:1882) at org.apache.poi.xssf.streaming.SXSSFWorkbook.write(SXSSFWorkbook.java:931) at com.sinosoft.application.platform.web.action.GgReportingTemplateAction.download(GgReportingTemplateAction.java:267) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.sinosoft.application.common.BaseProcessAction.execute(BaseProcessAction.java:213) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:216) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:117) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:198) at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:176) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265) at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107) at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:124) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:110) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149) at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.sinosoft.application.common.CAS_LANGUATE.doFilter(CAS_LANGUATE.java:35) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.sinosoft.sysframework.web.control.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:99) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.sinosoft.application.common.CompatibleFilter.doFilter(CompatibleFilter.java:29) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.sinosoft.application.common.ValidateSalt.doFilter(ValidateSalt.java:56) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:160) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.sinosoft.application.common.LoadSalt.doFilter(LoadSalt.java:41) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 此问题已解决,导致报错的原因是sheet.trackAllColumnsForAutoSizing();poi自动设置列宽的代码,注释这行之后问题解决。

apache poi 4.0.1设置单元格为数值类型但是打开excel提示单元格为非数字类型

``` // 整数 if (type == 1) { cell.setCellType(CellType.NUMERIC); XSSFDataFormat format = xssfWorkbook.createDataFormat(); cellStyle.setDataFormat(format.getFormat("0")); cell.setCellValue(PublicUtils.objToDou(value, 0D)); }// 浮点数 else if (type == 2) { cell.setCellType(CellType.NUMERIC); DataFormat format = workbook.createDataFormat(); String dateFormat = "0.00"; if (valMap.containsKey("format")) { dateFormat = (String) valMap.get("format"); if (PublicUtils.isEmpty(dateFormat)) { dateFormat = "0.00"; } cellStyle.setDataFormat(format.getFormat(dateFormat)); } cell.setCellValue(PublicUtils.objToDou(value, 0D)); } ``` ![图片说明](https://img-ask.csdn.net/upload/201901/16/1547649582_870665.png)

poi 跨列合并word中的表格的单元格

poi 合并word中的表格的单元格时,跨行可以正确合并,跨列合并则失败, 以下是合并列的代码:(poi 版本是 3.14 ) ``` public void mergeCellsHorizontal(XWPFTable table, int row, int fromCell, int toCell) { for (int cellIndex = fromCell; cellIndex <= toCell; cellIndex++) { XWPFTableCell cell = table.getRow(row).getCell(cellIndex); if ( cellIndex == fromCell ) { // The first merged cell is set with RESTART merge value cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART); } else { // Cells which join (merge) the first one, are set with CONTINUE cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE); } } } ```

POI获取excle合并单元格以及没有合并单元格的数据

问题描述:如果excle表里最后一行数据是没有合并的,就取不到值,如果最后一行是合并过的数据,就都能取得到了(合并未合并的都可以获取到)。有大神可以帮忙看一下代码解决一下吗,谢谢啦。 package service; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import entity.Table; public class ExcelOp { public String excelPath; public ExcelOp(String excelPath) { this.excelPath = excelPath; } public String getExcelPath() { return excelPath; } public void setExcelPath(String excelPath) { this.excelPath = excelPath; } /** * * @param excelPath:excel路径 * @param args:需要操作的列 * @throws IOException */ @SuppressWarnings("resource") public ArrayList<Table> readExcel() throws IOException{ File excelFile = new File(excelPath); InputStream is = new FileInputStream(excelFile); // 获取文件输入流 ArrayList<Table> list = null; String suffix = excelPath.substring(excelPath.lastIndexOf(".")+1); if(suffix.equals("xls")){ HSSFWorkbook workbook = null; workbook = new HSSFWorkbook(is); if(workbook != null){ HSSFSheet sheet = workbook.getSheetAt(1);//获取第二张表 if(sheet == null){ System.out.println(); return null; } list = new ArrayList<Table>(); int combineLines = 1; int number = 1; //读取行 for (int rowNum = 3; rowNum < sheet.getLastRowNum(); rowNum+=combineLines) { HSSFRow row = sheet.getRow(rowNum); if (row == null) continue; Table tb = new Table(); tb.setNumber("3.1." + number); // tb.setTestData(row.getCell(0).toString()); tb.setTitle(row.getCell(1).toString()); //Word换行主要有两大类,一类是表格单元格文本的换行,另一类是表格之外的文本的换行。对于表格外的文本我们可以使用“\r”或者“(char)11”来换行,然而对于表格内的文本我们只能使用“(char)11”来进行换行操作。 // tb.setFunctionPoint(row.getCell(2).toString().replace('\n', (char)11)); tb.setFunctionPoint(row.getCell(2).toString()); combineLines = isMergedRegion(sheet, rowNum, 1); String process = ""; String conclusion = ""; Set<String> s = new HashSet<String>(); for (int i = rowNum; i< rowNum + combineLines; i++) { //步骤 HSSFRow r1 = sheet.getRow(i); // process += r1.getCell(5).toString() + (char)11 + (char)11; process += r1.getCell(5).toString() + "\n" + "\n"; //结果 String result = r1.getCell(7).toString(); s.add(result); } tb.setProcess(process); tb.setConclusion(conclusion); number++; list.add(tb); } } } return list; } //返回合并单元格占用行数 public int isMergedRegion(Sheet sheet, int row, int column) { int sheetMergeCount = sheet.getNumMergedRegions(); for (int i = 0; i < sheetMergeCount; i++) { CellRangeAddress range = sheet.getMergedRegion(i); int firstRow = range.getFirstRow(); int lastRow = range.getLastRow(); int firstColumn = range.getFirstColumn(); int lastColumn = range.getLastColumn(); if (row >= firstRow && row <= lastRow) { if(column >= firstColumn && column <= lastColumn){ return lastRow - firstRow + 1; } } } return 1; } }

poi 生成Excel文字居中问题

HSSFCellStyle boderStyle = wb.createCellStyle(); //垂直居中 boderStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); boderStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); poi 设置了居中但是生成的Excel中文字没有居中显示 我这个是从数据取出的数据有层级关系

小白求助:poi生成excel速度过慢问题,该怎么优化

package poiMain; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Scanner; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class PoiGH3215 { private static String fileName=""; public static String getCell(int x,int y) throws IOException{ DecimalFormat df = new DecimalFormat("#"); InputStream myxls=new FileInputStream(fileName); @SuppressWarnings("resource") XSSFWorkbook wb =new XSSFWorkbook(myxls); XSSFSheet sheet=wb.getSheetAt(0);//第一个工作表 XSSFRow row =sheet.getRow(x-1);//第x行 XSSFCell cell =row.getCell((short)y-1);//第x行第y个元素 if(cell==null){ return null; } String cellValue = ""; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: cellValue = cell.getRichStringCellValue().getString().trim(); break; case HSSFCell.CELL_TYPE_NUMERIC: if (HSSFDateUtil.isCellDateFormatted(cell)) {// 处理日期格式、时间格式 SimpleDateFormat sdf = null; if (cell.getCellStyle().getDataFormat() == HSSFDataFormat .getBuiltinFormat("h:mm")) { sdf = new SimpleDateFormat("HH:mm"); } else {// 日期 sdf = new SimpleDateFormat("yyyy/MM/dd"); } Date date = cell.getDateCellValue(); cellValue = sdf.format(date); } else { cellValue = df.format(cell.getNumericCellValue()).toString(); } break; default: cellValue = ""; } return cellValue; } public static void ModelGH3215() throws IOException{ @SuppressWarnings("resource") XSSFWorkbook wb =new XSSFWorkbook(); Date d = new Date(); DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String fileName = df.format(d); FileOutputStream fileOut = new FileOutputStream("D:/输出/工行3215/" + fileName + "_main" + ".xls"); XSSFSheet sheet=wb.createSheet(); Font font = wb.createFont(); XSSFCellStyle style = wb.createCellStyle(); //新建单元格样式 font.setFontName("宋体"); font.setFontHeightInPoints((short) 12);//设置字体大小 font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体显示 style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中 style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直 style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); //下边框 style.setFont(font); //设置单元格列宽 sheet.setColumnWidth(0, 100 * 100); sheet.setColumnWidth(1, 100 * 30); sheet.setColumnWidth(3, 100 * 30); sheet.setColumnWidth(4, 100 * 30); sheet.setColumnWidth(9, 100 * 130); sheet.setColumnWidth(20, 100 * 40); XSSFRow row =sheet.createRow((short)0); XSSFCell cell=row.createCell((short)0); row.setHeight((short) 700);//设置行高 cell.setCellValue("银行科目"); row.getCell((short)0).setCellStyle(style); row.createCell((short)1).setCellValue("币别"); row.getCell((short)1).setCellStyle(style); row.createCell((short)2).setCellValue("序列号"); row.getCell((short)2).setCellStyle(style); row.createCell((short)3).setCellValue("日期"); row.getCell((short)3).setCellStyle(style); row.createCell((short)4).setCellValue("业务日期"); row.getCell((short)4).setCellStyle(style); row.createCell((short)5).setCellValue("凭证字"); row.getCell((short)5).setCellStyle(style); row.createCell((short)6).setCellValue("凭证号"); row.getCell((short)6).setCellStyle(style); row.createCell((short)7).setCellValue("凭证年"); row.getCell((short)7).setCellStyle(style); row.createCell((short)8).setCellValue("凭证期间"); row.getCell((short)8).setCellStyle(style); row.createCell((short)9).setCellValue("摘要"); row.getCell((short)9).setCellStyle(style); row.createCell((short)10).setCellValue("对方科目"); row.getCell((short)10).setCellStyle(style); row.createCell((short)11).setCellValue("结算方式"); row.getCell((short)11).setCellStyle(style); row.createCell((short)12).setCellValue("结算号"); row.getCell((short)12).setCellStyle(style); row.createCell((short)13).setCellValue(""); row.getCell((short)13).setCellStyle(style); row.createCell((short)14).setCellValue(""); row.getCell((short)14).setCellStyle(style); row.createCell((short)15).setCellValue("汇率"); row.getCell((short)15).setCellStyle(style); row.createCell((short)16).setCellValue("附件数"); row.getCell((short)16).setCellStyle(style); row.createCell((short)17).setCellValue("汇率类型"); row.getCell((short)17).setCellStyle(style); row.createCell((short)18).setCellValue("备注"); row.getCell((short)18).setCellStyle(style); row.createCell((short)19).setCellValue("对应外币"); row.getCell((short)19).setCellStyle(style); row.createCell((short)20).setCellValue("对应外币金额"); row.getCell((short)20).setCellStyle(style); int j = 1;int sum=0;int a=0;int s=getNum(); ArrayList<String> date1 = new ArrayList(); ArrayList<Integer> value1 = new ArrayList(); ArrayList<String> date2 = new ArrayList(); ArrayList<Integer> value2 = new ArrayList(); for(int i=5;i<s+2;i++){ if(PoiGH3215.getCell(i,4).equals("转款")&&(PoiGH3215.getCell(i,8).equals("31001547840050012398"))){ System.out.println("get"); XSSFRow row2 =sheet.createRow((short)j++); row2.createCell((short)14).setCellValue(getCell(i,5)); row2.createCell((short)13).setCellValue(getCell(i,7)); row2.createCell((short)3).setCellValue(getCell(i,2));//日期 row2.createCell((short)4).setCellValue(getCell(i,2));//日期 row2.createCell((short)0).setCellValue("1021.01.10|工行广州白云路支行(8980)-备汇缴");//第一列 row2.createCell((short)9).setCellValue("收转款,建行怒江2398转入工行侨香");//摘要 }else if(PoiGH3215.getCell(i,4).equals("收付")&&(!PoiGH3215.getCell(i,5).equals(PoiGH3215.getCell(i,6)))){ XSSFRow row3 =sheet.createRow((short)j); row3.createCell((short)9).setCellValue("付移动手机充值款"); row3.createCell((short)13).setCellValue(getCell(i,7));//添加值 row3.createCell((short)14).setCellValue(getCell(i,5));//添加值 row3.createCell((short)3).setCellValue(getCell(j,2)); row3.createCell((short)4).setCellValue(getCell(j,2)); row3.createCell((short)0).setCellValue("1021.01.10|工行广州白云路支行(8980)-备汇缴"); row3.createCell((short)14).setCellValue(getCell(i,5)); row3.createCell((short)9).setCellValue("收还款退款");//摘要 } else if(PoiGH3215.getCell(i,4).equals("收付")&&(PoiGH3215.getCell(i,5).equals(PoiGH3215.getCell(i,6)))){ XSSFRow row3 =sheet.createRow((short)j); row3.createCell((short)9).setCellValue("付移动手机充值款"); row3.createCell((short)13).setCellValue(getCell(i,7)); row3.createCell((short)14).setCellValue(getCell(i,5));//添加值 row3.createCell((short)3).setCellValue(getCell(j,2)); row3.createCell((short)4).setCellValue(getCell(j,2)); row3.createCell((short)0).setCellValue("1021.01.10|工行广州白云路支行(8980)-备汇缴"); row3.createCell((short)14).setCellValue(getCell(i,5)); row3.createCell((short)9).setCellValue("收收付");//摘要 } else if(PoiGH3215.getCell(i,4).equals("拉卡拉代付款")&&(!PoiGH3215.getCell(i,9).equals("拉卡拉支付有限公司客户备付金"))&&(!PoiGH3215.getCell(i,9).equals("拉卡拉支付有限公司(客户备付金)"))&&(!PoiGH3215.getCell(i,9).equals("拉卡拉网络技术有限公司北京分公司的数(合计数)"))){ //System.out.println(i); date1.add(PoiGH3215.getCell(i,2)); value1.add(Integer.parseInt(PoiGH3215.getCell(i,5))); } } for(int c=0;c<date1.size();c++){ try { if(date1.get(c).equals(date1.get(c+1))){ a=value1.get(c); sum=a+sum; }else { a= value1.get(c); sum=a+sum; date2.add(date1.get(c)); value2.add(sum); sum=0; } } catch (Exception e) { a=value1.get(c); sum=a+sum; date2.add(date1.get(c)); value2.add(sum); } } for(int k=0;k<date2.size();k++){ XSSFRow row3 =sheet.createRow((short)j+k); row3.createCell((short)14).setCellValue(value2.get(k)); row3.createCell((short)9).setCellValue("付代付款"); row3.createCell((short)3).setCellValue(date2.get(k)); row3.createCell((short)4).setCellValue(date2.get(k)); row3.createCell((short)0).setCellValue("1021.01.10|工行广州白云路支行(8980)-备汇缴"); } for(int m=1;m<j+date2.size();m++){ XSSFRow row2 =sheet.getRow((short)m); row2.createCell((short)1).setCellValue("RMB|人民币"); row2.createCell((short)15).setCellValue("1"); row2.createCell((short)16).setCellValue("0"); row2.createCell((short)17).setCellValue("01|公司汇率"); row2.createCell((short)20).setCellValue("0"); } wb.write(fileOut); fileOut.close(); System.out.println("输入完毕"); } public static int getNum() throws IOException{ synchronized (fileName) { while("".equals(fileName)){ System.out.println("请输入您的文件路径:"); Scanner sc = new Scanner(System.in); fileName = sc.nextLine(); sc.close(); } } InputStream myxls=new FileInputStream(fileName); @SuppressWarnings("resource") XSSFWorkbook wb =new XSSFWorkbook(myxls); XSSFSheet sheet=wb.getSheetAt(0);//第一个工作表 return sheet.getLastRowNum(); } } 我要处理的表有6万多行,我这个处理一个200行的都要1分钟

如何用xssf方法在java中设置excel的cell的格式为文本格式

``` package com.sitech.dss.ssjf.service.impl; import java.io.OutputStream; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; import org.apache.commons.collections.MapUtils; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.struts2.ServletActionContext; import org.springframework.stereotype.Service; import com.sitech.dss.ssjf.service.ExportUniteService; /** * 统一导出功能实现类 * @author cfl * 2014-7-31 */ @Service("export_service") public class ExportUniteServiceImpl implements ExportUniteService { private Logger logger = Logger.getLogger(ExportUniteServiceImpl.class); /** * EXCEL单行表头导出功能实现 * @author cfl */ @Override public void exportExcelBySingleHeader(List<Map<String, Object>> dateList, Map<String,String> headMap,String filename, String sheetName,Map<String, Object> styleMap) { try { /**---------------------------------------输出控制---------------------------------------------------------**/ HttpServletResponse response = ServletActionContext.getResponse(); OutputStream os = response.getOutputStream();// 取得输出流 filename = filename+".xlsx"; filename = new String(filename.getBytes("GBK"), "iso8859-1"); response.reset();// 清空输出流 response.setHeader("Content-disposition", "attachment; filename="+filename);// 设定输出文件头 response.setContentType("application/msexcel");// 定义输出类型 /**---------------------------------------创建webbook---------------------------------------------------------**/ // 第一步,创建一个webbook,对应一个Excel文件 XSSFWorkbook wb = new XSSFWorkbook(); // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet XSSFSheet sheet = wb.createSheet(sheetName); // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short XSSFRow row = sheet.createRow((int) 0); sheet.setDefaultColumnWidth((short) 15); /**---------------------------------------表头样式设置---------------------------------------------------------**/ // 第四步,创建单元格,并设置值表头 设置表头居中 CellStyle style = wb.createCellStyle(); style.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 //设置背景颜色 setBackColor(style,MapUtils.getShortValue(styleMap, "headerBackColor")); //设置边框颜色 setBorder(style,CellStyle.BORDER_THIN,MapUtils.getShortValue(styleMap, "borderColor")); //设置字体 Font font=wb.createFont(); setFont(font,style,(short)MapUtils.getIntValue(styleMap, "headerFontSize"),MapUtils.getShortValue(styleMap, "headerFontColor") , MapUtils.getString(styleMap, "font")); /**----------------------------------------表内容样式设置--------------------------------------------------------**/ CellStyle style2 = wb.createCellStyle(); //设置边框颜色 setBorder(style2,CellStyle.BORDER_THIN,MapUtils.getShortValue(styleMap, "borderColor")); //设置字体 Font font2=wb.createFont(); setFont(font2,style2,(short)MapUtils.getIntValue(styleMap, "bodyFontSize"),MapUtils.getShortValue(styleMap, "bodyFontColor") , MapUtils.getString(styleMap, "font")); style2.setAlignment(XSSFCellStyle.ALIGN_CENTER); /**----------------------------------------表头信息组装--------------------------------------------------------**/ XSSFCell cell = row.createCell((short) 0); int cellIndex = 0; for(Map.Entry<String, String> entry:headMap.entrySet()){ cell = row.createCell((short) cellIndex); cell.setCellValue(entry.getValue()); cell.setCellStyle(style); cellIndex++; } /**-----------------------------------------表内容信息组装-------------------------------------------------------**/ for (int i = 0; i < dateList.size(); i++) { row = sheet.createRow((int) i + 1); Map map = dateList.get(i); int rowCellIndex = 0; for(Map.Entry<String, String> entry:headMap.entrySet()){ cell = row.createCell((short) rowCellIndex); cell.setCellValue(MapUtils.getString(map, entry.getKey())); cell.setCellStyle(style2); rowCellIndex++; } } /**-----------------------------------------写入输出流,关闭输出流-------------------------------------------------------**/ wb.write(os); os.flush(); os.close(); } catch (Exception e) { e.printStackTrace(); } } /** * 设置背景颜色 * @author cfl * @param style style对象 * @param color :IndexedColors.SKY_BLUE.getIndex() * @return */ public static CellStyle setBackColor(CellStyle style,short color){ //设置前端颜色 style.setFillForegroundColor(color); //设置填充模式 style.setFillPattern(CellStyle.SOLID_FOREGROUND); return style; } /** * 设置单元格边框(四个方向的颜色一样) * @author cfl * @param style style对象 * @param borderStyle 边框类型 :dished-虚线 thick-加粗 double-双重 dotted-有点的 CellStyle.BORDER_THICK * @param borderColor 颜色 IndexedColors.BLUE.getIndex() * @return */ public static CellStyle setBorder(CellStyle style,short borderStyle,short borderColor){ //设置底部格式(样式+颜色) style.setBorderBottom(borderStyle); style.setBottomBorderColor(borderColor); //设置左边格式 style.setBorderLeft(borderStyle); style.setLeftBorderColor(borderColor); //设置右边格式 style.setBorderRight(borderStyle); style.setRightBorderColor(borderColor); //设置顶部格式 style.setBorderTop(borderStyle); style.setTopBorderColor(borderColor); return style; } /** * * 设置字体(简单的需求实现,如果复杂的字体,需要自己去实现)尽量重用 * @author cfl * @param style style对象 * @param fontSize 字体大小 shot(24) * @param color 字体颜色 IndexedColors.BLACK.getIndex() * @param fontName 字体名称 "Courier New" * @param */ public static CellStyle setFont(Font font, CellStyle style,short fontSize,short color,String fontName){ font.setFontHeightInPoints(fontSize); font.setFontName(fontName); //font.setItalic(true);// 斜体 //font.setStrikeout(true);//加干扰线 font.setColor(color);//设置颜色 // Fonts are set into a style so create a new one to use. style.setFont(font); return style; } } ``` 代码如上所示

poi导出后台提示报错,Minimum column number is 0!

今天在用poi做导出的时候遇到一些问题! java.lang.IllegalArgumentException: Minimum column number is 0 at org.apache.poi.ss.util.CellRangeAddressBase.validateColumn(CellRangeAddressBase.java:73) at org.apache.poi.ss.util.CellRangeAddressBase.validate(CellRangeAddressBase.java:54) at org.apache.poi.xssf.usermodel.XSSFSheet.addMergedRegion(XSSFSheet.java:270) at org.apache.poi.xssf.streaming.SXSSFSheet.addMergedRegion(SXSSFSheet.java:342) at com.sdfyzx.common.utils.excel.ExportExcel.initialize(ExportExcel.java:200) at com.sdfyzx.common.utils.excel.ExportExcel.<init>(ExportExcel.java:163) at com.sdfyzx.common.utils.excel.ExportExcel.<init>(ExportExcel.java:84) at com.sdfyzx.modules.echarts.web.EchartsController.exportFile(EchartsController.java:320) at com.sdfyzx.modules.echarts.web.EchartsController$$FastClassBySpringCGLIB$$887abd62.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:640) at com.sdfyzx.modules.echarts.web.EchartsController$$EnhancerBySpringCGLIB$$1f6b5675.exportFile(<generated>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129) at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) at java.lang.Thread.run(Thread.java:619)

java导出Excel时异常原因

org.apache.xmlbeans.SchemaTypeLoaderException: XML-BEANS compiled schema: Incompatible minor version - expecting up to 23, got 24 (schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.index) - code 3 at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl$XsbReader.<init>(SchemaTypeSystemImpl.java:1522) at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.initFromHeader(SchemaTypeSystemImpl.java:260) at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:183) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.TypeSystemHolder.loadTypeSystem(Unknown Source) at schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.TypeSystemHolder.<clinit>(Unknown Source) at sun.misc.Unsafe.ensureClassInitialized(Native Method) at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25) at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122) at java.lang.reflect.Field.acquireFieldAccessor(Field.java:918) at java.lang.reflect.Field.getFieldAccessor(Field.java:899) at java.lang.reflect.Field.get(Field.java:358) at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:770) at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook.<clinit>(Unknown Source) at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.newInstance(Unknown Source) at org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(XSSFWorkbook.java:321) at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:181) at com.zlkj.ywgl.action.VioSurveilAction.outVioSurveilOrMidExcel(VioSurveilAction.java:712) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:471) at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:408) at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153) at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:619)

java POI操作word 合并单元格的问题,求大神解决!

问题是这样的,有一个word模板,模板里带表格需要根据需要动态的改变单元格样式,有可能 横向合并,也有可能纵向合并,求大神给解决思路或代码! 拜谢了!!!

关于POI 单元格为空的问题

我在设值的时候 走到下面第2行代码 如果单元格未空,则报空指针异常,如果不为空则正常,怎么做呢? public void setCellValue(int r, int c, String value) { HSSFRow row = sheet.getRow(r); HSSFCell cell = row.getCell((short)c); HSSFRichTextString ts = new HSSFRichTextString(value); cell.setCellValue(ts); }

poi 怎么设置单元格格式,以文本方式显示数字

cellStyle.setDataFormat(format.getFormat("@")) 导出的excel中输入文本正常,输入数字以日期格式显示

poi设置完Excel后,怎上传到服务器,并返回一个服务器的ur

跪求大佬我现在有一个写了一个口,只要传输服务器的Url然后通过Url就可下载文件,但是现在要把poi设置的单元格设置到服务器,并返回一个Url,求大佬给个demo

POI根据word模板生成新的word,当模板里的表格超过8列,生成的word是空白

如题,开始以为是代码问题,后来通过删减word模板排查,发现有一行表格时9列, 删掉一列生成的word是没问题的,只要超过8列生成的word就是空白的。求解!

POI 生成Excel 分段处理问题

<p>大家好! <br><br>我在做java 生成Excel文件时,由于数据量很大(七万多条),我创建的文件扩展名是xlsx,一下不可以导入Excel中,下载做分段导入,就是在sql语句中(例如每次查询2000条),当第一次执行时,先创建Excel标题,然后把第一次查询的2000数据写入Excel中,然后一直循环,直到把全部数据写入。请问大侠们,怎么循环写入?用什么方法? <br><br>if(i == 0 ) <br>{ <br>     FileOutputStream os = new FileOutputStream(new File(“D:\\excel\a.xlsx”)); <br>     XSSFWorkbook wb = new XSSFWorkbook(); <br>// <br>     XSSFSheet sheet = (XSSFSheet) wb.createSheet("aaa"); <br>// <br>     XSSFRow row = null; <br>     XSSFCell cell = null; <br>     int row_num = 0; <br>     int cell_num = 0; <br><br>     row = sheet.createRow(row_num); <br>     row.setHeightInPoints(30); <br>     sheet.autoSizeColumn(0, true); <br><br>     cell = row.createCell(cell_num++); <br>     ExcelUtil.setFormatTitleCenter(wb, cell); <br>     cell.setCellValue("SEQ"); <br>     <br>     wb.write(os); <br>     os.close(); <br>} <br>if(list.size()&gt;0){ <br>File file = new File(StringUtil.FILE_NAME); <br><br>String fullname = file.getAbsolutePath(); <br><br>FileInputStream fs = new   FileInputStream(fullname); <br><br>XSSFWorkbook wb = new XSSFWorkbook(fs); <br><br>XSSFSheet   sheet   =   wb.getSheetAt(0); <br><br><br>PDTO dto = null; <br>Iterator itor = list.iterator(); <br>   <br>XSSFRow row = null; <br>XSSFCell cell = null; <br><br>                   while( itor.hasNext() ) <br>{ <br>dto = (PipeDTO)itor.next(); <br>i++; <br>//定义列 <br>int j=0; <br>row = sheet.createRow(i); <br>//设置行长度自动 <br>//row.setHeight((short)500); <br>row.setHeightInPoints(20); <br>//row.setZeroHeight(true); <br>sheet.autoSizeColumn(j+1, true); <br>//获得这一行的每j列 <br>cell = row.createCell(j++); <br>//给单元格设值 <br>ExcelUtil.setFormatLineRight(wb, cell); <br>cell.setCellValue(dto.getSeq); <br>} <br>FileOutputStream os = new FileOutputStream(new File(“D:\\excel\a.xlsx”)); <br>wb.write(os); <br>os.close(); <br>               } <br>               else <br>      { <br>break; <br>      } <br>这样执行是还是这样的错误, <br>[java] java.lang.ArrayIndexOutOfBoundsException: -32765 <br>[java]     at java.util.ArrayList.get(Unknown Source) <br>[java]     at org.apache.poi.xssf.model.StylesTable.getFontAt(StylesTable.java:190) <br>[java]     at org.apache.poi.xssf.usermodel.XSSFWorkbook.getFontAt(XSSFWorkbook.java:592) <br>[java]     at org.apache.poi.xssf.usermodel.helpers.ColumnHelper.getColumnWidth(ColumnHelper.java:355) <br>[java]     at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:337) <br>[java]     at dlstx.monitor.data.pipe.PipeDAO.rt_code_check_error(PipeDAO.java:688) <br>[java]     at dlstx.monitor.data.ERPMonitor.pipeCheck(ERPMonitor.java:105) <br>[java]     at dlstx.monitor.data.ERPMonitor.main(ERPMonitor.java:53) <br>请指点,有没有好点的方法,怎么修改,十分感谢!</p> <p> </p>

java程序jxl导出excel内存溢出

困扰了我3天的问题 java程序jxl导出excel内存溢出 在网上找了几个扩大tomcat内存的方法,比如 1.在catalina.bat最前面加入set JAVA_OPTS=-Xms384m -Xmx384m 2.在catalina.sh中echo "Using CATALINA_BASE: $CATALINA_BASE"前面加入JAVA_OPTS="-server -Xms800m -Xmx800m -XX:MaxNewSize=512m" 都不好使,下载10000条数据就会报内存溢出,如下: xception report message Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space description The server encountered an internal error that prevented it from fulfilling this request. exception org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:972) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) root cause java.lang.OutOfMemoryError: Java heap space com.roiland.maven.control.management.JlhdExcelController.jlhdGrmdExcel(JlhdExcelController.java:201) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.39 logs. 我的代码: @RequestMapping(value = "/jlhdGrmdExcel.do", method = { RequestMethod.GET, RequestMethod.POST }) @RequestMappingAssist(paramType=ParamType.httpType,viewType=ViewType.jspView) public String jlhdGrmdExcel(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setCharacterEncoding("utf-8"); response.setContentType("application/vnd.ms-excel"); Date date = new Date(System.currentTimeMillis()); String param2 = new SimpleDateFormat("yyyyMMdd").format(date).toString(); response.addHeader("Content-Disposition","attachment; filename=\"" + param2 + ".xls" + "\""); // 声明输出流对象 OutputStream os = null; // 实例流对象 os = response.getOutputStream(); // 创建工作簿和sheet表 WritableFont wf2 = new WritableFont(WritableFont.TIMES, 12,WritableFont.NO_BOLD, false); WritableCellFormat wcfF2 = new WritableCellFormat(wf2); // 设置单元格格式 wcfF2.setAlignment(jxl.format.Alignment.CENTRE); wcfF2.setAlignment(jxl.format.Alignment.CENTRE); // 声明工作簿 WritableWorkbook wwb = Workbook.createWorkbook(os); //获取jlhdid int jlhdid = Integer.parseInt(request.getParameter("jlhdid")); //获取jxsdm String jxsdm = request.getParameter("jxsdm"); JlhdGrmd jlhdgrmd = new JlhdGrmd(); //放入参数 jlhdgrmd.setJlhdid(jlhdid); jlhdgrmd.setJxsdm(jxsdm); request.setCharacterEncoding("UTF-8"); //查询符合条件的结果集 List<JlhdGrmd> excelGrmd = new ArrayList<JlhdGrmd>(); excelGrmd = jlhdGrmdMapper.selectJlhdGrmdByJlhdId(jlhdgrmd); if (excelGrmd != null && excelGrmd.size() > 0) { // 设置sheet名称 WritableSheet sheet = wwb.createSheet("个人名单", 0); // 设置列名 /*sheet.addCell(new Label(0, 0, "序号", wcfF2)); sheet.addCell(new Label(1, 0, "经销商代码", wcfF2)); sheet.addCell(new Label(2, 0, "经销商名称", wcfF2)); sheet.addCell(new Label(3, 0, "用户id", wcfF2)); sheet.addCell(new Label(4, 0, "个人代码", wcfF2)); sheet.addCell(new Label(5, 0, "姓名", wcfF2)); sheet.addCell(new Label(6, 0, "银行卡号", wcfF2)); sheet.addCell(new Label(7, 0, "身份证", wcfF2)); sheet.addCell(new Label(8, 0, "职务", wcfF2)); sheet.addCell(new Label(9, 0, "销售台数", wcfF2)); sheet.addCell(new Label(10, 0, "总积分", wcfF2)); sheet.addCell(new Label(11, 0, "总金额", wcfF2)); sheet.addCell(new Label(12, 0, "总所得税", wcfF2)); sheet.addCell(new Label(13, 0, "总支付金额", wcfF2)); sheet.addCell(new Label(14, 0, "是否打款", wcfF2)); sheet.addCell(new Label(15, 0, "打款失败原因", wcfF2)); sheet.addCell(new Label(16, 0, "上传次数", wcfF2)); sheet.addCell(new Label(17, 0, "支付日期", wcfF2)); sheet.addCell(new Label(18, 0, "添加时间", wcfF2)); sheet.addCell(new Label(19, 0, "添加人id", wcfF2));*/ sheet.addCell(new Label(0, 0, "序号", wcfF2)); sheet.addCell(new Label(1, 0, "经销商代码", wcfF2)); sheet.addCell(new Label(2, 0, "经销商名称", wcfF2)); sheet.addCell(new Label(3, 0, "个人代码", wcfF2)); sheet.addCell(new Label(4, 0, "姓名", wcfF2)); sheet.addCell(new Label(5, 0, "银行卡号", wcfF2)); sheet.addCell(new Label(6, 0, "身份证", wcfF2)); sheet.addCell(new Label(7, 0, "职务", wcfF2)); sheet.addCell(new Label(8, 0, "销售台数", wcfF2)); sheet.addCell(new Label(9, 0, "总积分", wcfF2)); sheet.addCell(new Label(10, 0, "总金额", wcfF2)); sheet.addCell(new Label(11, 0, "总所得税", wcfF2)); sheet.addCell(new Label(12, 0, "总支付金额", wcfF2)); sheet.addCell(new Label(13, 0, "是否打款", wcfF2)); sheet.addCell(new Label(14, 0, "打款失败原因", wcfF2)); sheet.addCell(new Label(15, 0, "支付日期", wcfF2)); sheet.addCell(new Label(16, 0, "添加时间", wcfF2)); sheet.addCell(new Label(0, excelGrmd.size() + 2, "合计:", wcfF2)); //合计销售台数 int sumXsts = 0; //合计总积分 double sumZjf = 0; //合计奖励数量 double sumZje = 0; //合计个人所得税 double sumGrsds = 0; //合计总支付金额 double sumZzfje = 0; // 循环输出经销商列表 for (int i = 1; i < excelGrmd.size() + 1; i++) { JlhdGrmd emp = excelGrmd.get(i - 1); //宽度设置 sheet.setColumnView(0, 10); sheet.setColumnView(1, 20); sheet.setColumnView(2, 50); sheet.setColumnView(3, 20); sheet.setColumnView(4, 20); sheet.setColumnView(5, 20); sheet.setColumnView(6, 20); sheet.setColumnView(7, 20); sheet.setColumnView(8, 20); sheet.setColumnView(9, 20); sheet.setColumnView(10, 20); sheet.setColumnView(11, 20); sheet.setColumnView(12, 20); sheet.setColumnView(13, 20); sheet.setColumnView(14, 20); sheet.setColumnView(15, 20); sheet.setColumnView(16, 30); sheet.setColumnView(17, 30); int xsts = 0;//销售台数 double zjf = 0; //总积分 double zje = 0;//总金额 double grsds = 0;//个人所得税 double zzfje = 0;//总支付金额 xsts = emp.getXsts(); try { if(emp.getZjf()!=null && emp.getZjf()!=""){ zjf = Double.parseDouble(emp.getZjf()); } System.err.println("emp.getZje()"+emp.getZje()); if(emp.getZje()!=null && emp.getZje()!=""){ zje = Double.parseDouble(emp.getZje()); } if(emp.getZsds()!=null && emp.getZsds()!=""){ grsds = Double.parseDouble(emp.getZsds()); } if(emp.getZzfje()!=null && emp.getZzfje()!=""){ zzfje = Double.parseDouble(emp.getZzfje()); } } catch (Exception e) { } sheet.addCell(new Label(0, i, i + "", wcfF2)); sheet.addCell(new Label(1, i, emp.getJxsdm(), wcfF2)); sheet.addCell(new Label(2, i, emp.getJxsmc(), wcfF2)); sheet.addCell(new Label(3, i, emp.getGrdm(), wcfF2)); sheet.addCell(new Label(4, i, emp.getGrmc(), wcfF2)); sheet.addCell(new Label(5, i, emp.getYhkh(), wcfF2)); sheet.addCell(new Label(6, i, emp.getSfz(), wcfF2)); sheet.addCell(new Label(7, i, emp.getZw(), wcfF2)); sheet.addCell(new Number(8, i,xsts, wcfF2)); sheet.addCell(new Number(9, i, zjf, wcfF2)); sheet.addCell(new Number(10, i, zje, wcfF2)); sheet.addCell(new Number(11, i, grsds, wcfF2)); sheet.addCell(new Number(12, i,zzfje, wcfF2)); sheet.addCell(new Label(13, i, emp.getIsdk(), wcfF2)); sheet.addCell(new Label(14, i, emp.getDksbyy(), wcfF2)); sheet.addCell(new Label(15, i, emp.getZfrq(), wcfF2)); sheet.addCell(new Label(16, i, emp.getAddtime(), wcfF2)); sumXsts += xsts;//合计销售台数 sumZje += zje;//合计总金额 sumZjf += zjf; //合计总积分 sumGrsds += grsds;//合计总个人所得税 sumZzfje += zzfje; //合计总支付金额 } sheet.addCell(new Number(8, excelGrmd.size() + 2,sumXsts, wcfF2)); sheet.addCell(new Number(9, excelGrmd.size() + 2,sumZjf, wcfF2)); sheet.addCell(new Number(10, excelGrmd.size() + 2,sumZje, wcfF2)); sheet.addCell(new Number(11, excelGrmd.size() + 2,sumGrsds, wcfF2)); sheet.addCell(new Number(12, excelGrmd.size() + 2,sumZzfje, wcfF2)); } wwb.write(); wwb.close(); os.close(); //response.flushBuffer(); return null; } 哪位大侠能帮小弟解决此问题,万分感谢!

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

Linux面试题(2020最新版)

文章目录Linux 概述什么是LinuxUnix和Linux有什么区别?什么是 Linux 内核?Linux的基本组件是什么?Linux 的体系结构BASH和DOS之间的基本区别是什么?Linux 开机启动过程?Linux系统缺省的运行级别?Linux 使用的进程间通信方式?Linux 有哪些系统日志文件?Linux系统安装多个桌面环境有帮助吗?什么是交换空间?什么是root帐户什么是LILO?什...

Linux命令学习神器!命令看不懂直接给你解释!

大家都知道,Linux 系统有非常多的命令,而且每个命令又有非常多的用法,想要全部记住所有命令的所有用法,恐怕是一件不可能完成的任务。 一般情况下,我们学习一个命令时,要么直接百度去搜索它的用法,要么就直接用 man 命令去查看守冗长的帮助手册。这两个都可以实现我们的目标,但有没有更简便的方式呢? 答案是必须有的!今天给大家推荐一款有趣而实用学习神器 — kmdr,让你解锁 Linux 学习新姿势...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

史上最全的 python 基础知识汇总篇,没有比这再全面的了,建议收藏

网友们有福了,小编终于把基础篇的内容全部涉略了一遍,这是一篇关于基础知识的汇总的文章,请朋友们收下,不用客气,不过文章篇幅肯能会有点长,耐心阅读吧爬虫(七十)多进程multiproces...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

85后蒋凡:28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门,他的人生底层逻辑是什么?...

蒋凡是何许人也? 2017年12月27日,在入职4年时间里,蒋凡开挂般坐上了淘宝总裁位置。 为此,时任阿里CEO张勇在任命书中力赞: 蒋凡加入阿里,始终保持创业者的冲劲,有敏锐的...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

新一代神器STM32CubeMonitor介绍、下载、安装和使用教程

关注、星标公众号,不错过精彩内容作者:黄工公众号:strongerHuang最近ST官网悄悄新上线了一款比较强大的工具:STM32CubeMonitor V1.0.0。经过我研究和使用之...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

大学一路走来,学习互联网全靠这几个网站,最终拿下了一把offer

大佬原来都是这样炼成的

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

什么时候跳槽,为什么离职,你想好了么?

都是出来打工的,多为自己着想

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

你期望月薪4万,出门右拐,不送,这几个点,你也就是个初级的水平

先来看几个问题通过注解的方式注入依赖对象,介绍一下你知道的几种方式@Autowired和@Resource有何区别说一下@Autowired查找候选者的...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

立即提问
相关内容推荐