mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
|
||||
package org.dromara.hutool.poi.excel;
|
||||
|
||||
import org.dromara.hutool.poi.excel.cell.CellLocation;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
import org.dromara.hutool.poi.excel.cell.CellReferenceUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -23,39 +24,39 @@ public class ExcelUtilTest {
|
||||
|
||||
@Test
|
||||
public void indexToColNameTest() {
|
||||
Assertions.assertEquals("A", ExcelUtil.indexToColName(0));
|
||||
Assertions.assertEquals("B", ExcelUtil.indexToColName(1));
|
||||
Assertions.assertEquals("C", ExcelUtil.indexToColName(2));
|
||||
Assertions.assertEquals("A", CellReferenceUtil.indexToColName(0));
|
||||
Assertions.assertEquals("B", CellReferenceUtil.indexToColName(1));
|
||||
Assertions.assertEquals("C", CellReferenceUtil.indexToColName(2));
|
||||
|
||||
Assertions.assertEquals("AA", ExcelUtil.indexToColName(26));
|
||||
Assertions.assertEquals("AB", ExcelUtil.indexToColName(27));
|
||||
Assertions.assertEquals("AC", ExcelUtil.indexToColName(28));
|
||||
Assertions.assertEquals("AA", CellReferenceUtil.indexToColName(26));
|
||||
Assertions.assertEquals("AB", CellReferenceUtil.indexToColName(27));
|
||||
Assertions.assertEquals("AC", CellReferenceUtil.indexToColName(28));
|
||||
|
||||
Assertions.assertEquals("AAA", ExcelUtil.indexToColName(702));
|
||||
Assertions.assertEquals("AAB", ExcelUtil.indexToColName(703));
|
||||
Assertions.assertEquals("AAC", ExcelUtil.indexToColName(704));
|
||||
Assertions.assertEquals("AAA", CellReferenceUtil.indexToColName(702));
|
||||
Assertions.assertEquals("AAB", CellReferenceUtil.indexToColName(703));
|
||||
Assertions.assertEquals("AAC", CellReferenceUtil.indexToColName(704));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void colNameToIndexTest() {
|
||||
Assertions.assertEquals(704, ExcelUtil.colNameToIndex("AAC"));
|
||||
Assertions.assertEquals(703, ExcelUtil.colNameToIndex("AAB"));
|
||||
Assertions.assertEquals(702, ExcelUtil.colNameToIndex("AAA"));
|
||||
Assertions.assertEquals(704, CellReferenceUtil.colNameToIndex("AAC"));
|
||||
Assertions.assertEquals(703, CellReferenceUtil.colNameToIndex("AAB"));
|
||||
Assertions.assertEquals(702, CellReferenceUtil.colNameToIndex("AAA"));
|
||||
|
||||
Assertions.assertEquals(28, ExcelUtil.colNameToIndex("AC"));
|
||||
Assertions.assertEquals(27, ExcelUtil.colNameToIndex("AB"));
|
||||
Assertions.assertEquals(26, ExcelUtil.colNameToIndex("AA"));
|
||||
Assertions.assertEquals(28, CellReferenceUtil.colNameToIndex("AC"));
|
||||
Assertions.assertEquals(27, CellReferenceUtil.colNameToIndex("AB"));
|
||||
Assertions.assertEquals(26, CellReferenceUtil.colNameToIndex("AA"));
|
||||
|
||||
Assertions.assertEquals(2, ExcelUtil.colNameToIndex("C"));
|
||||
Assertions.assertEquals(1, ExcelUtil.colNameToIndex("B"));
|
||||
Assertions.assertEquals(0, ExcelUtil.colNameToIndex("A"));
|
||||
Assertions.assertEquals(2, CellReferenceUtil.colNameToIndex("C"));
|
||||
Assertions.assertEquals(1, CellReferenceUtil.colNameToIndex("B"));
|
||||
Assertions.assertEquals(0, CellReferenceUtil.colNameToIndex("A"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toLocationTest() {
|
||||
final CellLocation a11 = ExcelUtil.toLocation("A11");
|
||||
Assertions.assertEquals(0, a11.getX());
|
||||
Assertions.assertEquals(10, a11.getY());
|
||||
public void cellReferenceTest() {
|
||||
final CellReference a11 = new CellReference("A11");
|
||||
Assertions.assertEquals(0, a11.getCol());
|
||||
Assertions.assertEquals(10, a11.getRow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -12,6 +12,11 @@
|
||||
|
||||
package org.dromara.hutool.poi.excel.writer;
|
||||
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.date.DateUtil;
|
||||
import org.dromara.hutool.core.io.file.FileUtil;
|
||||
@@ -22,10 +27,6 @@ import org.dromara.hutool.poi.excel.ExcelUtil;
|
||||
import org.dromara.hutool.poi.excel.ExcelWriter;
|
||||
import org.dromara.hutool.poi.excel.TestBean;
|
||||
import org.dromara.hutool.poi.excel.style.StyleUtil;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -102,7 +103,7 @@ public class BigExcelWriteTest {
|
||||
writer.write(rows);
|
||||
|
||||
// 合并单元格后的标题行,使用默认标题样式
|
||||
writer.merge(7, 10, 4, 10, "测试Merge", false);
|
||||
writer.merge(new CellRangeAddress(7, 10, 4, 10), "测试Merge", false);
|
||||
|
||||
// 关闭writer,释放内存
|
||||
writer.close();
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
package org.dromara.hutool.poi.excel.writer;
|
||||
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.date.DateUtil;
|
||||
import org.dromara.hutool.core.io.file.FileUtil;
|
||||
@@ -187,7 +188,7 @@ public class ExcelWriteTest {
|
||||
writer.write(rows);
|
||||
|
||||
// 合并单元格后的标题行,使用默认标题样式
|
||||
writer.merge(7, 10, 4, 10, "测试Merge", false);
|
||||
writer.merge(new CellRangeAddress(7, 10, 4, 10), "测试Merge", false);
|
||||
|
||||
// 关闭writer,释放内存
|
||||
writer.close();
|
||||
@@ -705,14 +706,14 @@ public class ExcelWriteTest {
|
||||
cellStyle.setFont(font);
|
||||
|
||||
// 合并单元格后的标题行,使用设置好的样式
|
||||
writer.merge(0, 1, 0, row1.size() - 1, "标题XXXXXXXX", cellStyle);
|
||||
writer.merge(new CellRangeAddress(0, 1, 0, row1.size() - 1), "标题XXXXXXXX", cellStyle);
|
||||
Console.log(writer.getCurrentRow());
|
||||
|
||||
//设置复杂表头
|
||||
writer.merge(2, 3, 0, 0, "序号", true);
|
||||
writer.merge(2, 2, 1, 2, "AABB", true);
|
||||
writer.merge(2, 3, 3, 3, "CCCC", true);
|
||||
writer.merge(2, 2, 4, 5, "DDEE", true);
|
||||
writer.merge(new CellRangeAddress(2, 3, 0, 0), "序号", true);
|
||||
writer.merge(new CellRangeAddress(2, 2, 1, 2), "AABB", true);
|
||||
writer.merge(new CellRangeAddress(2, 3, 3, 3), "CCCC", true);
|
||||
writer.merge(new CellRangeAddress(2, 2, 4, 5), "DDEE", true);
|
||||
writer.setCurrentRow(3);
|
||||
|
||||
final List<String> sechead = ListUtil.of("AA", "BB", "DD", "EE");
|
||||
@@ -775,7 +776,7 @@ public class ExcelWriteTest {
|
||||
|
||||
//合并单元格后的标题行,使用默认标题样式
|
||||
writer.merge(7, "测试标题");
|
||||
writer.merge(3, 4, 0, 0, new XSSFRichTextString("9999"), true);
|
||||
writer.merge(new CellRangeAddress(3, 4, 0, 0), new XSSFRichTextString("9999"), true);
|
||||
writer.write(list, true);
|
||||
writer.close();
|
||||
}
|
||||
@@ -789,7 +790,7 @@ public class ExcelWriteTest {
|
||||
final String path = "d:/test/mergeForDate.xlsx";
|
||||
FileUtil.del(FileUtil.file(path));
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(path);
|
||||
writer.merge(0, 3, 0, 2, DateUtil.now(), false);
|
||||
writer.merge(new CellRangeAddress(0, 3, 0, 2), DateUtil.now(), false);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@@ -870,7 +871,7 @@ public class ExcelWriteTest {
|
||||
FileUtil.del(tempFile);
|
||||
|
||||
final BigExcelWriter writer = new BigExcelWriter(tempFile);
|
||||
writer.merge(0, 1, 2, 2, 3.99, false);
|
||||
writer.merge(new CellRangeAddress(0, 1, 2, 2), 3.99, false);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
package org.dromara.hutool.poi.excel.writer;
|
||||
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.dromara.hutool.poi.excel.ExcelUtil;
|
||||
@@ -84,9 +85,9 @@ public class Issue2221Test {
|
||||
writer.setOnlyAlias(true);
|
||||
|
||||
// 设置合并的单元格
|
||||
writer.merge(0, 1, 0, 0, "日期", true);
|
||||
writer.merge(0, 0, 1, 2, "运行次数", true);
|
||||
writer.merge(0, 0, 3, 4, "新增人数", true);
|
||||
writer.merge(new CellRangeAddress(0, 1, 0, 0), "日期", true);
|
||||
writer.merge(new CellRangeAddress(0, 0, 1, 2), "运行次数", true);
|
||||
writer.merge(new CellRangeAddress(0, 0, 3, 4), "新增人数", true);
|
||||
|
||||
// 写入数据
|
||||
final List<Map<Object, Object>> data = ListUtil.view(
|
||||
|
Reference in New Issue
Block a user