java解析xls文件做报表上传的功能

controller层展示

@RequestMapping(value = "/batch", method = RequestMethod.POST)
public HttpResult batchAdd(@RequestAttribute User user, @RequestParam MultipartFile file)
        throws IOException, BiffException {
    HttpResult result = null;
    Sheet sheet = null;
    logService.add(new SystemLog(user, "报表上传", "批量上传"));
    Workbook workbook = null;
    List<String> errors = null;
    ReportParams reportParams = null;
    try {
        workbook = Workbook.getWorkbook(file.getInputStream());
        sheet = workbook.getSheet(0);
        errors = new ArrayList<>();
        reportParams = new ReportParams();
    } catch (BiffException e) {
        e.printStackTrace();
        return HttpResult.newError("提交的文件不是真实.xls格式!请将文件另存为.xls格式之后再提交!");
    }
    for (int i = 1; i < sheet.getRows(); i++) {
        Cell[] cells = sheet.getRow(i);
        if(!cells[0].getContents().isEmpty()){
        reportParams.setCompanyCode(cells[0].getContents());
        reportParams.setCustomerNumber(cells[1].getContents());
        reportParams.setCustomerName(cells[2].getContents());
        reportParams.setMaterialNumber(cells[3].getContents());
        reportParams.setMaterialName(cells[4].getContents());
        reportParams.setTradeName(cells[5].getContents());
        reportParams.setSpecifications(cells[6].getContents());
        reportParams.setManufacturer(cells[7].getContents());
        reportParams.setUnit(cells[8].getContents());
        reportParams.setNumber(Double.parseDouble(cells[9].getContents()));
        reportParams.setUploadPeople(cells[10].getContents());
        result = reportService.add(reportParams);

        int status = (int) result.get("status");
        if (status != 200) {
            errors.add(String.valueOf(result.get("msg")));
            return result.add("errors", errors);
        }
    }
    }
    return result.add("errors", errors);
}

实体类展示

public class ReportParams {
    private int id;
    private String companyCode;
    private String customerNumber;
    private String customerName;
    private String materialNumber;
    private String materialName;
    private String tradeName;
    private String specifications;
    private String manufacturer;
    private String Unit;
    private Double number;
    private String uploadPeople;
    private List<String> time = new ArrayList<>();

    public List<String> getTime() {
        return time;
    }

    public void setTime(List<String> time) {
        this.time = time;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCompanyCode() {
        return companyCode;
    }

    public void setCompanyCode(String companyCode) {
        this.companyCode = companyCode;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getMaterialNumber() {
        return materialNumber;
    }

    public void setMaterialNumber(String materialNumber) {
        this.materialNumber = materialNumber;
    }

    public String getMaterialName() {
        return materialName;
    }

    public void setMaterialName(String materialName) {
        this.materialName = materialName;
    }

    public String getTradeName() {
        return tradeName;
    }

    public void setTradeName(String tradeName) {
        this.tradeName = tradeName;
    }

    public String getSpecifications() {
        return specifications;
    }

    public void setSpecifications(String specifications) {
        this.specifications = specifications;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public String getUnit() {
        return Unit;
    }

    public void setUnit(String unit) {
        Unit = unit;
    }

    public Double getNumber() {
        return number;
    }

    public void setNumber(Double number) {
        this.number = number;
    }

    public String getUploadPeople() {
        return uploadPeople;
    }

    public void setUploadPeople(String uploadPeople) {
        this.uploadPeople = uploadPeople;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值