/*
 * Copyright (c) 2013-2025 Hutool Team and hutool.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.hutool.v7.poi.excel.writer;

import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import cn.hutool.v7.core.collection.ListUtil;
import cn.hutool.v7.core.data.id.IdUtil;
import cn.hutool.v7.core.date.DateUtil;
import cn.hutool.v7.core.io.file.FileUtil;
import cn.hutool.v7.core.lang.Console;
import cn.hutool.v7.core.map.MapUtil;
import cn.hutool.v7.core.util.ObjUtil;
import cn.hutool.v7.poi.excel.ExcelUtil;
import cn.hutool.v7.poi.excel.OrderExcel;
import cn.hutool.v7.poi.excel.TestBean;
import cn.hutool.v7.poi.excel.cell.setters.EscapeStrCellSetter;
import cn.hutool.v7.poi.excel.reader.ExcelReader;
import cn.hutool.v7.poi.excel.style.DefaultStyleSet;
import cn.hutool.v7.poi.excel.style.StyleUtil;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.*;

/**
 * 写出Excel单元测试
 *
 * @author Looly
 */
public class ExcelWriteTest {

	public static Map<String, Object> MAP_DATA_1 = new LinkedHashMap<>();
	public static Map<String, Object> MAP_DATA_2 = new LinkedHashMap<>();

	static {
		MAP_DATA_1.put("姓名", "张三");
		MAP_DATA_1.put("年龄", 23);
		MAP_DATA_1.put("成绩", 88.32);
		MAP_DATA_1.put("是否合格", true);
		MAP_DATA_1.put("考试日期", DateUtil.now());

		MAP_DATA_2.put("姓名", "张三");
		MAP_DATA_2.put("年龄", 23);
		MAP_DATA_2.put("成绩", 88.32);
		MAP_DATA_2.put("是否合格", true);
		MAP_DATA_2.put("考试日期", DateUtil.now());
	}

	@Test
	public void writeNoFlushTest() {
		final List<?> row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.now(), 3.22676575765);
		final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.now(), 250.7676);
		final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.now(), 0.111);
		final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.now(), 35);
		final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.now(), 28.00);
		final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);

		final ExcelWriter writer = ExcelUtil.getWriter();
		writer.write(rows);
		writer.close();
	}

	@Test
	@Disabled
	public void testRowOrColumnCellStyle() {
		final List<?> row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.now(), 3.22676575765);
		final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.now(), 250.7676);
		final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.now(), 0.111);
		final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.now(), 35);
		final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.now(), 28.00);

		final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);
		final BigExcelWriter overtimeWriter = ExcelUtil.getBigWriter("d:/test/style_line.xlsx");

		overtimeWriter.write(rows, true);

		final CellStyle cellStyle = overtimeWriter.getWorkbook().createCellStyle();
		StyleUtil.setBorder(cellStyle, BorderStyle.THIN, IndexedColors.BLACK);
		cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
		cellStyle.setFillForegroundColor((short) 13);
		cellStyle.setDataFormat((short) 22);//时间格式
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
		cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

		//原设置行、列样式的方法
