employeeManager-master/src/main/java/com/suny/utils/ExcelUtils.java

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package com.suny.utils;

import com.suny.entity.Employee;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class ExcelUtils {

    /**
     * 下载学生数据模板
     *
     * @param fileDir 要生成的模板的文件地址
     * @throws IOException 抛出IO流异常
     */
    public static void buildExcel(String fileDir, List employeeList) throws IOException {
        Workbook workbook = new XSSFWorkbook();                                    //创建一个表格
        Sheet sheet1 = workbook.createSheet("students");                          //创建一张工作表
        setTitles(sheet1);                                                       //设置标题行
        setStudentDetails(sheet1, employeeList);                                                    //填充数值
        FileOutputStream fileOutputStream = new FileOutputStream(fileDir);         //输出文件
        workbook.write(fileOutputStream);                                        //写入文件
        fileOutputStream.close();                                                //关闭
    }

    /**
     * 填充表格数据
     *
     * @param sheet1 Excel数据表
     */
    public static void setStudentDetails(Sheet sheet1, List employeeList) {
        Cell cell;
        for (int i = 0; i < employeeList.size(); i++) {
            //"序列号","姓名","班级","电话号码","寝室号","部门编号"
            Row row1 = sheet1.createRow(i + 1);        //因为前面已经创建了标题行,所以从第2行开始
            Employee employee = (Employee) employeeList.get(i);       //从第一个开始读取
            //序列号
            cell = row1.createCell(0);
            cell.setCellValue("" + i);
            //中间空缺账号密码,为不提供下载信息
            //成员姓名
            cell = row1.createCell(3);
            cell.setCellValue(employee.getEmpName());
            //所在班级
            cell = row1.createCell(4);
            cell.setCellValue(employee.getClassName());
            //电话号码
            cell = row1.createCell(5);
            cell.setCellValue(employee.getTel());
            //寝室号
            cell = row1.createCell(6);
            cell.setCellValue(employee.getBedroom());
后面还有 92 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。