4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package com.excel.poi.common;
18 |
19 | /**
20 | * @author NingWei
21 | */
22 | public final class Constant {
23 | /**
24 | * Excel自动刷新到磁盘的数量
25 | */
26 | public static final int DEFAULT_ROW_ACCESS_WINDOW_SIZE = 2000;
27 | /**
28 | * 分页条数
29 | */
30 | public static final int DEFAULT_PAGE_SIZE = 3000;
31 | /**
32 | * 分Sheet条数
33 | */
34 | public static final int DEFAULT_RECORD_COUNT_PEER_SHEET = 80000;
35 | /**
36 | * 是否开启自动适配宽度
37 | */
38 | public static final boolean OPEN_AUTO_COLUM_WIDTH = true;
39 |
40 | public static final String CELL = "c";
41 | public static final String XYZ_LOCATION = "r";
42 | public static final String CELL_T_PROPERTY = "t";
43 | public static final String CELL_S_VALUE = "s";
44 | public static final String ROW = "row";
45 |
46 | public static final int CHINESES_ATUO_SIZE_COLUMN_WIDTH_MAX = 60;
47 | public static final int CHINESES_ATUO_SIZE_COLUMN_WIDTH_MIN = 15;
48 |
49 | public static final int MAX_RECORD_COUNT_PEER_SHEET = 1000000;
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/excel/poi/annotation/ExportField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 NingWei (ningww1@126.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package com.excel.poi.factory;
18 |
19 | import com.excel.poi.annotation.ExportField;
20 | import com.excel.poi.annotation.ImportField;
21 | import com.excel.poi.entity.ExcelEntity;
22 | import com.excel.poi.entity.ExcelPropertyEntity;
23 | import com.excel.poi.exception.ExcelBootException;
24 | import java.lang.reflect.Field;
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | /**
29 | * @author NingWei
30 | */
31 | public class ExcelMappingFactory {
32 |
33 | /**
34 | * 根据指定Excel实体获取导入Excel文件相关信息
35 | *
36 | * @param clazz
37 | * @return
38 | * @throws IllegalAccessException
39 | * @throws InstantiationException
40 | */
41 | public static ExcelEntity loadImportExcelClass(Class clazz) {
42 | List propertyList = new ArrayList();
43 |
44 | Field[] fields = clazz.getDeclaredFields();
45 | for (Field field : fields) {
46 | ImportField importField = field.getAnnotation(ImportField.class);
47 | if (null != importField) {
48 | field.setAccessible(true);
49 | ExcelPropertyEntity excelPropertyEntity = ExcelPropertyEntity.builder()
50 | .fieldEntity(field)
51 | .required(importField.required())
52 | .dateFormat(importField.dateFormat().trim())
53 | .regex(importField.regex().trim())
54 | .regexMessage(importField.regexMessage().trim())
55 | .scale(importField.scale())
56 | .roundingMode(importField.roundingMode())
57 | .build();
58 | propertyList.add(excelPropertyEntity);
59 | }
60 | }
61 | if (propertyList.isEmpty()) {
62 | throw new ExcelBootException("[{}] 类未找到标注@ImportField注解的属性!", clazz.getName());
63 | }
64 | ExcelEntity excelMapping = new ExcelEntity();
65 | excelMapping.setPropertyList(propertyList);
66 | return excelMapping;
67 |
68 | }
69 |
70 | /**
71 | * 根据指定Excel实体获取导出Excel文件相关信息
72 | *
73 | * @param clazz
74 | * @return
75 | * @throws IllegalAccessException
76 | * @throws InstantiationException
77 | */
78 | public static ExcelEntity loadExportExcelClass(Class> clazz, String fileName) {
79 | List propertyList = new ArrayList();
80 |
81 | Field[] fields = clazz.getDeclaredFields();
82 | for (Field field : fields) {
83 | ExportField exportField = field.getAnnotation(ExportField.class);
84 | if (null != exportField) {
85 | field.setAccessible(true);
86 | ExcelPropertyEntity excelPropertyEntity = ExcelPropertyEntity.builder()
87 | .fieldEntity(field)
88 | .columnName(exportField.columnName().trim())
89 | .scale(exportField.scale())
90 | .roundingMode(exportField.roundingMode())
91 | .dateFormat(exportField.dateFormat().trim())
92 | .templateCellValue(exportField.defaultCellValue().trim())
93 | .build();
94 | propertyList.add(excelPropertyEntity);
95 | }
96 | }
97 | if (propertyList.isEmpty()) {
98 | throw new ExcelBootException("[{}]类未找到标注@ExportField注解的属性!", clazz.getName());
99 | }
100 | ExcelEntity excelMapping = new ExcelEntity();
101 | excelMapping.setPropertyList(propertyList);
102 | excelMapping.setFileName(fileName);
103 | return excelMapping;
104 | }
105 |
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Artistic License 2.0
2 | Copyright (c)
3 |
4 | Everyone is permitted to copy and distribute verbatim copies of this license
5 | document, but changing it is not allowed.
6 |
7 | Preamble
8 | This license establishes the terms under which a given free software Package may
9 | be copied, modified, distributed, and/or redistributed. The intent is that the
10 | Copyright Holder maintains some artistic control over the development of that
11 | Package while still keeping the Package available as open source and free
12 | software.
13 |
14 | You are always permitted to make arrangements wholly outside of this license
15 | directly with the Copyright Holder of a given Package. If the terms of this
16 | license do not permit the full use that you propose to make of the Package, you
17 | should contact the Copyright Holder and seek a different licensing arrangement.
18 |
19 | Definitions
20 | "Copyright Holder" means the individual(s) or organization(s) named in the
21 | copyright notice for the entire Package.
22 |
23 | "Contributor" means any party that has contributed code or other material to the
24 | Package, in accordance with the Copyright Holder's procedures.
25 |
26 | "You" and "your" means any person who would like to copy, distribute, or modify
27 | the Package.
28 |
29 | "Package" means the collection of files distributed by the Copyright Holder, and
30 | derivatives of that collection and/or of those files. A given Package may
31 | consist of either the Standard Version, or a Modified Version.
32 |
33 | "Distribute" means providing a copy of the Package or making it accessible to
34 | anyone else, or in the case of a company or organization, to others outside of
35 | your company or organization.
36 |
37 | "Distributor Fee" means any fee that you charge for Distributing this Package or
38 | providing support for this Package to another party. It does not mean licensing
39 | fees.
40 |
41 | "Standard Version" refers to the Package if it has not been modified, or has
42 | been modified only in ways explicitly requested by the Copyright Holder.
43 |
44 | "Modified Version" means the Package, if it has been changed, and such changes
45 | were not explicitly requested by the Copyright Holder.
46 |
47 | "Original License" means this Artistic License as Distributed with the Standard
48 | Version of the Package, in its current version or as it may be modified by The
49 | Perl Foundation in the future.
50 |
51 | "Source" form means the source code, documentation source, and configuration
52 | files for the Package.
53 |
54 | "Compiled" form means the compiled bytecode, object code, binary, or any other
55 | form resulting from mechanical transformation or translation of the Source form.
56 |
57 | Permission for Use and Modification Without Distribution
58 | (1) You are permitted to use the Standard Version and create and use Modified
59 | Versions for any purpose without restriction, provided that you do not
60 | Distribute the Modified Version.
61 |
62 | Permissions for Redistribution of the Standard Version
63 | (2) You may Distribute verbatim copies of the Source form of the Standard
64 | Version of this Package in any medium without restriction, either gratis or for
65 | a Distributor Fee, provided that you duplicate all of the original copyright
66 | notices and associated disclaimers. At your discretion, such verbatim copies may
67 | or may not include a Compiled form of the Package.
68 |
69 | (3) You may apply any bug fixes, portability changes, and other modifications
70 | made available from the Copyright Holder. The resulting Package will still be
71 | considered the Standard Version, and as such will be subject to the Original
72 | License.
73 |
74 | Distribution of Modified Versions of the Package as Source
75 | (4) You may Distribute your Modified Version as Source (either gratis or for a
76 | Distributor Fee, and with or without a Compiled form of the Modified Version)
77 | provided that you clearly document how it differs from the Standard Version,
78 | including, but not limited to, documenting any non-standard features,
79 | executables, or modules, and provided that you do at least ONE of the following:
80 |
81 | (a) make the Modified Version available to the Copyright Holder of the Standard
82 | Version, under the Original License, so that the Copyright Holder may include
83 | your modifications in the Standard Version.
84 | (b) ensure that installation of your Modified Version does not prevent the user
85 | installing or running the Standard Version. In addition, the Modified Version
86 | must bear a name that is different from the name of the Standard Version.
87 | (c) allow anyone who receives a copy of the Modified Version to make the Source
88 | form of the Modified Version available to others under
89 | (i) the Original License or
90 | (ii) a license that permits the licensee to freely copy, modify and redistribute
91 | the Modified Version using the same licensing terms that apply to the copy that
92 | the licensee received, and requires that the Source form of the Modified
93 | Version, and of any works derived from it, be made freely available in that
94 | license fees are prohibited but Distributor Fees are allowed.
95 |
96 | Distribution of Compiled Forms of the Standard Version or Modified Versions
97 | without the Source
98 | (5) You may Distribute Compiled forms of the Standard Version without the
99 | Source, provided that you include complete instructions on how to get the Source
100 | of the Standard Version. Such instructions must be valid at the time of your
101 | distribution. If these instructions, at any time while you are carrying out such
102 | distribution, become invalid, you must provide new instructions on demand or
103 | cease further distribution. If you provide valid instructions or cease
104 | distribution within thirty days after you become aware that the instructions are
105 | invalid, then you do not forfeit any of your rights under this license.
106 |
107 | (6) You may Distribute a Modified Version in Compiled form without the Source,
108 | provided that you comply with Section 4 with respect to the Source of the
109 | Modified Version.
110 |
111 | Aggregating or Linking the Package
112 | (7) You may aggregate the Package (either the Standard Version or Modified
113 | Version) with other packages and Distribute the resulting aggregation provided
114 | that you do not charge a licensing fee for the Package. Distributor Fees are
115 | permitted, and licensing fees for other components in the aggregation are
116 | permitted. The terms of this license apply to the use and Distribution of the
117 | Standard or Modified Versions as included in the aggregation.
118 |
119 | (8) You are permitted to link Modified and Standard Versions with other works,
120 | to embed the Package in a larger work of your own, or to build stand-alone
121 | binary or bytecode versions of applications that include the Package, and
122 | Distribute the result without restriction, provided the result does not expose a
123 | direct interface to the Package.
124 |
125 | Items That are Not Considered Part of a Modified Version
126 |
127 | (9) Works (including, but not limited to, modules and scripts) that merely
128 | extend or make use of the Package, do not, by themselves, cause the Package to
129 | be a Modified Version. In addition, such works are not considered parts of the
130 | Package itself, and are not subject to the terms of this license.
131 |
132 | General Provisions
133 |
134 | (10) Any use, modification, and distribution of the Standard or Modified
135 | Versions is governed by this Artistic License. By using, modifying or
136 | distributing the Package, you accept this license. Do not use, modify, or
137 | distribute the Package, if you do not accept this license.
138 |
139 | (11) If your Modified Version has been derived from a Modified Version made by
140 | someone other than you, you are nevertheless required to ensure that your
141 | Modified Version complies with the requirements of this license.
142 |
143 | (12) This license does not grant you the right to use any trademark, service
144 | mark, tradename, or logo of the Copyright Holder.
145 |
146 | (13) This license includes the non-exclusive, worldwide, free-of-charge patent
147 | license to make, have made, use, offer to sell, sell, import and otherwise
148 | transfer the Package with respect to any patent claims licensable by the
149 | Copyright Holder that are necessarily infringed by the Package. If you institute
150 | patent litigation (including a cross-claim or counterclaim) against any party
151 | alleging that the Package constitutes direct or contributory patent
152 | infringement, then this Artistic License to you shall terminate on the date that
153 | such litigation is filed.
154 |
155 | (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
156 | CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
157 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
158 | NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
159 | UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR
160 | ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY
161 | OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
162 | DAMAGE.
--------------------------------------------------------------------------------
/src/main/java/com/excel/poi/excel/ExcelWriter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 NingWei (ningww1@126.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *