国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java POI (2)—— Excel文件的上傳與導出(實例演示)

這篇具有很好參考價值的文章主要介紹了Java POI (2)—— Excel文件的上傳與導出(實例演示)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、單文件的上傳功能

Java POI (2)—— Excel文件的上傳與導出(實例演示),編程,開發(fā),java,spring boot,intellij-idea,idea

?????????這里是一個demo的流程圖,下面按照這個流程圖做了一個簡單的實現(xiàn),有部分判斷沒有加上,實際操作中,可以根據(jù)自己的需求進行增加或者修改。并且此處還是在接受文件傳入后將文件進行了下載,保存到本地的操作,這個要按照具體情況具體分析,看需求是否要把上傳進來的文件進行數(shù)據(jù)備份,或者直接以流的形式讀進來,然后進行解析等邏輯操作后,最后關(guān)閉釋放流也可以,沒有說一定要上傳完文件就要下載下來。

controller層 (接受前端傳入的文件參數(shù),為單個文件)

@RequestMapping( "/salary/server/excelxz")
public class SalaryExcelOperatController {

    @Autowired
    private SalaryExcelOperatService salaryexcelOperatService;

    @PostMapping("/upload")
    public RespondDto uploadFile(@RequestParam("file") MultipartFile multipartFile) {
    SalaryExcelOperatVo excelOperatVo =salaryexcelOperatService.uploadExcel(multipartFile);
    return new RespondDto(excelOperatVo);
}

service層 (這里使用了easyExcel的方式實現(xiàn)了,一個Excel中包含多個sheet的讀取操作,但本質(zhì)和POI的思想是差不多的?)

@Service
@Slf4j
public class SalaryExcelOperatServiceImpl implements SalaryExcelOperatService {


    @Resource
    private SalaryExcelOperatMapper salaryexcelOperatMapper;
    @Resource
    private LoginMapper loginMapper;

