记一次 Vue + cloud项目进行导出指定数据

5 篇文章 0 订阅
1 篇文章 0 订阅

 前端页面:

一个简单的Vue导出按钮!

<!--导出按钮-->
<el-form-item>
<el-button size="mini" type="primary" @click="exportData">导出</el-button>
</el-form-item>

 这个是前端给后台控制端传送值的地点!不知道写法对不对 但是可以给后端传递到需要的数据!

	  // 导出Excel表
	  const exportData = async () => {
		  const { data } = await _this.$API.system.get(
			  _this.$BASEDATA.exportData, {
				  //给后台传递需要的值
				  projectId: reactiveParams.infoForm.projectId,
			  }
		  );
	  };

 后端代码

Gatway层

    //导出Excel表
    void exportInvoice(List<DataMyannotationsEntity> list, String path) throws IOException;

    //导出Excel表
    @Override
    public void exportInvoice(List<DataMyannotationsEntity> list, String path) throws IOException {
        dataProjectconterService.exportInvoice(list, path);
    }

Server层

    //导出Excel表
    void exportInvoice(List<DataMyannotationsEntity> list, String path) throws IOException;

 /**
     * 导出Excel
     * @param list
     * @param path
     * @throws IOException
     */
    @Override
    public void exportInvoice(List<DataMyannotationsEntity> list, String path) throws IOException {
        //创建工作表
        XSSFWorkbook workbook=new XSSFWorkbook();
        XSSFSheet sheet=workbook.createSheet();
        XSSFRow row=sheet.createRow(0);
        //设置单元格内容
        row.createCell(0).setCellValue("标注日期");
        row.createCell(1).setCellValue("姓名");
        row.createCell(2).setCellValue("题包号");
        row.createCell(3).setCellValue("计划标注量");
        row.createCell(4).setCellValue("实际标注量");
        //遍历导出数据
        for(int i =0;i<list.size();i++){
            XSSFRow row1 = sheet.createRow(i + 1);
            row1.createCell(0).setCellValue(list.get(i).getProjectTime());
            row1.createCell(1).setCellValue(list.get(i).getUpdatedBy());
            row1.createCell(2).setCellValue(list.get(i).getProjectName());
            row1.createCell(3).setCellValue(list.get(i).getPackageFrames()+"/"+list.get(i).getPackageCircles());
            row1.createCell(4).setCellValue(list.get(i).getFrames()+"/"+list.get(i).getCircles());
        }
        FileOutputStream fileOutputStream=new FileOutputStream(path);
        workbook.write(fileOutputStream);
        fileOutputStream.flush();
        fileOutputStream.close();
        workbook.close();
    }

Controller层

 /**
     * 导出Excel表,导出的excel表会直接存在于系统桌面上
     * @param dataMyannotationsEntity :获取前端传入过来的数据
     * @param projectId
     */
    @GetMapping("/exportData")
    public void exportData(@Validated DataMyannotationsEntity dataMyannotationsEntity,
                           @RequestParam(defaultValue = "", name = "projectId") String projectId) {
                //构造器查询
                QueryWrapper<DataMyannotationsEntity> queryWrapper=new QueryWrapper<>();
                //输入查询条件,根据指定的字段排序
                queryWrapper.eq("project_id", projectId)
                            .orderByAsc("project_time");
                //查询符合条件的字段
                List<DataMyannotationsEntity> list = dataMyannotationsService.getBaseMapper().selectList(queryWrapper);
                try {
                    //获取系统桌面路径
                    File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory();
                    String desktoPath = desktopDir.getAbsolutePath();
                    //导出的文件加名
                    String path = desktoPath + "\\标注计划导出.xlsx";
                    dataProjectcenterService.exportInvoice(list, path);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

总结: 项目经验太少,逻辑思维不清楚,对于前端技术的迷惘!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值