Skip to content
清沐 edited this page Mar 21, 2020 · 4 revisions

1.Does the toolkit support JDK6 and JDK7?

All versions of myexcel only support jdk8+.

2.How to support Chinese for response stream output file name?

Version 1.4.1 and later, please use AttachmentExportUtil \ FileExportUtil tool class to export, do not care about the suffix and Chinese issues; For other versions, please set the response stream as follows:

response.setCharacterEncoding(CharEncoding.UTF_8);
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, CharEncoding.UTF_8));

3.Do not specify workbook format, what is the default format?

If the workbooktype is not specified, the default format of the file is. Xlsx, which is also recommended.

4.Where can template files be stored?

Currently, the template engines supported by default include FreeMarker, Beetl, groovy and thymeleaf template engine. When excel is created by the above default excelbuilder, template files can only be placed under classpath, such as resources.

6.How to set excel sheet name in HTML

Set Excel sheet name:Add <caption>sheet名称</caption> to Table

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<table>
		<caption>sheet名称</caption>
		<thead>
			<tr>
				<th></th>
				<th></th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td></td>
				<td></td>
			</tr>
		</tbody>
	</table>
</body>
</html>

7.Excel sheet maximum number of rows / columns supported

Excel version Maximum number of rows columns supported
Excel 2013 1,048,576 16,384
Excel 2010 1,048,576 16,384
Excel 2007 1,048,576 16,384
Excel 97-2003 65,536 256

8.Whether there will be security problems in the case of high concurrency?

The following errors may occur during the concurrent generation of Excel in the lower version of poi:

Caused by: java.io.IOException: Could not create temporary directory '/home/admin/dio2o/.default/temp/poifiles'
        at org.apache.poi.util.DefaultTempFileCreationStrategy.createTempDirectory(DefaultTempFileCreationStrategy.java:93) ~[poi-3.15.jar:3.15]
        at org.apache.poi.util.DefaultTempFileCreationStrategy.createPOIFilesDirectory(DefaultTempFileCreationStrategy.java:82) ~[poi-3.15.jar:3.15]

The corresponding source code is as follows:

 private void createTempDirectory(File directory) throws IOException {
        if (!(directory.exists() || directory.mkdirs()) || !directory.isDirectory()) {
            throw new IOException("Could not create temporary directory '" + directory + "'");
        }
    }

The POI version adopted by myexcel has fixed this problem. Please feel free to use it. The modified source code is as follows:

private synchronized void createTempDirectory(File directory) throws IOException {
     boolean dirExists = directory.exists() || directory.mkdirs();
     if (!dirExists) {
         throw new IOException("Could not create temporary directory '" + directory + "'");
     } else if (!directory.isDirectory()) {
         throw new IOException("Could not create temporary directory. '" + directory + "' exists but is not a directory.");
     }
}

9.Solution to invalid custom color of .XLS file

For. XLS files, POI predefined 56 colors. If you want to customize colors, you need to cover 56 colors. Currently, the solution is not determined. Therefore, it is recommended that you use. Xlsx for customized colors. If you can only use. XLS files, you can only use 56 predefined colors. For color list, please refer to: color index

Usage mode: Take HSSFColor. Olive green as an example. When setting a style, set it to style = "background color: olivegreen".

10.DefaultExcelReader / SaxexcelReader class readthen interface prompt error solution

Using the readthen interface in some scenarios will result in the following error prompt:

Error:(210, 62) java: ambiguous reference to readthen
com.github.liaochong.myexcel.core.DefaultExcelReader->
readThen(java.io.InputStream,java.util.function.Consumer<T>) with com.github.liaochong.myexcel.core.DefaultExcelReader-> readThen(java.io.InputStream,java.util.function.Function<T,java.lang.Boolean>) all match

To solve this problem, add braces in the method body "{",as follows:

readThen(file,data->{System.out.println(data.name);})

11.Postman test download

Postman test download, you need to select 'send and download'. Otherwise, the following exceptions may occur:

java.lang.RuntimeException: java.io.IOException: This archive contains unclosed entries. 

12.excel on the loss of accuracy of imported values

When using saxexcelreader to read excel, the original value of 9.5 may appear, and the imported value will become 9.50000000007. The problem is that the actual storage of Excel is 9.50000000007. For non program reasons, to solve the problem, you can use the text function, change the value to text, and remember that you can't simply set the cell to text. This method can't change the cell in practice format.

13.FreeMarker large value output error

When using FreemarkerExcelBuilder to export excel, if there is a large value output greater than 1000, there may be the following errors:

Actual value: 1018,280029687 Result after rendering: 1 01828

You can use ${x?c} to solve this problem.

Clone this wiki locally