当前位置 博文首页 > 文章内容

    weixin_42405661的博客:poi导出xlsx格式的excel怎么打不开,求大神帮忙!急

    作者:shunshunshun18 栏目:未分类 时间:2021-11-28 8:51:51

    本站于2023年9月4日。收到“大连君*****咨询有限公司”通知
    说我们IIS7站长博客,有一篇博文用了他们的图片。
    要求我们给他们一张图片6000元。要不然法院告我们

    为避免不必要的麻烦,IIS7站长博客,全站内容图片下架、并积极应诉
    博文内容全部不再显示,请需要相关资讯的站长朋友到必应搜索。谢谢!

    另祝:版权碰瓷诈骗团伙,早日弃暗投明。

    相关新闻:借版权之名、行诈骗之实,周某因犯诈骗罪被判处有期徒刑十一年六个月

    叹!百花齐放的时代,渐行渐远!



    poi导出xlsx格式的excel怎么打不开,求大神帮忙!急

    代码如下
    /**
    * 执行导出Excel操作
    */
    function opExportOne(e) {
    var f = KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲requirePlanDeta…(e.currentTarget).closest(“tr”));
    var url = “${ctx}/oms/requirePlan/1/” + false+"/exportDetail?ids="+f.id;
    window.location.href = url;
    }

    /**
    * Excel导出
    * @param ids
    * @param templateId
    * @param isTransient
    * @param request
    * @param response
    */
    @RequestMapping(value = “{templateId}/{isTransient}/exportDetail”)
    public void exportExcel(@RequestParam(value = “ids”,required = false) String[] ids,
    @PathVariable(“templateId”) String templateId,
    @PathVariable(“isTransient”) boolean isTransient,
    HttpServletRequest request, HttpServletResponse response) {
    Searchable searchable = parseSearchFromExport(request);
    requirePlanDetailService.exportExcel(ids, searchable, response, templateId, isTransient);
    }

    业务层:
    @Override
    public void exportExcel(String[] ids,Searchable searchable, HttpServletResponse response, String templateId, boolean isTransient) {
    searchable.removePageable();
    UserAuthModel userAuthModel = (UserAuthModel) UserInfoUtil.getCurrentLoginUser();
    List purchaseGroupIdList = userAuthModel.getPurchaseGroupIds();
    if (CollectionUtil.isNotEmpty(purchaseGroupIdList)) {
    searchable.addSearchFilter(“groupId”, Operator.IN, purchaseGroupIdList);
    }

    	List<String> storerGroupIds = userAuthModel.getStorerGroupIds();
    	if (CollectionUtil.isNotEmpty(storerGroupIds)) {
    		searchable.addSearchFilter("parentObj.customerId", Operator.IN, storerGroupIds);
    	}
    
    	String[] rowName = {"序号","计划号","计划行号","预留号","提报单元","物料编码","物料描述","供应商","采购订单号","主单位","需求数量","需求日期",
    			"采购申请号","WBS元素","网络号","工单号","工单描述","项目、装置名称","施工单位"};
    	HSSFWorkbook workbook = new HSSFWorkbook();
    	HSSFSheet sheet = workbook.createSheet("需求计划明细表");
    	HSSFCellStyle columnTopStyle = this.getColumnTopStyle(workbook);
    	HSSFCellStyle style = this.getStyle(workbook);
    	// 定义所需列数
    	int columnNum = rowName.length;
    	HSSFRow rowRowName = sheet.createRow(1);
    	rowRowName.setHeight((short) (25 * 25));
    	// 将列头设置到sheet的单元格中
    	for(int n=0;n<columnNum;n++){
    		HSSFCell  cellRowName = rowRowName.createCell(n);                //创建列头对应个数的单元格
    		cellRowName.setCellType(HSSFCell.CELL_TYPE_STRING);                //设置列头单元格的数据类型
    		HSSFRichTextString text = new HSSFRichTextString(rowName[n]);
    		cellRowName.setCellValue(text);                                    //设置列头单元格的值
    		cellRowName.setCellStyle(columnTopStyle);                        //设置列头单元格样式
    	}
    	//写入数据
    	List<RequirePlanDetail> result = requirePlanDetailRepository.findAll(Arrays.asList(ids));
    	int i = 1;
    	for(RequirePlanDetail requirePlanDetail : result){
    		if(requirePlanDetail.getIsResease().equals(YesNoEnum.YES.getCode())){
    			continue;
    		}
    		HSSFRow row = sheet.createRow(++i);
    		row.setHeight((short) (30 * 20));
    
    		HSSFCell  cell0 = row.createCell(0);
    		cell0.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
    		cell0.setCellValue(i - 1);
    		cell0.setCellStyle(style);
    		this.setStyleAndValue(row.createCell(1), requirePlanDetail.getPlanNo(), style);
    		this.setStyleAndValue(row.createCell(2),requirePlanDetail.getColNo(),style);
    		this.setStyleAndValue(row.createCell(3),requirePlanDetail.getReserveNo(),style);
    		this.setStyleAndValue(row.createCell(4), requirePlanDetail.getParentObj().getCustomerName(), style);
    		this.setStyleAndValue(row.createCell(5),requirePlanDetail.getPartNo(),style);
    		this.setStyleAndValue(row.createCell(6),requirePlanDetail.getPartName(),style);
    		this.setStyleAndValue(row.createCell(7),requirePlanDetail.getVendorName(),style);
    		this.setStyleAndValue(row.createCell(8),requirePlanDetail.getPoNo(),style);
    		this.setStyleAndValue(row.createCell(9),requirePlanDetail.getUnitName(),style);
    		this.setStyleAndValue(row.createCell(10),String.valueOf(requirePlanDetail.getQtyRequire()),style);
    		this.setStyleAndValue(row.createCell(11),requirePlanDetail.getParentObj().getRequireDate() == null ? "" : DateUtil.formatDate(requirePlanDetail.getParentObj().getRequireDate(), "yyyy-MM-dd HH:mm:ss"),style);
    		this.setStyleAndValue(row.createCell(12),requirePlanDetail.getApplyNo(),style);
    		this.setStyleAndValue(row.createCell(13),requirePlanDetail.getWbsElement(),style);
    		this.setStyleAndValue(row.createCell(14),requirePlanDetail.getNetworkNo(),style);
    		this.setStyleAndValue(row.createCell(15),requirePlanDetail.getJobNo(),style);
    		this.setStyleAndValue(row.createCell(16),requirePlanDetail.getJobDesc(),style);
    		this.setStyleAndValue(row.createCell(17),requirePlanDetail.getProjectName(),style);
    		this.setStyleAndValue(row.createCell(18),requirePlanDetail.getBuilderName(),style);
    	}
    	//让列宽随着导出的列长自动适应
    	for (int colNum = 0; colNum <=18; colNum++) {
    		int columnWidth = sheet.getColumnWidth(colNum) / 256;
    		for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {
    			HSSFRow currentRow;
    			//当前行未被使用过
    			if (sheet.getRow(rowNum) == null) {
    				currentRow = sheet.createRow(rowNum);
    			} else {
    				currentRow = sheet.getRow(rowNum);
    			}
    			if (currentRow.getCell(colNum) != null) {
    				HSSFCell currentCell = currentRow.getCell(colNum);
    				if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
    					int length = currentCell.getStringCellValue().getBytes().length;
    					if (columnWidth < length) {
    						columnWidth = length;
    					}
    				}
    			}
    		}
    		if(colNum == 0){
    			sheet.setColumnWidth(colNum, (columnWidth-2) * 128);
    		}else{
    			sheet.setColumnWidth(colNum, (columnWidth+4) * 256);
    		}
    	}
    
    	try {
    		String fileName = "需求计划明细";
    		//输出Excel文件
    		OutputStream output=response.getOutputStream();
    		response.setHeader("Content-Disposition", "attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName + DateUtil.formatDate(new Date(), "yyyyMMdd") + ".xlsx", "UTF-8"))));
    		response.setHeader("Connection", "close");
    		response.setHeader("Content-Type", "application/vnd.ms-excel");
    		workbook.write(output);
    		output.close();
    	}catch(Exception e){
    		LogUtil.logError("导出Excel失败!原因:" + e.getMessage());
    	}
    }
    
    /*
     * 列头单元格样式
     */
    public HSSFCellStyle getColumnTopStyle(HSSFWorkbook workbook) {
    	HSSFFont font = workbook.createFont();
    	font.setFontHeightInPoints((short) 12);
    	font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    	HSSFCellStyle style = workbook.createCellStyle();
    	style.setFont(font);
    	style.setWrapText(false);
    	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    	style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    	style.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    	style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    	style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
    	style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
    	style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
    	style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
    	return style;
    }
    
    /*
     * 列数据信息头单元格样式
     */
    public HSSFCellStyle getStyle(HSSFWorkbook workbook) {
    	HSSFFont font = workbook.createFont();
    	font.setFontHeightInPoints((short) 12);
    	HSSFCellStyle style = workbook.createCellStyle();
    	style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
    	style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
    	style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
    	style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
    	style.setFont(font);
    	style.setWrapText(false);
    	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    	style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    
    	return style;
    
    }
    
    /*
     * 列数据信息单元格样式
     * @param cell
     * @param value
     * @param style
     */
    public void setStyleAndValue(HSSFCell cell,String value,HSSFCellStyle style){
    	cell.setCellType(HSSFCell.CELL_TYPE_STRING);
    	HSSFRichTextString text = new HSSFRichTextString(value);
    	cell.setCellValue(text);
    	cell.setCellStyle(style);
    }
    

    插入链接与图片

    链接: link.

    图片: Alt

    带尺寸的图片: Alt

    居中的图片: Alt

    居中并且带尺寸的图片: Alt

    当然,我们为了让用户更加便捷,我们增加了图片拖拽功能。

    如何插入一段漂亮的代码片

    去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

    // An highlighted block
    var foo = 'bar';
    

    生成一个适合你的列表

    • 项目
      • 项目
        • 项目
    1. 项目1
    2. 项目2
    3. 项目3
    • 计划任务
    • 完成任务

    创建一个表格

    一个简单的表格是这么创建的:

    项目Value
    电脑$1600
    手机$12
    导管$1

    设定内容居中、居左、居右

    使用:---------:居中
    使用:----------居左
    使用----------:居右

    第一列第二列第三列
    第一列文本居中第二列文本居右第三列文本居左

    SmartyPants

    SmartyPants将ASCII标点字符转换为“智能”印刷标点HTML实体。例如:

    TYPEASCIIHTML
    Single backticks'Isn't this fun?'‘Isn’t this fun?’
    Quotes"Isn't this fun?"“Isn’t this fun?”
    Dashes-- is en-dash, --- is em-dash– is en-dash, — is em-dash

    创建一个自定义列表

    Markdown
    Text-to- HTML conversion tool
    Authors
    John
    Luke

    如何创建一个注脚

    一个具有注脚的文本。1

    注释也是必不可少的

    Markdown将文本转换为 HTML。

    KaTeX数学公式

    您可以使用渲染LaTeX数学表达式 KaTeX:

    Gamma公式展示 Γ ( n ) = ( n − 1 ) ! ∀ n ∈ N \Gamma(n) = (n-1)!\quad\forall n\in\mathbb N Γ(n)=(n1)!nN 是通过欧拉积分

    Γ ( z ) = ∫ 0 ∞ t z − 1 e − t d t &ThinSpace; . \Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,. Γ(z)=0tz1etdt.

    你可以找到更多关于的信息 LaTeX 数学表达式here.

    新的甘特图功能,丰富你的文章

    Mon 06 Mon 13 Mon 20 已完成 进行中 计划一 计划二 现有任务 Adding GANTT diagram functionality to mermaid cs