Merge pull request #3050 from GengMS/v5-dev

Issue#3048: 添加 数字单元格精度据单元格实际数值自动适配新特性;
This commit is contained in:
Golden Looly
2023-04-11 23:37:08 +08:00
committed by GitHub
3 changed files with 70 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
package cn.hutool.poi.excel;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.Ignore;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
* https://github.com/dromara/hutool/issues/3048 Excel导出javaBean中有BigDecimal类型精度流失
*
*/
public class Issue3048Test {
@Test
@Ignore
public void excelOutPutBeanListToExcel(){
List<TestBean> excelExportList = new ArrayList<>();
excelExportList.add(new TestBean("1", new BigDecimal("1.22")));
excelExportList.add(new TestBean("2", new BigDecimal("2.342")));
excelExportList.add(new TestBean("3", new BigDecimal("1.2346")));
ExcelWriter excelWriter = ExcelUtil.getWriter(true);
excelWriter.setNumberAutoPrecision(true);
excelWriter.write(excelExportList, true);
excelWriter.flush(new File("e:/test.xlsx"));
excelWriter.close();
}
@Data
@AllArgsConstructor
static class TestBean{
private String testKey;
private BigDecimal testValue;
}
}