This commit is contained in:
Looly 2021-07-10 01:14:41 +08:00
parent b8d04654ef
commit 0e15b89cfa
2 changed files with 34 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Console;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.IdUtil;
@ -33,12 +34,12 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@ -763,6 +764,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
if (null != content) {
final Cell cell = getOrCreateCell(firstColumn, firstRow);
CellUtil.setCellValue(cell, content, cellStyle);
Console.log("{} {} {}", firstColumn, firstRow, cell.getStringCellValue());
}
return this;
}

View File

@ -18,6 +18,7 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.junit.Ignore;
import org.junit.Test;
@ -678,4 +679,34 @@ public class ExcelWriteTest {
final ExcelReader reader = ExcelUtil.getReader(file);
Console.log(reader.read());
}
@Test
@Ignore
public void mergeTest3(){
// https://github.com/dromara/hutool/issues/1696
List<Map<String,Object>> list = new ArrayList<>();
Map<String,Object> map = new HashMap<>();
map.put("xmnf","2021");
list.add(map);
Map<String,Object> map1 = new HashMap<>();
map1.put("xmnf",new XSSFRichTextString("9999"));
list.add(map1);
Map<String,Object> map2 = new HashMap<>();
map2.put("xmnf","2019");
list.add(map2);
//通过工具类创建writer
FileUtil.del("d:/test/writeTest2123.xlsx");
ExcelWriter writer = ExcelUtil.getWriter("d:/test/writeTest2123.xlsx");
writer.addHeaderAlias("xmnf", "项目年份");//1
//合并单元格后的标题行使用默认标题样式
writer.merge(7, "测试标题");
writer.merge(3, 4, 0, 0, new XSSFRichTextString("9999"), true);
writer.write(list, true);
writer.close();
}
}