easy_poi合并行以及样式调整

package com.example.springboottest;

import cn.afterturn.easypoi.cache.manager.POICacheManager;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelXorHtmlUtil;
import cn.afterturn.easypoi.excel.entity.ExcelToHtmlParams;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.util.PoiMergeCellUtil;
import cn.afterturn.easypoi.util.StyleUtil;
import cn.afterturn.easypoi.word.WordExportUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.*;

@RunWith(SpringRunner.class)
@SpringBootTest(properties = "spring.main.web-application-type=reactive")
public class SpringboottestApplicationTests {

    @Test
    public  void fe_map() throws Exception {
        TemplateExportParams params = new TemplateExportParams(
                "G:\\file\\test.xls");
        Map map = new HashMap();
        List> listMap = new ArrayList>();
        for (int i = 0; i < 4; i++) {
            Map lm = new HashMap();
            lm.put("id","1");
            lm.put("schoolName","河北科技师范学院"+i);
            lm.put("name","张三"+i);
            lm.put("age",10*i+(Math.pow(i,2)));
            List> listsMap = new ArrayList>();
            for(int j=0;j<4;j++){
                Map map1=new HashMap<>();
                map1.put("name","张三"+j);
                listsMap.add(map1);
            }
            lm.put("stulist",listsMap);
            listMap.add(lm);
        }
        map.put("maplist", listMap);

        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        Sheet sheet = workbook.getSheetAt(0);
        System.out.println(sheet.getFirstRowNum());
        Cell cell = sheet.getRow(5).getCell(2);
        CellStyle cellStyle = workbook.createCellStyle();
//        cellStyle.setHidden(true);
        cellStyle.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.DARK_BLUE.getIndex2());
        cellStyle.setFillForegroundColor(IndexedColors.AQUA.index);
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        Font font=workbook.createFont();
        font.setBold(true);
        font.setColor(IndexedColors.BLUE1.index);
        cellStyle.setFont(font);
        StyleUtil.changeStyle(sheet,0,9,0,3,cellStyle);
        cell.setCellStyle(cellStyle);
//        Cell cell = row.createCell(5);
//        cell.setCellStyle(cellStyle);
//        cell.setCellValue(52);
        /**合并单元格**/
//        PoiMergeCellUtil.mergeCells(6,sheet,8,0,1);
        File savefile = new File("G:\\file\\");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream("G:\\file\\专项支出用款申请书_map.xls");
        workbook.write(fos);
        fos.close();
    }
    public static String disposeNullByKg(Object str) {
        if(str==null) {
            return " ";
        }else {
            return String.valueOf(str);
        }
    }
}

你可能感兴趣的:(easypoi)