package com.bmw.ntt.utils;
import com.bmw.ttm.excel.ExcelUtil;
import com.bmw.ttm.util.UtilDate;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelStyleType;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.export.ExcelExportServer;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.util.*;
public class ExcelExportTemplateTest {
//List<CourseEntity> list = new ArrayList<CourseEntity>();
// CourseEntity courseEntity;
//@Test
// public void one() throws Exception {
// TemplateExportParams params = new TemplateExportParams(
// "C:\\Users\\13571\\Desktop\\exportTemp.xls", true);
// params.setHeadingRows(2);
// params.setHeadingStartRow(2);
// params.setStyle(ExcelStyleType.BORDER.getClazz());
// Map<String, Object> map = new HashMap<String, Object>();
// //sheet 1
// map.put("year", "2013");
// map.put("sunCourses", list.size());
// Map<String, Object> obj = new HashMap<String, Object>();
// map.put("obj", obj);
// obj.put("name", list.size());
//
//
// // sheet 2
// map.put("month", 10);
// Map<String, Object> temp;
// for (int i = 1; i < 8; i++) {
// temp = new HashMap<String, Object>();
// temp.put("per", i * 10);
// temp.put("mon", i * 1000);
// temp.put("summon", i * 10000);
// map.put("i" + i, temp);
// }
// Workbook book = ExcelExportUtil.exportExcel(params, CourseEntity.class, list, map);
// File savefile = new File("D:/excel/");
// if (!savefile.exists()) {
// savefile.mkdirs();
// }
// FileOutputStream fos = new FileOutputStream("D:/excel/exportTemp-ntt-twoSheet.xls");
// book.write(fos);
// fos.close();
//
// }
//@Before
// public void testBefore() {
// courseEntity = new CourseEntity();
// courseEntity.setId("1131");
// courseEntity.setName("小白");
//
// TeacherEntity teacherEntity = new TeacherEntity();
// teacherEntity.setId("12131231");
// teacherEntity.setName("你们");
// courseEntity.setChineseTeacher(teacherEntity);
//
// teacherEntity = new TeacherEntity();
// teacherEntity.setId("121312314312421131");
// teacherEntity.setName("老王");
// courseEntity.setMathTeacher(teacherEntity);
//
// StudentEntity studentEntity = new StudentEntity();
// studentEntity.setId("11231");
// studentEntity.setName("撒旦法司法局");
// studentEntity.setBirthday(new Date());
// studentEntity.setSex(1);
// List<StudentEntity> studentList = new ArrayList<StudentEntity>();
// studentList.add(studentEntity);
// studentList.add(studentEntity);
// courseEntity.setStudents(studentList);
//
// for (int i = 0; i < 3; i++) {
// list.add(courseEntity);
// }
// }
@Test
public void two() throws Exception {
// TemplateExportParams params = new TemplateExportParams(
// "C:\\Users\\13571\\Desktop\\exportTemp.xls", 1);
TemplateExportParams params = new TemplateExportParams("C:\\Users\\13571\\Desktop\\exportTemp.xls", 1);
Map<String, Object> map = new HashMap<String, Object>();
map.put("month", 10);
Map<String, Object> temp;
for (int i = 1; i < 8; i++) {
temp = new HashMap<String, Object>();
temp.put("per", i * 10);
temp.put("mon", i * 1000);
temp.put("summon", i * 10000);
map.put("i" + i, temp);
}
params.setTempParams("t");
params.setSheetName("sheetname");
Workbook book = ExcelExportUtil.exportExcel(params, map);
File savefile = new File("D:/excel/");
if (!savefile.exists()) {
savefile.mkdirs();
}
FileOutputStream fos = new FileOutputStream("D:/excel/exportTemp-ntt-sheets4.xls");
book.write(fos);
fos.close();
}
@Test
public void four() throws Exception {
TemplateExportParams params = new TemplateExportParams(
"C:\\Users\\13571\\Desktop\\ExamNoticeTemplate.xls");
params.setStyle(ExcelStyleType.BORDER.getClazz());
String studentNotice = "1、所有考生根据考试安排表准时出席认证开场说明会和各考试项目,如果没有在规定时间内参加认证或迟到时间5分钟以上的作自动放弃处理, 取消认证资格;\n" +
"\n 2、考试当天请出示身份证,严禁携带手机等通讯设备,如果携带,需交给老师统一保管,一旦发现使用手机,以作弊论处; ";
Map<String, Object> temp = new HashMap<>();
temp.put("cerName", "2016年BMW技师L1认证_3月25日XATC");
temp.put("name", "寇广杰");
temp.put("tel", "13820887481");
temp.put("position", "机电");
temp.put("address", "BMW西安培训中心");
temp.put("dealer", "天津浩之宝");
temp.put("timeTip", "2016-03-25--2016-03-25 \n " +
"具体时间安排请到考试现场查询");
temp.put("studentNotice", studentNotice);
temp.put("verCode", "087312");
List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
for (int i = 0; i < 13; i++) {
Map<String, String> lm = new HashMap<String, String>();
lm.put("id", i+"");
lm.put("itemName", "功能操作"+i);
listMap.add(lm);
}
params.setSheetName("考试通知");
//Workbook book = ExcelExportUtil.exportExcel(params, Map.class, itemNameList, temp);
temp.put("maplist", listMap);
Workbook book = ExcelExportUtil.exportExcel(params, temp);
book.createSheet("考试通知2");
TemplateExportParams params2 = params;
params2.setSheetName("test1");
Workbook book2 = ExcelExportUtil.exportExcel(params2, temp);
File savefile = new File("D:/excel/");
if (!savefile.exists()) {
savefile.mkdirs();
}
//POIUtils.copySheet((HSSFWorkbook)book, (HSSFSheet)book2.getSheet("test1"), (HSSFSheet)book.getSheet("考试通知2"), true);
POIUtilCopyWorkBook.copySheet((HSSFWorkbook)book2, (HSSFWorkbook)book, 0, 1);
FileOutputStream fos = new FileOutputStream("D:/excel/exportTemp-ntt-A222.xls");
book.write(fos);
FileOutputStream fos1 = new FileOutputStream("D:/excel/exportTemp-ntt-B222.xls");
book2.write(fos1);
fos.close();
fos1.close();
}
@Test
public void outName(){
String name = "ExamNotice"+"_"+ UtilDate.convertDateTimeWithUnderScore(new Date())+".xlsx";
System.out.println(name);
}
}