This commit is contained in:
Looly 2024-05-08 17:17:28 +08:00
parent bee80f3d14
commit 829fecdc38

View File

@ -1,11 +1,7 @@
package cn.hutool.poi.excel;
import cn.hutool.core.collection.ListUtil;
import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IgnoredErrorType;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import cn.hutool.poi.excel.cell.FormulaCellValue;
import org.junit.Ignore;
import org.junit.Test;
@ -13,15 +9,11 @@ public class WriteNumberToStringTest {
@Test
@Ignore
public void writeNumberTest() {
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/dataWithNumber.xlsx");
final XSSFSheet sheet = (XSSFSheet) writer.getSheet();
sheet.addIgnoredErrors(new CellRangeAddress(0, 100, 0, 100), IgnoredErrorType.NUMBER_STORED_AS_TEXT);
final CellStyle cellStyle = writer.getStyleSet().getCellStyle();
cellStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("TEXT"));
final ExcelWriter writer = ExcelUtil.getBigWriter("d:/test/dataWithNumber.xlsx");
writer.writeRow(ListUtil.of("姓名", "编号"));
writer.writeRow(ListUtil.of("张三", "010001"));
writer.writeRow(ListUtil.of("李四", "120001"));
writer.writeRow(ListUtil.of("张三", new FormulaCellValue("010001")));
writer.writeRow(ListUtil.of("李四", new FormulaCellValue("120001")));
writer.writeRow(ListUtil.of("王五", 123456));
writer.close();