excel导入数据

1.pom

        <!-- jwt -->
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>${jwt.version}</version>
        </dependency>

        <dependency>
            <groupId>net.sourceforge.jexcelapi</groupId>
            <artifactId>jxl</artifactId>
            <version>2.6.12</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel-core</artifactId>
            <version>3.2.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi-ooxml</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi-ooxml-schemas</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>4.1.2</version>
        </dependency>

2. 导入数据代码

    @ApiOperation(value = "网页名称地址字典导入", httpMethod = "POST")
    @PostMapping("/importWebUrl")
    @MustAuth(mustLogin = false)
    @LogDiy(title = "网页名称地址字典导入")
    public void importWebUrl(String excelFilePath) {
        try (FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
             Workbook workbook = new XSSFWorkbook(inputStream)) {
            Sheet sheet = workbook.getSheetAt(0); // 读取第一个工作表
            for (Row row : sheet) { // 迭代每一行
                if (row.getRowNum() != 0) {
                    String stringCellValue = row.getCell(0).getStringCellValue();
                    String stringCellValue1 = row.getCell(1).getStringCellValue();
                    JSONObject jsonObject = JSONObject.parseObject(stringCellValue);
                    String webName = jsonObject.get("website_name").toString();
                    WebDomainDictionaryTable webDomain = new WebDomainDictionaryTable();
                    String domain = "";
                    if (stringCellValue1.startsWith("http")) {
                        URL url = new URL(stringCellValue1);
                        domain = url.getHost();
                    } else {
                        domain = stringCellValue1;
                    }
                    webDomain.setInsertTime(new Date());
                    webDomain.setUrl(domain);
                    webDomain.setWebsiteName(webName);
                    service.save(webDomain);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值