package cn.com.qmth.examcloud.tool;

import cn.com.qmth.examcloud.tool.utils.ExcelHelper;
import com.alibaba.excel.EasyExcel;
import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class DataTest {

    @Test
    public void demo() throws Exception {
        String dataFilePath = ToolTest.DATA_DIR + "ddd.xlsx";

        List<List<String>> excelRows = new ArrayList<>();
        for (int i = 1; i <= 100; i++) {
            String code = "S" + (100000000L + i);

            List<String> data = new ArrayList<>();
            data.add("考生_" + i);
            data.add(code);
            data.add(code);
            data.add("org101");
            data.add("");
            data.add("c101");
            data.add("");
            data.add("");
            excelRows.add(data);
        }

        List<String> excelHeaders = Lists.newArrayList("姓名", "学号", "身份证号", "机构代码", "机构名称",
                "课程代码", "课程名称", "专业名称");
        EasyExcel.write(dataFilePath)
                .head(ExcelHelper.buildHeaders(excelHeaders))
                .registerWriteHandler(ExcelHelper.sheetStrategy())
                .sheet()
                .doWrite(excelRows);
    }

}
