Java - Excel解析示例
内容纲要
package com.****.****.controller;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author wintersakura
 * @version 1.0
 * @date 2023/7/16 10:47
 */

@Api(tags = "*****-EXCEL")
@RestController
@RequestMapping("/xxxx")
public class ExcelImportController {

    /**
     * 导入excel
     *
     * @param file
     */
    @PostMapping("/import")
    public void importExcel(MultipartFile file) throws IOException {
        //1.第一种 头必须和实体(英文)一样
        //文件处理成io流
        InputStream in = file.getInputStream();
//        //io流给ExcelReader
        ExcelReader excelReader = ExcelUtil.getReader(in, 0);

        //2.第二种导入方式
        //忽略第一行头(第一行是中文的情况),直接读取表的内容
        List<List<Object>> list = excelReader.read(1);
        for (int i = 1; i < list.size(); i++) {
            List<Object> row = list.get(i);
            //System.out.print("第" + (i + 1) + "行,");

            for (int j = 0; j < row.size(); j++) {
                String spanValue = row.get(j) + "";
                //System.out.print(spanValue + ", ");
                System.out.print("第" + (i + 1) + "行,第" + (j + 1) + "列,值:" + spanValue);

            }

        }

    }

}
hi,我是秋田猫,很高兴认识你,或许我们可以相互分享各自领域的”宝藏“,祝你天天开心~
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