    /**
     * 上傳 Excel 文件
     * 1、接收文件,保存到本地;
     * 2、獲取本地文件路徑調(diào)用 readExcel 讀成ArrayList;
     */
    @Override
    public SalaryExcelOperatVo uploadExcel(MultipartFile multipartFile) {

        if (multipartFile==null) {
            log.error("文件不能為空");
             throw new RuntimeException("上傳Excel文件內(nèi)容為空,請重新上傳!");
        }
        String fileName = multipartFile.getOriginalFilename();
        //判斷文件是否是excel文件
        assert fileName != null;
        if (!fileName.endsWith("xls") && !fileName.endsWith("xlsx")) {
            log.error(fileName + "不是Excel文件!");
            throw new RuntimeException(fileName + "不是Excel文件!");
        }

        //保存文件到本地
        File dir1 = new File("/roots/uploadFile/xzExcel");
        if (!dir1.exists()) {
            dir1.mkdirs();
        }
        //統(tǒng)一日期格式
        LocalDateTime current = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formatted = current.format(formatter);
        //加上三位隨機數(shù)
        Random random = new Random();
        int end3 = random.nextInt(999);

        File file1 = new File(dir1.getAbsolutePath() + File.separator + formatted + "-" + end3 + "-" + multipartFile.getOriginalFilename());
        try {
            multipartFile.transferTo(file1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        //創(chuàng)建返回對象SalaryExcelOperatVo的實例化對象: result
        SalaryExcelOperatVo result = new SalaryExcelOperatVo();
        //獲取excel文件sheet1 的內(nèi)容
        ArrayList<InSalary> inSalaries1 = readExcel1(file1.getAbsolutePath());

        ArrayList<SalaryStaffPerOneListVo> vo1 = new ArrayList<>();

        SalaryStaffPerOneListVo oneListVo ;

        for(InSalary inSalary1:inSalaries1){
            oneListVo = new SalaryStaffPerOneListVo();
            BeanUtils.copyProperties(inSalary1,oneListVo);
            vo1.add(oneListVo);
}
        result.setSheetOne(vo1);

        //獲取excel文件sheet2 的內(nèi)容
        ArrayList<InSalary> inSalaries2 = readExcel2(file1.getAbsolutePath());

        ArrayList<SalaryStaffPerTwoListVo> vo2 = new ArrayList<>();

        SalaryStaffPerTwoListVo twoListVo ;
        for(InSalary inSalary2:inSalaries2){
            twoListVo = new SalaryStaffPerTwoListVo();
            BeanUtils.copyProperties(inSalary2,twoListVo);
            vo2.add(twoListVo);
        }

        result.setSheetTwo(vo2);
        return result;
    }

    /**
     * 抽離出   【讀取excel文件,包含多個sheet內(nèi)容的方法】
     * 1、工作區(qū)間 -> Sheet -> cell;
     * 2、每行為一個 inSalary 對象, 把所有對象用 ArrayList保存;
     * 從第二行開始讀取,第一行表頭忽略;
     *
     * @param filePath ;本地保存后的文件地址
     * @return ArrayList<InSalary>
     */
    private ArrayList<InSalary> readExcel1(String filePath) {

        ArrayList<InSalary> inSalary = new ArrayList<>();

        // 該監(jiān)聽將excel文件一行一行讀入內(nèi)存(必須有)
        SalaryExcelListener listener = new SalaryExcelListener();
        ExcelReader excelReader = EasyExcel.read(filePath, InSalary.class,
                listener).build();
        ReadSheet readSheet = EasyExcel.readSheet(0).build();
        excelReader.read(readSheet);
        // 這里千萬別忘記關(guān)閉,讀的時候會創(chuàng)建臨時文件,到時磁盤會崩的
        excelReader.finish();
        // readList 文件中的數(shù)據(jù),不包括表頭
        inSalary .addAll(listener.getList());
        return inSalary;
    }
    private ArrayList<InSalary> readExcel2(String filePath) {

        ArrayList<InSalary> inSalary = new ArrayList<>();

        // 該監(jiān)聽將excel文件一行一行讀入內(nèi)存(必須有)
        SalaryExcelListener listener = new SalaryExcelListener();
        ExcelReader excelReader = EasyExcel.read(filePath, InSalary.class,
                listener).build();
        ReadSheet readSheet = EasyExcel.readSheet(1).build();
        excelReader.read(readSheet);
        // 這里千萬別忘記關(guān)閉,讀的時候會創(chuàng)建臨時文件,到時磁盤會崩的
        excelReader.finish();
        // readList 文件中的數(shù)據(jù),不包括表頭
        inSalary .addAll(listener.getList());
        return inSalary;
    }

二、多文件的上傳功能?

controller層 (接受前端傳入的文件參數(shù),為多個文件)

    @PostMapping(value = "/uploadExcels")
    public RespondDto upLoadFiles(@NonNull @RequestParam("multipartFiles") MultipartFile[] multipartFiles,
                                  @NonNull @RequestParam("types") String[] types){
        return fileService.upLoadFiles(multipartFiles,types);
    }

????????這里需要說明一點,controller層的實現(xiàn)方式有很多中,沒有說當要傳入多個文件的時候一定要去使用數(shù)組的形式進行 ,在這樣寫之前我也嘗試了其他的兩種寫法:

    @PostMapping("/upload")
    public String upload(@RequestParam("files") List<MultipartFile> files, HttpServletRequest request) {
        for (MultipartFile file : files) {
            String type1 = request.getParameter("type1");
            String type2 = request.getParameter("type2");
            // 根據(jù)type1和type2的值,對上傳的文件進行特定處理
            // ...
        }
        return "upload success";
    }
    @PostMapping(value = "/uploadExcels")
    public RespondDto upLoadFiles(@NonNull @RequestParam("multipartFiles") List<MultipartFile> multipartFiles,
                                  @NonNull @RequestParam("types") List<MultipartFile> types){
        return fileService.upLoadFiles(multipartFiles,types);
    }

?不過實際中具體怎么寫,還是看跟前端的溝通以及最終的接口文檔來進行操作。

service層 (這里實現(xiàn)了將多個Excel一次性上傳后,后端將這些Excel文件進行接收并保存到本地,并且將每個文件的名字以文件類型的名字進行重命名)

@Override
public RespondDto upLoadFiles(MultipartFile[] files, String[] types) {

    long MAX_SIZE = 1024 * 1024 * 10;// 文件大小限制為10MB
    LocalDateTime current = LocalDateTime.now();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    String formattedDate = current.format(formatter);
    //加上三位隨機數(shù)
    Random random = new Random();
    int randomNum = random.nextInt(999);
    File dir = new File("/manage/uploadFile/"+formattedDate+randomNum);
    if (!dir.exists()) {
            dir.mkdirs();
    }

    for (int i = 0; i < files.length; i++) {
            MultipartFile file = files[i];
            String type = types[i];
            // 判斷文件或類型不能為空
            if (file.isEmpty() || StringUtils.isEmpty(type)) {
                return new RespondDto<>("文件或類型不能為空,請重新上傳!");
            }
            // 判斷文件大小是否合適
            if (file.getSize() > MAX_SIZE) {
                return new RespondDto<>("文件過大,上傳失敗!");
            }
            String originalFileName = file.getOriginalFilename();
            // 獲取文件名和擴展名
            String fileExt = originalFileName.substring(originalFileName.lastIndexOf("."));
            String fileName = type ;
            File fileToSave = new File(dir.getAbsolutePath() + File.separator + fileName +fileExt);
        try {
                //文件寫入 transferTo
                file.transferTo(fileToSave);
                String fileUrl =  fileToSave.getAbsolutePath();
                 fileUrls.add(fileUrl);
       } catch (IOException e) {
                e.printStackTrace();
                return new RespondDto<>("文件上傳失敗!");
       }
            log.info("【上傳文件】"+fileName+" 已保存到本地:{}", originalFileName, fileToSave.getAbsolutePath());
     }
     return new RespondDto<>(fileUrls);
}

?在postman中進行測試,結(jié)果為:

Java POI (2)—— Excel文件的上傳與導出(實例演示),編程,開發(fā),java,spring boot,intellij-idea,idea

三、文件導出功能

①、導出帶有圖片的Excel

@RestController
@RequestMapping( "/salary/server/excel")
@Slf4j
public class ExportjxExcelsController {

    @Value("#{'${headerTitles}'.split(',')}")
    private String[] headerTitles;

    @Autowired
    StaffMapper staffMapper;

    @GetMapping("/jxdownload")
    public void export( HttpServletResponse response ,Integer year,Integer month) throws IOException {

        //設置響應
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // 設置要導出的文件名, 這里URLEncoder.encode可以防止中文亂碼 當然和easyexcel沒有關(guān)系
        String fileName= URLEncoder.encode("XXXX數(shù)據(jù)","UTF-8").replaceAll("\\+","%20");
        response.setHeader("Content-disposition","attachment;filename*=utf-8''"+fileName+".xlsx");


        // 從數(shù)據(jù)庫ensure表中讀取數(shù)據(jù)
        List<Salary> userList =  staffMapper.getAllStaff(year, month);
        log.info("數(shù)據(jù)為:\n{}", userList);

        List<Map<String, String>> salaryList = new ArrayList<>();
        for (Salary salary : userList) {

            Map<String, String> salaryMap = new LinkedHashMap<>();

            salaryMap.put("userName", salary.getUserName());
            salaryMap.put("firstDepart", salary.getFirstDepart());
            salaryMap.put("secondDepart", salary.getSecondDepart());
            salaryMap.put("post", salary.getPost());;
            salaryMap.put("careDeduct", salary.getCareDeduct());
            salaryMap.put("personalTax", salary.getPersonalTax());
            salaryMap.put("actualPay", salary.getActualPay());
            salaryMap.put("socialUnitpart", salary.getSocialUnitpart());
            salaryMap.put("amonthlySalary", salary.getAmonthlySalary());
            salaryMap.put("achieveBonus", salary.getAchieveBonus());
            salaryMap.put("status", Integer.valueOf(103).equals(salary.getStatus()) ? "已確認" : "未確認");
            salaryMap.put("evidence", salary.getEvidence());

            salaryList.add(salaryMap);
        }

        //取出map鍵值對中的value值
        List<String> valueList = new ArrayList<>();

        for (Map<String, String> salaryMap : salaryList) {
            Set<Map.Entry<String, String>> entrySet = salaryMap.entrySet();
            for (Map.Entry<String, String> entry : entrySet) {
                valueList.add(entry.getValue());
            }
        }

        //  保存文件到本地
        File dir = new File("/roots/uploadFile/exportxzExcel");
        if (!dir.exists()) {
            dir.mkdirs();
        }
        //加上三位隨機數(shù)
        Random random = new Random();
        int end3 = random.nextInt(999);

        String path = dir.getAbsolutePath() + File.separator + end3  +fileName + ".xlsx";
        log.info("path文件路徑為:{}",path);

        SSExcel07Workbook ssExcel07Workbook = (new SSExcel07Workbook()).openOrCreate(path);
        SSExcel07Sheet sheet = ssExcel07Workbook.createSheet("sheet1");
        // 創(chuàng)建Excel表格頭部(有43個字符串)
        //將表頭數(shù)據(jù)寫入到單元格中
        int col = 0;
        for (String title : headerTitles) {
            SSExcel07Cell cell = sheet.getCellOrCreate(0, col);
            cell.setCellValue(title);
            col++;
        }

        // 將數(shù)據(jù)寫入數(shù)據(jù)到Excel文件中
        // 循環(huán)遍歷 salaryList 中的值,寫入到 Excel 文件中
        int row = 1;
        int col1 = 0;
        for (String strval : valueList) {
            // 判斷當前列是否超過了最大列數(shù),如果超過了,則重置列數(shù),同時行數(shù)加1
            if (col1 >= headerTitles.length) {
                col1 = 0;
                row++;
            }
            if(col1==42){
                //在最后一列插入圖片
                SSExcel07Cell imgCell = sheet.getCellOrCreate(row, 42);

                imgCell.insertImg(strval, 0, 0);
            }else {
                // 獲取當前單元格
                SSExcel07Cell cell = sheet.getCellOrCreate(row, col1);
                // 將當前單元格的值設置為當前的 strval 值
                cell.setCellValue(strval);
            }
            // 將列數(shù)加1
            col1++;
        }
        ssExcel07Workbook.getXSSFWorkBook().write(response.getOutputStream());
        log.info("文件導出完成!");
    }
}

②、將之前上傳的多個Excel按照一定的映射規(guī)則生成一個Excel文件(映射規(guī)則可以寫在配置文件中,也可以寫到數(shù)據(jù)庫中,主要看映射關(guān)系的改動頻率是多少)

@Override
    public RespondDto writeExcel(String[] fileUrls) throws IOException {

        long startTime=System.currentTimeMillis (); //獲取開始時間

        String fileUrl = null;
        for (String url : fileUrls) {
            fileUrl = url;
        }

        // 讀取配置文件,configFile 是指配置文件的路徑和名稱。
        Properties config = new Properties();
        ClassPathResource configInputStream = new ClassPathResource("config.properties");
        config.load(configInputStream.getInputStream());

        //  保存文件到本地
        File excelDir = new File("/manage/uploadFile");
        if (!excelDir.exists()) {
            excelDir.mkdirs();
        }
        LocalDateTime current = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate = current.format(formatter);
        //加上三位隨機數(shù)
        Random random = new Random();
        int randomNum = random.nextInt(999);

        // 獲取文件名
        String destExcelFileName = formattedDate + "-" + randomNum + "-" ;


        FileInputStream destinationFileInputStream = new FileInputStream(excelDir + destExcelFileName);
        Workbook destinationWorkbook = new XSSFWorkbook(destinationFileInputStream);

        Map<String, Workbook> workbookMap = new HashMap<>();

        for (String key : config.stringPropertyNames()) {
            String[] destArray = org.springframework.util.StringUtils.tokenizeToStringArray(key, ".");

            String[] srcArray = org.springframework.util.StringUtils.tokenizeToStringArray(config.getProperty(key), ".");
            System.out.println(srcArray[0]);
            if (destArray == null || srcArray == null || srcArray.length != 3 || destArray.length != 2) {
                continue;
            }
            Workbook sourceWorkbook = null;
            if (workbookMap.containsKey(srcArray[0])) {
                sourceWorkbook = workbookMap.get(srcArray[0]);
            } else {
                // 讀取源文件
                //FileInputStream sourceFileInputStream = new FileInputStream(excelDir + srcArray[0] + ".xlsx");
                FileInputStream sourceFileInputStream = new FileInputStream(fileUrl);
                sourceWorkbook = new XSSFWorkbook(sourceFileInputStream);
                workbookMap.put(srcArray[0], sourceWorkbook);

            }
            Sheet sourceSheet = sourceWorkbook.getSheet(srcArray[1]);
            CellReference sourceCellRef = new CellReference(srcArray[2]);
            Row sourceRow = sourceSheet.getRow(sourceCellRef.getRow());
            Cell sourceCell = null;
            if (sourceRow != null) {
                sourceCell = sourceRow.getCell(sourceCellRef.getCol());
            }

            Sheet destinationSheet = destinationWorkbook.getSheet(destArray[0]);
            CellReference destCellRef = new CellReference(destArray[1]);
            Row destRow = destinationSheet.getRow(destCellRef.getRow());
            if (destRow == null) {
                destRow = destinationSheet.createRow(destCellRef.getRow());
            }
            Cell destCell = destRow.createCell(destCellRef.getCol());
            // 執(zhí)行 copy 方法
            copyCellValue(sourceCell, destCell);
        }
        // 保存目標文件
        FileOutputStream outputStream = new FileOutputStream(excelDir + destExcelFileName);
        destinationWorkbook.write(outputStream);

        // 關(guān)閉資源
        outputStream.close();
        destinationFileInputStream.close();
        destinationWorkbook.close();
        workbookMap.values().forEach(k -> {
            try {
                k.close();
            } catch (IOException e) {
            }
        });

        long endTime=System.currentTimeMillis (); //獲取結(jié)束時間
        System.out.println ( "程序運行時間: " + (endTime-startTime)/1000 + "s" );
        return new RespondDto<>("Excel導出成功!");
    }


    /**
     * copyCellValue() 方法用于將源單元格的值復制到目標單元格中。
     * @param sourceCell 是源單元格對象
     * @param destCell 是目標單元格對象
     */
    public static void copyCellValue(Cell sourceCell, Cell destCell) {
        // 如果 sourceCell 和 destCell 中任意一個為 null,則不進行操作,方法直接返回。
        if (sourceCell == null || destCell == null) {
            return;
        }
        // 首先,將源單元格的單元格樣式克隆到目標單元格上,然后再將源單元格的值賦給目標單元格。
        CellStyle sourceStyle = sourceCell.getCellStyle();
        CellStyle destinationStyle = destCell.getSheet().getWorkbook().createCellStyle();
        destinationStyle.cloneStyleFrom(sourceStyle);
        destCell.setCellStyle(destinationStyle);
        // 如果源單元格的數(shù)據(jù)類型為字符串類型,則復制字符串值;如果為布爾類型,則復制布爾值;如果為公式類型,則復制公式字符串;如果為數(shù)字類型,則復制數(shù)字值。
        if (sourceCell.getCellTypeEnum().equals(CellType.STRING)) {

            destCell.setCellValue(sourceCell.getStringCellValue());

        } else if (sourceCell.getCellTypeEnum().equals(CellType.BOOLEAN)) {

            destCell.setCellValue(sourceCell.getBooleanCellValue());

        } else if (sourceCell.getCellTypeEnum().equals(CellType.FORMULA)) {

            if (DateUtil.isCellDateFormatted(sourceCell)) {
                destCell.setCellValue(sourceCell.getDateCellValue());
            } else {
                destCell.setCellValue(sourceCell.getNumericCellValue());
            }

        } else if (sourceCell.getCellTypeEnum().equals(CellType.NUMERIC)) {
            if (DateUtil.isCellDateFormatted(sourceCell)) {
                destCell.setCellValue(sourceCell.getDateCellValue());
            } else {
                destCell.setCellValue(sourceCell.getNumericCellValue());
            }
            // 如果源單元格是空的,則在目標單元格中寫入一個空串("")。
        } else if (sourceCell.getCellTypeEnum().equals(CellType.BLANK)) {
            destCell.setCellValue("");
        }
    }

四、注意事項

①、在使用poi的時候一定要注意,選對依賴的版本

不能想用什么依賴的版本就使用什么依賴版本,有些方法,不同的版本之間相差還是比較大的,此處我使用的版本就是3.17的,如果你使用3.9版本的依賴,就不能運行成功。

        <!--xlsx(07)-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>

②、當在上傳多個文件的時候,出現(xiàn)?the request was rejected because its size (10821303) exceeds the configured maximum (10485760)的報錯

Java POI (2)—— Excel文件的上傳與導出(實例演示),編程,開發(fā),java,spring boot,intellij-idea,idea????????這是因為springboot默認配置?multipart.max-file-size大小是1M,max-request-size默認大小是10M? 故可以在yml文件中添加:文章來源地址http://www.zghlxwxcb.cn/news/detail-516362.html

spring:
  servlet:
    multipart:
      max-file-size: 100MB
      max-request-size: 500MB

到了這里,關(guān)于Java POI (2)—— Excel文件的上傳與導出(實例演示)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • poi實現(xiàn)Excel文件導出【SpringBoot篇】

    在系統(tǒng)中,數(shù)據(jù)庫的excel文件導出是一項及為基礎的功能。此篇文章將通過實例利用poi實現(xiàn)excel文件導出。 Jakarta POI 是apache的子項目,目標是處理ole2對象。它提供了一組操縱Windows文檔的Java API 。目前比較成熟的是HSSF接口,處理MS Excel(97-2002)對象。它不象我們僅僅是用csv生

    2024年02月05日
    瀏覽(27)
  • Java使用POI導出Excel

    Java使用POI導出Excel

    在項目開發(fā)中往往需要使用到Excel的導入和導出,導入就是從Excel中導入到DB中,而導出就是從DB中查詢數(shù)據(jù)然后使用POI寫到Excel上。 操作Excel目前比較流行的就是 Apache POI 和阿里巴巴的 easyExcel ! 廢話不多說,開始擼起來?。?! POI官網(wǎng);https://poi.apache.org/ POI官網(wǎng)API:https://poi.

    2024年02月04日
    瀏覽(36)
  • Java Poi導出Excel表格詳解

    Java Poi導出Excel表格詳解

    一、導出下面的表格 二、流程詳解 ??????? 1、導出excel需要先將數(shù)據(jù)準備好 ??????? 2、創(chuàng)建工作傅對象SXSSFWorkbook ??????? 3、使用工作傅對象創(chuàng)建sheet對象(工作頁) ??????? 4、使用sheet對象創(chuàng)建行對象row(行對象) ??????? 5、使用row對象創(chuàng)建cell對象(單元格

    2024年02月10日
    瀏覽(28)
  • java poi實現(xiàn)Excel多級表頭導出

    java poi實現(xiàn)Excel多級表頭導出

    最近碰到一個導出,比較繁瑣,也查詢了許多博客,在其中一篇博客的基礎上修改,實現(xiàn)了最終想要的效果。話不多說,直接上效果圖 1.主代碼: 2.合并單元格 3.設置表頭單元格的寬度 4.填充數(shù)據(jù)(注:我這里的數(shù)據(jù)格式是ListMapString, Object類型,可以根據(jù)自己的實際情況來封

    2024年02月03日
    瀏覽(47)
  • 【Java】使用POI按模板樣式導出Excel

    根據(jù)模板樣式進行excel導出。 首先,當然是要有一個excel模板,excel的樣式用wps等進行設置。 然后就是代碼的實現(xiàn)了,先引入POI的依賴: 然后就是實現(xiàn)方法里的代碼,首先定義響應信息: 然后將excel模板轉(zhuǎn)為輸入流,這一步的實現(xiàn)方法有很多,具體選擇因人而異,我這里就舉

    2024年02月14日
    瀏覽(27)
  • java中使用POI生成Excel并導出

    java中使用POI生成Excel并導出

    注:本文章中代碼均為本地Demo版本,若后續(xù)代碼更新將不會更新文章 根據(jù)從數(shù)據(jù)庫查詢出的數(shù)據(jù),將其寫入excel表并導出 我的想法是通過在實體屬性上寫自定義注解的方式去完成。因為我們在代碼中可以通過反射的方式去獲取實體類中全部的注解及屬性名稱等等。我們可以

    2024年02月16日
    瀏覽(27)
  • 使用POI設計一個限制導出日期為三十天,且導出文件為excel

    使用POI設計一個限制導出日期為三十天,且導出文件為excel,前端使用Vue的element ui進行設計,前端可以通過選擇時間來導出具體的表格數(shù)據(jù),根據(jù)用戶選擇的時間進行Excel文件的數(shù)據(jù)導出。 按照需求來設計代碼,根據(jù)element ui對前端代碼進行設計。 后端使用 Java,依賴 Apache

    2024年02月15日
    瀏覽(20)
  • 使用POI和EasyExcel來實現(xiàn)excel文件的導入導出

    使用POI和EasyExcel來實現(xiàn)excel文件的導入導出

    廢話不多說咱們直接上干貨?。。?! 一.讀取Excel表格 【1】使用POI讀取excel表格中的數(shù)據(jù) POI還可以操作我們這個word文檔等等,他不僅僅只能弄Excel,而JXI只能操作excel 1.POI的結(jié)構(gòu),我們可以更具文件的類去選擇 相關(guān)的對象我當前是使用的XLSX來操作的 HSSF - 提供讀寫Microsoft

    2024年02月05日
    瀏覽(31)
  • poi實現(xiàn)excel文件導入導出(基本數(shù)據(jù)導出、含格式導出、含批注導出、含圖片圖表導出)——springboot

    poi實現(xiàn)excel文件導入導出(基本數(shù)據(jù)導出、含格式導出、含批注導出、含圖片圖表導出)——springboot

    本文主要是介紹springboot + poi實現(xiàn)基本的excel文件導入導出,包含數(shù)據(jù)導出導入時數(shù)據(jù)的其他需求校驗,導出含有批注信息、導出含有圖片信息、導出含有圖表信息等的介紹等等,主要是一個demo盡可能簡單明了的來介紹相關(guān)功能即可。有什么問題可以在留言哦!并在文章末尾附

    2024年02月08日
    瀏覽(29)
  • Java原生POI實現(xiàn)的Excel導入導出(簡單易懂)

    Java原生POI實現(xiàn)的Excel導入導出(簡單易懂)

    首先是Controller入口方法 這個接口在postman上傳參是下面這樣的: 注意里面的參數(shù)名稱要和接口上的一致,不然會拿不到值 還有file那里key的類型要選file類型的,這樣就可以在后面value里面選擇文件 然后是Service方法 首先是Controller入口 strJson是用來接受其它參數(shù)的,一般導出的

    2024年02月11日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包