//		overtimeWriter.setRowStyle(2,cellStyle);
//		overtimeWriter.setColumnStyle(1,cellStyle);

		//现增加的设置行、列样式的方法
		//给第三行加背景色
		overtimeWriter.setRowStyleIfHasData(2, cellStyle);
		//给第二列加背景色 从第一行开始加（用于控制有表头时）
		overtimeWriter.setColumnStyleIfHasData(1, 0, cellStyle);

		final CellStyle cellStyle1 = overtimeWriter.getWorkbook().createCellStyle();
		StyleUtil.setBorder(cellStyle1, BorderStyle.THIN, IndexedColors.BLACK);
		cellStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
		cellStyle1.setFillForegroundColor((short) 13);
		cellStyle1.setDataFormat((short) 2);//小数保留两位
		cellStyle1.setAlignment(HorizontalAlignment.CENTER);
		cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
		overtimeWriter.setStyle(cellStyle1, 5, 2);//由于第6列是数字 上面应用了日期格式会错乱，这里单独设置下第六列的格式

		overtimeWriter.close();
	}

	@Test
	@Disabled
	public void writeTest2() {
		final List<String> row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
		final ExcelWriter overtimeWriter = ExcelUtil.getWriter("d:/test/excel/single_line.xlsx");
		overtimeWriter.writeRow(row);
		overtimeWriter.close();
	}

	@Test
	@Disabled
	public void writeWithSheetTest() {
		final ExcelWriter writer = ExcelUtil.getWriterWithSheet("表格1");

		// 写出第一张表
		final List<String> row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
		writer.writeRow(row);

		// 写出第二张表
		writer.setSheet("表格2");
		final List<String> row2 = ListUtil.of("姓名2", "加班日期2", "下班时间2", "加班时长2", "餐补2", "车补次数2", "车补2", "总计2");
		writer.writeRow(row2);

		// 生成文件或导出Excel
		writer.flush(FileUtil.file("d:/test/writeWithSheetTest.xlsx"), true);

		writer.close();
	}

	@Test
	@Disabled
	public void writeTest() {
		final List<?> row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.now(), 3.22676575765);
		final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.now(), 250.7676);
		final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.now(), 0.111);
		final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.now(), 35);
		final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.now(), 28.00);

		final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);
		for (int i = 0; i < 400; i++) {
			// 超大列表写出测试
			rows.add(ObjUtil.clone(row1));
		}

		final String filePath = "d:/test/writeTest.xlsx";
		FileUtil.del(FileUtil.file(filePath));
		// 通过工具类创建writer
		final ExcelWriter writer = ExcelUtil.getWriter(filePath);
		// 通过构造方法创建writer
		// ExcelWriter writer = new ExcelWriter("d:/writeTest.xls");

		// 跳过当前行，即第一行，非必须，在此演示用
		writer.passCurrentRow();
		// 合并单元格后的标题行，使用默认标题样式
		writer.merge(row1.size() - 1, "测试标题");
		// 一次性写出内容，使用默认样式
		writer.write(rows);
		writer.autoSizeColumn(0, true, 0);
		//冻结前两行
		writer.setFreezePane(0, 2);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void mergeTest() {
		final List<?> row1 = ListUtil.of("aa", "bb", "cc", "dd", DateUtil.now(), 3.22676575765);
		final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.now(), 250.7676);
		final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.now(), 0.111);
		final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.now(), 35);
		final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.now(), 28.00);

		final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);

		// 通过工具类创建writer
		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/mergeTest.xlsx");
		final CellStyle style = ((DefaultStyleSet)writer.getStyleSet()).getHeadCellStyle();
		StyleUtil.setColor(style, IndexedColors.RED, FillPatternType.SOLID_FOREGROUND);

		// 跳过当前行，即第一行，非必须，在此演示用
		writer.passCurrentRow();
		// 合并单元格后的标题行，使用默认标题样式
		writer.merge(row1.size() - 1, "测试标题");
		// 一次性写出内容，使用默认样式
		writer.write(rows);

		// 合并单元格后的标题行，使用默认标题样式
		writer.merge(new CellRangeAddress(7, 10, 4, 10), "测试Merge", false);

		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void mergeNotExistCellTest(){
		final ExcelWriter writer = ExcelUtil.getWriter()
			.merge(5);

		writer
			.flush(FileUtil.file("d:/test/mergeNotExist.xlsx"), true)
			.close();
	}

	@Test
	@Disabled
	public void mergeTest2() {
		final ArrayList<Map<String, Object>> rows = ListUtil.of(MAP_DATA_1, MAP_DATA_2);

		// 通过工具类创建writer
		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/writeMapTest.xlsx");
		// 合并单元格后的标题行，使用默认标题样式
		writer.merge(MAP_DATA_1.size() - 1, "一班成绩单");

		// 一次性写出内容，使用默认样式，强制输出标题
		writer.write(rows, true);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeMapTest() {
		final ArrayList<Map<String, Object>> rows = ListUtil.of(MAP_DATA_1, MAP_DATA_2);

		// 通过工具类创建writer
		final ExcelWriter writer = ExcelUtil.getWriter("e:/excel/writeMapTest.xlsx");

		// 设置内容字体
		final Font font = writer.createFont();
		font.setBold(true);
		font.setColor(Font.COLOR_RED);
		font.setItalic(true);
		((DefaultStyleSet)writer.getStyleSet()).setFont(font, true);

		// 合并单元格后的标题行，使用默认标题样式
		writer.merge(MAP_DATA_1.size() - 1, "一班成绩单");
		// 一次性写出内容，使用默认样式
		writer.write(rows, true);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeMapTest2() {
		// 通过工具类创建writer
		final ExcelWriter writer = ExcelUtil.getWriter("e:/writeMapTest2.xlsx");

		// 一次性写出内容，使用默认样式
		writer.writeRow(MAP_DATA_1, true);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeMapWithStyleTest() {
		// 通过工具类创建writer
		final String path = "f:/test/writeMapWithStyleTest.xlsx";
		FileUtil.del(FileUtil.file(path));
		final ExcelWriter writer = ExcelUtil.getWriter(path);
		writer.setStyleSet(null);

		// 一次性写出内容，使用默认样式
		writer.writeRow(MAP_DATA_1, true);

		// 设置某个单元格样式
		final CellStyle orCreateRowStyle = writer.getOrCreateCellStyle(0, 1);
		StyleUtil.setColor(orCreateRowStyle, IndexedColors.RED.getIndex(), FillPatternType.SOLID_FOREGROUND);

		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeMapAliasTest() {
		final Map<Object, Object> row1 = new LinkedHashMap<>();
		row1.put("name", "张三");
		row1.put("age", 22);
		row1.put("isPass", true);
		row1.put("score", 66.30);
		row1.put("examDate", DateUtil.now());
		final Map<Object, Object> row2 = new LinkedHashMap<>();
		row2.put("name", "李四");
		row2.put("age", 233);
		row2.put("isPass", false);
		row2.put("score", 32.30);
		row2.put("examDate", DateUtil.now());

		final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
		// 通过工具类创建writer
		final String file = "d:/test/writeMapAlias.xlsx";
		FileUtil.del(FileUtil.file(file));
		final ExcelWriter writer = ExcelUtil.getWriter(file);
		// 自定义标题
		final ExcelWriteConfig config = writer.getConfig();
		config.addHeaderAlias("name", "姓名");
		config.addHeaderAlias("age", "年龄");
		config.addHeaderAlias("score", "分数");
		config.addHeaderAlias("isPass", "是否通过");
		config.addHeaderAlias("examDate", "考试时间");
		// 合并单元格后的标题行，使用默认标题样式
		writer.merge(4, "一班成绩单");
		// 一次性写出内容，使用默认样式
		writer.write(rows, true);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeMapOnlyAliasTest() {
		final Map<Object, Object> row1 = new LinkedHashMap<>();
		row1.put("name", "张三");
		row1.put("age", 22);
		row1.put("isPass", true);
		row1.put("score", 66.30);
		row1.put("examDate", DateUtil.now());
		final Map<Object, Object> row2 = new LinkedHashMap<>();
		row2.put("name", "李四");
		row2.put("age", 233);
		row2.put("isPass", false);
		row2.put("score", 32.30);
		row2.put("examDate", DateUtil.now());

		final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
		// 通过工具类创建writer
		final String file = "f:/test/test_alias.xlsx";
		FileUtil.del(FileUtil.file(file));
		final ExcelWriter writer = ExcelUtil.getWriter(file);
		final ExcelWriteConfig config = writer.getConfig();
		config.setOnlyAlias(true);
		// 自定义标题
		config.addHeaderAlias("name", "姓名");
		config.addHeaderAlias("age", "年龄");
		// 合并单元格后的标题行，使用默认标题样式
		writer.merge(4, "一班成绩单");
		// 一次性写出内容，使用默认样式
		writer.write(rows, true);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeMapOnlyAliasTest2() {
		final Map<Object, Object> row1 = new LinkedHashMap<>();
		row1.put("name", "张三");
		row1.put("age", 22);
		row1.put("isPass", true);
		row1.put("score", 66.30);
		row1.put("examDate", DateUtil.now());
		final Map<Object, Object> row2 = new LinkedHashMap<>();
		row2.put("name", "李四");
		row2.put("age", 233);
		row2.put("isPass", false);
		row2.put("score", 32.30);
		row2.put("examDate", DateUtil.now());

		final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
		// 通过工具类创建writer
		final String file = "d:/test/test_alias.xls";
		final ExcelWriter writer = ExcelUtil.getWriter(file, "test1");
		// 自定义标题
		final ExcelWriteConfig config = writer.getConfig();
//		writer.setOnlyAlias(true);
		config.addHeaderAlias("name", "姓名");
		config.addHeaderAlias("age", "年龄");
		// 一次性写出内容，使用默认样式
		writer.write(rows, true);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeMapOnlyAliasTest3() {
		final Map<Object, Object> row1 = new LinkedHashMap<>();
		row1.put("name", "张三");
		row1.put("age", 22);
		row1.put("isPass", true);
		row1.put("score", 66.30);
		row1.put("examDate", DateUtil.now());

		final Map<Object, Object> row2 = new LinkedHashMap<>();
		row2.put("name", "李四");
//		row2.put("age", 233);
		row2.put("isPass", false);
		row2.put("score", 32.30);
		row2.put("examDate", DateUtil.now());

		final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
		// 通过工具类创建writer
		final String file = "d:/test/test_alias.xls";
		final ExcelWriter writer = ExcelUtil.getWriter(file, "test1");
		final ExcelWriteConfig config = writer.getConfig();
		config.setOnlyAlias(true);

		// 自定义标题
		config.addHeaderAlias("name", "姓名");
		config.addHeaderAlias("age", "年龄");
		config.addHeaderAlias("examDate", "考试时间");

		// 一次性写出内容，使用默认样式
		writer.write(rows, true);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeBeanTest() {
		final TestBean bean1 = new TestBean();
		bean1.setName("张三");
		bean1.setAge(22);
		bean1.setPass(true);
		bean1.setScore(66.30);
		bean1.setExamDate(DateUtil.now());

		final TestBean bean2 = new TestBean();
		bean2.setName("李四");
		bean2.setAge(28);
		bean2.setPass(false);
		bean2.setScore(38.50);
		bean2.setExamDate(DateUtil.now());

		final List<TestBean> rows = ListUtil.of(bean1, bean2);
		// 通过工具类创建writer
		final String file = "e:/writeBeanTest.xlsx";
		FileUtil.del(FileUtil.file(file));
		final ExcelWriter writer = ExcelUtil.getWriter(file);
		final ExcelWriteConfig config = writer.getConfig();
		// 自定义标题
		config.addHeaderAlias("name", "姓名");
		config.addHeaderAlias("age", "年龄");
		config.addHeaderAlias("score", "分数");
		config.addHeaderAlias("isPass", "是否通过");
		config.addHeaderAlias("examDate", "考试时间");
		// 合并单元格后的标题行，使用默认标题样式
		writer.merge(4, "一班成绩单");
		// 一次性写出内容，使用默认样式
		writer.write(rows, true);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeBeanTest2() {
		final OrderExcel order1 = new OrderExcel();
		order1.setId("1");
		order1.setNum("123");
		order1.setBody("body1");

		final OrderExcel order2 = new OrderExcel();
		order1.setId("2");
		order1.setNum("456");
		order1.setBody("body2");

		final List<OrderExcel> rows = ListUtil.of(order1, order2);
		// 通过工具类创建writer
		final String file = "f:/test/writeBeanTest2.xlsx";
		FileUtil.del(FileUtil.file(file));
		final ExcelWriter writer = ExcelUtil.getWriter(file);
		// 自定义标题
		final ExcelWriteConfig config = writer.getConfig();
		config.addHeaderAlias("id", "编号");
		config.addHeaderAlias("num", "序号");
		config.addHeaderAlias("body", "内容");
		// 一次性写出内容，使用默认样式
		writer.write(rows, true);
		// 关闭writer，释放内存
		writer.close();
	}

	@Test
	@Disabled
	public void writeCellValueTest() {
		final ExcelWriter writer = new ExcelWriter("d:/cellValueTest.xls");
		writer.writeCellValue(3, 5, "aaa");
		writer.writeCellValue(3, 5, "aaa");
		writer.close();
	}

	@Test
	@Disabled
	public void addSelectTest() {
		final List<String> row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
		final ExcelWriter overtimeWriter = ExcelUtil.getWriter("d:/test/single_line.xlsx");
		overtimeWriter.writeCellValue(3, 4, "AAAA");
		overtimeWriter.addSelect(3, 4, row.toArray(new String[0]));
		overtimeWriter.close();
	}

	@Test
	@Disabled
	public void addSelectTest2() {
		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/select.xls");
		writer.writeCellValue(0, 0, "请选择科目");
		final int firstRow = 0;
		final int lastRow = 0;
		final int firstCol = 0;
		final int lastCol = 0;
		final CellRangeAddressList addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol);
		writer.addSelect(addressList, "1001", "1002", "1003");

		final List<?> rows = new ArrayList<>();
		writer.write(rows, true);

		writer.close();
	}

	@Test
	@Disabled
	public void writeMultiSheetTest() {
		final List<Map<String, Object>> rows = new LinkedList<>();
		for (int i = 0; i < 10; i++) {
			final Map<String, Object> tempList = new TreeMap<>();
			for (int j = 0; j < 10; j++) {
				tempList.put(String.valueOf(j), IdUtil.randomUUID());
			}
			rows.add(tempList);
		}
		final ExcelWriter writer = ExcelUtil.getWriter("D:\\test\\multiSheet.xlsx", "正常数据");
		final ExcelWriteConfig config = writer.getConfig();
		config.addHeaderAlias("1", "row1");
		config.addHeaderAlias("3", "row2");
		config.setOnlyAlias(true);

		writer.write(rows, true);
		writer.autoSizeColumnAll(false, 0);

		//表2
		writer.setSheet("当前重复数据");
		config.clearHeaderAlias();
		config.addHeaderAlias("3", "行3");
		config.addHeaderAlias("1", "行1");
		writer.write(rows, true);
		writer.autoSizeColumnAll(false, 0);

		//表3
		writer.setSheet("历史重复数据");
		writer.write(rows, true);
		writer.autoSizeColumnAll(false, 0);

		writer.close();
	}

	@Test
	@Disabled
	public void writeMultiSheetTest2() {
		final List<Map<String, Object>> rows = new LinkedList<>();
		final HashMap<String, Object> map = MapUtil.newHashMap();
		map.put("k1", "v1");
		map.put("k2", "v2");
		map.put("k3", "v3");
		rows.add(map);

		final ExcelWriter writer = ExcelUtil.getWriter("D:\\test\\multiSheet2.xlsx", "正常数据");
		writer.write(rows);

		//表2
		writer.setSheet("表2");
		final List<Map<String, Object>> rows2 = new LinkedList<>();
		final HashMap<String, Object> map2 = MapUtil.newHashMap();
		map2.put("x1", "v1");
		rows2.add(map2);
		writer.write(rows2);

		writer.close();
	}

	@Test
	@Disabled
	public void writeMultiSheetWithStyleTest() {
		final ExcelWriter writer = ExcelUtil.getWriter("D:\\test\\multiSheetWithStyle.xlsx", "表格1");

		// 表1
		final List<Map<String, Object>> rows = new LinkedList<>();
		final HashMap<String, Object> map = MapUtil.newHashMap();
		map.put("k1", "v1");
		map.put("k2", "v2");
		map.put("k3", "v3");
		rows.add(map);
		writer.write(rows);

		final Font headFont = writer.createFont();
		headFont.setBold(true);
		headFont.setFontHeightInPoints((short) 50);
		headFont.setFontName("Microsoft YaHei");
		((DefaultStyleSet)writer.getStyleSet()).getHeadCellStyle().setFont(headFont);

		//表2
		writer.setSheet("表2");
		final List<Map<String, Object>> rows2 = new LinkedList<>();
		final HashMap<String, Object> map2 = MapUtil.newHashMap();
		map2.put("x1", "v1");
		rows2.add(map2);
		writer.write(rows2);

		writer.close();
	}

	@Test
	@Disabled
	public void writeMapsTest() {
		final List<Map<String, Object>> rows = new ArrayList<>();

		final Map<String, Object> map1 = new HashMap<>();
		map1.put("a", 1);
		map1.put("b", 2);
		map1.put("c", 3);
		map1.put("d", 4);
		map1.put("e", 5);
		final Map<String, Object> map2 = new HashMap<>();
		map2.put("c", 3);
		map2.put("d", 4);
		map2.put("e", 5);
		final Map<String, Object> map3 = new HashMap<>();
		map3.put("d", 4);
		map3.put("e", 5);

		rows.add(map1);
		rows.add(map2);
		rows.add(map3);

		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/rows.xlsx");
		writer.write(rows);
		writer.close();
	}

	@Test
	@Disabled
	public void formatTest() {
		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/formatTest.xlsx");
		final CellStyle cellStyle = writer.createCellStyle(0, 0);
		cellStyle.setDataFormat(writer.getWorkbook().createDataFormat().getFormat("yyyy-mm-dd"));
		writer.close();
	}

	@Test
	@Disabled
	public void writeNumberFormatTest() {
		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/formatTest.xlsx");
		writer.disableDefaultStyle();
		writer.writeRow(ListUtil.of(51.33333333, 90.111111111));
		final CellStyle columnStyle = writer.createCellStyle(0, 0);
		columnStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("0.00"));
		writer.close();
	}

	/**
	 * issue#1659@Github
	 * 测试使用BigWriter写出，ExcelWriter修改失败
	 */
	@Test
	@Disabled
	public void editTest() {
		// 生成文件
		final File file = new File("d:/test/100_.xlsx");
		FileUtil.del(file);

		final BigExcelWriter writer = ExcelUtil.getBigWriter(file);
		writer.disableDefaultStyle();
		final List<List<String>> rows = Collections.singletonList(Arrays.asList("哈哈", "嘿嘿"));
		writer.write(rows);
		writer.close();

		// 修改文件
		final ExcelWriter writer2 = ExcelUtil.getWriter(file);
		writer2.disableDefaultStyle();
		writer2.writeCellValue(0, 0, "a");
		writer2.close();

		final ExcelReader reader = ExcelUtil.getReader(file);
		Console.log(reader.read());
	}

	@Test
	@Disabled
	public void mergeTest3() {
		// https://github.com/chinabugotech/hutool/issues/1696

		final List<Map<String, Object>> list = new ArrayList<>();
		final Map<String, Object> map = new HashMap<>();
		map.put("xmnf", "2021");
		list.add(map);

		final Map<String, Object> map1 = new HashMap<>();
		map1.put("xmnf", new XSSFRichTextString("9999"));
		list.add(map1);

		final Map<String, Object> map2 = new HashMap<>();
		map2.put("xmnf", "2019");
		list.add(map2);

		//通过工具类创建writer
		FileUtil.del(FileUtil.file("d:/test/writeTest2123.xlsx"));
		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/writeTest2123.xlsx");
		writer.getConfig().addHeaderAlias("xmnf", "项目年份");//1

		//合并单元格后的标题行，使用默认标题样式
		writer.merge(7, "测试标题");
		writer.merge(new CellRangeAddress(3, 4, 0, 0), new XSSFRichTextString("9999"), true);
		writer.write(list, true);
		writer.close();
	}

	@Test
	@Disabled
	public void mergeForDateTest() {
		// https://github.com/chinabugotech/hutool/issues/1911

		//通过工具类创建writer
		final String path = "d:/test/mergeForDate.xlsx";
		FileUtil.del(FileUtil.file(path));
		final ExcelWriter writer = ExcelUtil.getWriter(path);
		writer.merge(new CellRangeAddress(0, 3, 0, 2), DateUtil.now(), false);
		writer.close();
	}

	@Test
	@Disabled
	public void changeHeaderStyleTest() {
		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/headerStyle.xlsx");
		writer.writeHeaderRow(ListUtil.view("姓名", "性别", "年龄"));
		final CellStyle headCellStyle = ((DefaultStyleSet)writer.getStyleSet()).getHeadCellStyle();
		headCellStyle.setFillForegroundColor(IndexedColors.YELLOW1.index);
		headCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

		writer.close();
	}

	@Test
	@Disabled
	public void writeFloatTest() {
		//issue https://gitee.com/chinabugotech/hutool/issues/I43U9G
		final String path = "d:/test/floatTest.xlsx";
		FileUtil.del(FileUtil.file(path));

		final ExcelWriter writer = ExcelUtil.getWriter(path);
		writer.writeRow(ListUtil.view(22.9f));
		writer.close();
	}

	@Test
	@Disabled
	public void writeDoubleTest() {
		// https://gitee.com/chinabugotech/hutool/issues/I5PI5C
		final String path = "d:/test/doubleTest.xlsx";
		FileUtil.del(FileUtil.file(path));

		final ExcelWriter writer = ExcelUtil.getWriter(path);
		writer.disableDefaultStyle();
		writer.writeRow(ListUtil.view(0.427d));
		writer.close();
	}

	@Test
	@Disabled
	public void issueI466ZZTest() {
		// https://gitee.com/chinabugotech/hutool/issues/I466ZZ
		// 需要输出S_20000314_x5116_0004
		// 此处加入一个转义前缀：_x005F
		final List<Object> row = ListUtil.view(new EscapeStrCellSetter("S_20000314_x5116_0004"));

		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/_x.xlsx");
		writer.writeRow(row);
		writer.close();
	}

	@Test
	@Disabled
	public void writeLongTest() {
		//https://gitee.com/chinabugotech/hutool/issues/I49R6U
		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/long.xlsx");
		writer.write(ListUtil.view(1427545395336093698L));
		writer.close();
	}

	@Test
	@Disabled
	public void writeHyperlinkTest() {
		final ExcelWriter writer = ExcelUtil.getWriter("d:/test/hyperlink.xlsx");

		final Hyperlink hyperlink = writer.createHyperlink(HyperlinkType.URL, "https://hutool.cn");

		writer.write(ListUtil.view(hyperlink));
		writer.close();
	}

	@Test
	@Disabled
	public void mergeNumberTest() {
		final File tempFile = new File("d:/test/mergeNumber.xlsx");
		FileUtil.del(tempFile);

		final BigExcelWriter writer = new BigExcelWriter(tempFile);
		writer.merge(new CellRangeAddress(0, 1, 2, 2), 3.99, false);
		writer.close();
	}

	@Test
	@Disabled
	public void writeImgTest() {
		final ExcelWriter writer = ExcelUtil.getWriter(true);

		final File file = new File("C:\\Users\\zsz\\Desktop\\1.jpg");

		writer.writePic(file, 0, 0, 5, 10);

		writer.flush(new File("C:\\Users\\zsz\\Desktop\\2.xlsx"), true);

		writer.close();
	}

	@Test
	@Disabled
	public void autoSizeColumnTest() {

		final Map<String, Object> map = new LinkedHashMap<>(MAP_DATA_1);
		map.put("中文长度测试（符号）", "abc");

		final String file1 = "d:/test/autoSizeColumnTest.xlsx";
		final String file2 = "d:/test/autoSizeColumnTest2.xlsx";

		FileUtil.del(file1);
		FileUtil.del(file2);

		try (final ExcelWriter writer = new ExcelWriter(file1)) {
			writer.writeRow(map, true);
			writer.autoSizeColumnAll(false, 2f);
		}

		try (final BigExcelWriter writer = new BigExcelWriter(file2)) {
			writer.writeRow(map, true);
			writer.autoSizeColumnAll(false, 2f);
		}
	}
}
