Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LongestMatchColumnWidthStyleStrategy 单元格长度错误 #734

Closed
WangChaolin opened this issue Oct 23, 2019 · 1 comment
Closed

LongestMatchColumnWidthStyleStrategy 单元格长度错误 #734

WangChaolin opened this issue Oct 23, 2019 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@WangChaolin
Copy link

触发场景描述
单元格内容长度大于256时触发
触发Bug的代码

  private List<LongestMatchColumnWidthData> dataLong() {
        List<LongestMatchColumnWidthData> list = new ArrayList<LongestMatchColumnWidthData>();
        for (int i = 0; i < 10; i++) {
            LongestMatchColumnWidthData data = new LongestMatchColumnWidthData();
            data.setString("测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串测试很长的字符串" + i);
            data.setDate(new Date());
            data.setDoubleData(1000000000000.0);
            list.add(data);
        }
        return list;
    }

public void longestMatchColumnWidthWrite() {
        String fileName =
            TestFileUtil.getPath() + "longestMatchColumnWidthWrite" + System.currentTimeMillis() + ".xlsx";
        // 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
        EasyExcel.write(fileName, LongestMatchColumnWidthData.class)
            .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("模板").doWrite(dataLong());
    }

提示的异常或者没有达到的效果

java.lang.IllegalArgumentException: The maximum column width for an individual cell is 255 characters.

at org.apache.poi.xssf.usermodel.XSSFSheet.setColumnWidth(XSSFSheet.java:2527)
at org.apache.poi.xssf.streaming.SXSSFSheet.setColumnWidth(SXSSFSheet.java:268)
at com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy.setColumnWidth(LongestMatchColumnWidthStyleStrategy.java:47)
at com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy.afterCellCreate(AbstractColumnWidthStyleStrategy.java:34)
at com.alibaba.excel.write.ExcelBuilderImpl.afterCellCreate(ExcelBuilderImpl.java:287)
at com.alibaba.excel.write.ExcelBuilderImpl.addJavaObjectToExcel(ExcelBuilderImpl.java:222)
at com.alibaba.excel.write.ExcelBuilderImpl.addOneRowOfDataToExcel(ExcelBuilderImpl.java:128)
at com.alibaba.excel.write.ExcelBuilderImpl.doAddContent(ExcelBuilderImpl.java:79)
at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:93)
at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:155)
at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:140)
at com.alibaba.excel.write.builder.ExcelWriterSheetBuilder.doWrite(ExcelWriterSheetBuilder.java:134)
at com.alibaba.easyexcel.test.demo.write.WriteTest.longestMatchColumnWidthWrite(WriteTest.java:360)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
@WangChaolin WangChaolin added the bug Something isn't working label Oct 23, 2019
@zhuangjiaju
Copy link
Collaborator

非常感谢您的意见,该问题已经在2.1.0-beta3修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants