├── .gitignore ├── CHANGELOG ├── LICENSE ├── README.md ├── images ├── auto-width.png ├── dynamic_style.png ├── multi-headers.png ├── preset_effect.jpg ├── report1.png ├── report3.png ├── simple_sheet.png └── write_read_100w.jpg ├── pom.xml ├── ref └── ColorIndex.html └── src ├── main ├── java │ └── org │ │ └── ttzero │ │ └── excel │ │ ├── annotation │ │ ├── ExcelColumn.java │ │ ├── ExcelColumns.java │ │ ├── FreezePanes.java │ │ ├── HeaderComment.java │ │ ├── HeaderStyle.java │ │ ├── Hyperlink.java │ │ ├── IgnoreExport.java │ │ ├── IgnoreImport.java │ │ ├── MediaColumn.java │ │ ├── RowNum.java │ │ └── StyleDesign.java │ │ ├── drawing │ │ ├── Bevel.java │ │ ├── Camera.java │ │ ├── Effect.java │ │ ├── EffectProducer.java │ │ ├── Enums.java │ │ ├── Fill.java │ │ ├── Glow.java │ │ ├── LightRig.java │ │ ├── Outline.java │ │ ├── PresetPictureEffect.java │ │ ├── Reflection.java │ │ ├── Scene3D.java │ │ ├── Shadow.java │ │ └── Shape3D.java │ │ ├── entity │ │ ├── CSVSheet.java │ │ ├── CollectionSheet.java │ │ ├── Column.java │ │ ├── Comment.java │ │ ├── Comments.java │ │ ├── EmptySheet.java │ │ ├── ExcelWriteException.java │ │ ├── ICellValueAndStyle.java │ │ ├── IDrawingsWriter.java │ │ ├── IWorkbookWriter.java │ │ ├── IWorksheetWriter.java │ │ ├── ListMapSheet.java │ │ ├── ListSheet.java │ │ ├── Panes.java │ │ ├── Picture.java │ │ ├── Relationship.java │ │ ├── ResultSetSheet.java │ │ ├── Row.java │ │ ├── RowBlock.java │ │ ├── SharedStringTable.java │ │ ├── SharedStrings.java │ │ ├── Sheet.java │ │ ├── SimpleSheet.java │ │ ├── StatementSheet.java │ │ ├── Storable.java │ │ ├── TemplateSheet.java │ │ ├── TooManyColumnsException.java │ │ ├── WaterMark.java │ │ ├── Workbook.java │ │ ├── csv │ │ │ ├── CSVCellValueAndStyle.java │ │ │ ├── CSVWorkbookWriter.java │ │ │ └── CSVWorksheetWriter.java │ │ ├── e7 │ │ │ ├── ContentType.java │ │ │ ├── XMLCellValueAndStyle.java │ │ │ ├── XMLDrawingsWriter.java │ │ │ ├── XMLWorkbookWriter.java │ │ │ ├── XMLWorksheetWriter.java │ │ │ └── XMLZebraLineCellValueAndStyle.java │ │ └── style │ │ │ ├── Border.java │ │ │ ├── BorderStyle.java │ │ │ ├── BuildInColor.java │ │ │ ├── BuiltInNumFmt.java │ │ │ ├── Charset.java │ │ │ ├── ColorIndex.java │ │ │ ├── Fill.java │ │ │ ├── Font.java │ │ │ ├── HlsColor.java │ │ │ ├── Horizontals.java │ │ │ ├── NumFmt.java │ │ │ ├── PatternType.java │ │ │ ├── Styles.java │ │ │ ├── Theme.java │ │ │ └── Verticals.java │ │ ├── hash │ │ ├── AbstractStreamingHasher.java │ │ ├── LockFreeBitArray.java │ │ ├── Murmur3_128Hasher.java │ │ └── StringBloomFilter.java │ │ ├── manager │ │ ├── Const.java │ │ ├── ExcelType.java │ │ ├── NS.java │ │ ├── RelManager.java │ │ ├── TopNS.java │ │ └── docProps │ │ │ ├── App.java │ │ │ ├── Core.java │ │ │ ├── CustomProperties.java │ │ │ ├── Tuple2.java │ │ │ └── XmlEntity.java │ │ ├── processor │ │ ├── ConversionProcessor.java │ │ ├── Converter.java │ │ ├── ParamProcessor.java │ │ └── StyleProcessor.java │ │ ├── reader │ │ ├── AppInfo.java │ │ ├── Cache.java │ │ ├── CalcSheet.java │ │ ├── Cell.java │ │ ├── CellType.java │ │ ├── Col.java │ │ ├── Dimension.java │ │ ├── Drawings.java │ │ ├── ExcelReadException.java │ │ ├── ExcelReader.java │ │ ├── FixSizeLRUCache.java │ │ ├── FullSheet.java │ │ ├── Grid.java │ │ ├── GridFactory.java │ │ ├── HeaderRow.java │ │ ├── IndexSharedStringTable.java │ │ ├── MergeSheet.java │ │ ├── PreCalc.java │ │ ├── Row.java │ │ ├── RowSetIterator.java │ │ ├── SharedStrings.java │ │ ├── Sheet.java │ │ ├── TypeCastException.java │ │ ├── UncheckedTypeException.java │ │ ├── XMLDrawings.java │ │ ├── XMLRow.java │ │ └── XMLSheet.java │ │ ├── util │ │ ├── CSVUtil.java │ │ ├── DateUtil.java │ │ ├── ExtBufferedWriter.java │ │ ├── ExtXMLWriter.java │ │ ├── FileSignatures.java │ │ ├── FileUtil.java │ │ ├── ReflectUtil.java │ │ ├── StringUtil.java │ │ └── ZipUtil.java │ │ └── validation │ │ ├── DateValidation.java │ │ ├── ListValidation.java │ │ ├── TextLengthValidation.java │ │ ├── TimeValidation.java │ │ ├── Tuple2Validation.java │ │ ├── Validation.java │ │ └── WholeValidation.java └── resources │ ├── numFmt │ └── template │ └── theme1.xml └── test ├── java └── org │ └── ttzero │ └── excel │ ├── Print.java │ ├── annotation │ ├── CellData.java │ ├── Converter.java │ ├── CustomAnnoReaderTest.java │ └── HeaderStyleTest.java │ ├── bloom │ └── BloomFilterTest.java │ ├── customAnno │ └── ExcelProperty.java │ ├── entity │ ├── AutoSizeTest.java │ ├── CommentTest.java │ ├── CustomColIndexTest.java │ ├── CustomerNumFmtTest.java │ ├── CustomizeDataSourceSheet.java │ ├── EmptySheetTest.java │ ├── FreezeSheetTest.java │ ├── GridLinesTest.java │ ├── HideColumnTest.java │ ├── ListMapPagingTest.java │ ├── ListMapSheetTest.java │ ├── ListObjectPagingTest.java │ ├── ListObjectSheetTest.java │ ├── ListObjectSheetTest2.java │ ├── MultiHeaderColumnsTest.java │ ├── MultiWorksheetTest.java │ ├── PictureTest.java │ ├── ReLimitXMLWorkbookWriter.java │ ├── ReportDesignTest.java │ ├── ResultSetPagingTest.java │ ├── ResultSetSheetTest.java │ ├── SQLWorkbookTest.java │ ├── SharedStringTableTest.java │ ├── SharedStringsTest.java │ ├── SimpleSheetTest.java │ ├── StatementPagingTest.java │ ├── StatementSheetTest.java │ ├── StyleDesignTest.java │ ├── TemplateSheetTest.java │ ├── ValidationTest.java │ ├── WorkbookTest.java │ ├── XMLCellValueAndStyleTest.java │ ├── ZebraLineTest.java │ ├── csv │ │ ├── CsvToExcelTest.java │ │ ├── ListMapSheetTest.java │ │ ├── ListObjectSheetTest.java │ │ ├── ResultSetSheetTest.java │ │ └── StatementSheetTest.java │ └── style │ │ └── StylesTest.java │ ├── reader │ ├── CacheTest.java │ ├── CacheTesterTest.java │ ├── DimensionTest.java │ ├── ExcelReaderTest.java │ ├── ExcelReaderTest2.java │ ├── FormulasLoader.java │ ├── GridTest.java │ ├── IndexSharedStringTableTest.java │ ├── MultiHeaderReaderTest.java │ ├── MultiStyleInCellTest.java │ ├── PreCalcTest.java │ ├── ReadStyleTest.java │ └── SharedStringsTest.java │ ├── service │ └── StudentService.java │ └── util │ ├── CSVUtilTest.java │ ├── DateUtilTest.java │ └── ReflectUtilTest.java └── resources ├── #145.xlsx ├── #148.xlsx ├── #150.xlsx ├── #169.xlsx ├── #175.xlsx ├── #226.xlsx ├── #238.xlsx ├── #354.xlsx ├── #81.xlsx ├── 1.xlsx ├── 247&249.xlsx ├── 4.xlsx ├── Number2Excel.xlsx ├── all type.xlsx ├── drawing.xlsx ├── elven-eyes.jpg ├── expect ├── #145$plu.txt ├── #148$Sheet1.txt ├── #354$人员导入模版.txt ├── #354$人员导入模版说明.txt ├── #81$Sheet1.txt ├── 1$Object测试.txt ├── 4$用户注册.txt ├── formula$Sheet1$formulas.txt └── formula$Sheet3$formulas.txt ├── formula.xlsx ├── fracture merged.xlsx ├── inner string.xlsx ├── largeMerged.xlsx ├── logback.xml ├── mark.png ├── merge.xlsx ├── multi-style In cell.xlsx ├── template.xlsx ├── template2.xlsx ├── test-fixed-row.xlsx └── test.properties /.gitignore: -------------------------------------------------------------------------------- 1 | ### common ### 2 | /target/ 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | 26 | ### VS Code ### 27 | .vscode/ 28 | 29 | ### Eclipse ### 30 | /.classpath 31 | /.project 32 | /.settings/ -------------------------------------------------------------------------------- /images/auto-width.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/images/auto-width.png -------------------------------------------------------------------------------- /images/dynamic_style.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/images/dynamic_style.png -------------------------------------------------------------------------------- /images/multi-headers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/images/multi-headers.png -------------------------------------------------------------------------------- /images/preset_effect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/images/preset_effect.jpg -------------------------------------------------------------------------------- /images/report1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/images/report1.png -------------------------------------------------------------------------------- /images/report3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/images/report3.png -------------------------------------------------------------------------------- /images/simple_sheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/images/simple_sheet.png -------------------------------------------------------------------------------- /images/write_read_100w.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/images/write_read_100w.jpg -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/ExcelColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Inherited; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * 定义可重复的{@link ExcelColumn}注解以支持多行表头,导出时的表头顺序按注解顺序 28 | * 29 | * @author guanquan.wang at 2022-06-27 23:05 30 | */ 31 | @Target({ ElementType.FIELD, ElementType.METHOD }) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Inherited 34 | @Documented 35 | public @interface ExcelColumns { 36 | /** 37 | * 支持多个ExcelColumn 38 | * 39 | * @return ExcelColumn数组 40 | */ 41 | ExcelColumn[] value(); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/FreezePanes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.annotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Inherited; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | * 设置行列“冻结”,滚动工作表时保持首行或首列总是可见,此功能为增强型功能。 29 | * 30 | *

注意:不能指定一个范围值,冻结必须从首行和首列开始,只能指定结尾行列号,如{@code FreezePanes(topRow = 3)} 31 | * 这段代码将冻结前3行即1,2,3这三行在滚动工作表时总是可见且总是在顶部,{@code firstColumn}也是同样的效果

32 | * 33 | * @author guanquan.wang at 2022-04-17 11:35 34 | */ 35 | @Target(ElementType.TYPE) 36 | @Retention(RetentionPolicy.RUNTIME) 37 | @Inherited 38 | @Documented 39 | public @interface FreezePanes { 40 | /** 41 | * 指定冻结的结尾行号(从1开始),0和负数表示不冻结 42 | * 43 | * @return 从1开始的行号,0和负数表示不冻结 44 | */ 45 | int topRow() default 0; 46 | 47 | /** 48 | * 指定冻结的结尾列号(从1开始),0和负数表示不冻结 49 | * 50 | * @return 从1开始的列号,0和负数表示不冻结 51 | */ 52 | int firstColumn() default 0; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/HeaderComment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2020, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.annotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * 表头批注,{@code title}将加粗显示但不是必须的,大多数情况下将批注文本放到{@code value}下即可, 28 | * 描述文本较多时需要使用{@code width}和{@code height}两个属性来调整弹出框的大小以将内容显示完全 29 | * 30 | * @author guanquan.wang at 2020-05-21 16:43 31 | */ 32 | @Target({ElementType.FIELD, ElementType.METHOD}) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Documented 35 | public @interface HeaderComment { 36 | /** 37 | * 批注正文 38 | * 39 | * @return 正文文本,为空时不显示批注 40 | */ 41 | String value() default ""; 42 | 43 | /** 44 | * 批注标题,加粗显示 45 | * 46 | * @return 标题,可为空 47 | */ 48 | String title() default ""; 49 | 50 | /** 51 | * 指定批注弹出框宽度 52 | * 53 | * @return 批注宽度 54 | */ 55 | double width() default 100.8D; 56 | 57 | /** 58 | * 指定批注弹出框高度 59 | * 60 | * @return 批注高度 61 | */ 62 | double height() default 60.6D; 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/HeaderStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2021, carl.jia@qq.com All Rights Reserved. 3 | * Copyright (c) 2017-2021, guanquan.wang@yandex.com All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package org.ttzero.excel.annotation; 20 | 21 | import org.ttzero.excel.entity.style.Fill; 22 | 23 | import java.lang.annotation.Documented; 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * Custom header styles 31 | * 32 | * @author jialei2 at 2021-05-10 17:38 33 | * @author guanquan.wang at 2021-08-06 18:19 34 | */ 35 | @Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD }) 36 | @Retention(RetentionPolicy.RUNTIME) 37 | @Documented 38 | public @interface HeaderStyle { 39 | 40 | /** 41 | * Set font color. 42 | * 43 | * @return color 44 | */ 45 | String fontColor() default "black"; 46 | 47 | /** 48 | * Set the foreground color. 49 | * 50 | * @see Fill#parse(java.lang.String) 51 | * @return color 52 | */ 53 | String fillFgColor() default "#E9EAEC"; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/Hyperlink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2024, guanquan.wang@hotmail.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.annotation; 19 | 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * 指定当前列为"超链接"格式 28 | * 29 | * @author guanquan.wang at 2024-03-26 15:23 30 | */ 31 | @Target({ElementType.FIELD, ElementType.METHOD}) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | public @interface Hyperlink { } 34 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/IgnoreExport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.annotation; 18 | 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Inherited; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | * 忽略导出,标记有此注解的字段和方法导出时将被忽略,一般用于忽略敏感字段 29 | * 30 | * @author guanquan.wang at 2018-01-30 15:09 31 | */ 32 | @Target({ ElementType.FIELD, ElementType.METHOD }) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Inherited 35 | @Documented 36 | public @interface IgnoreExport { 37 | /** 38 | * 填写忽略原因,无实际意义 39 | * 40 | * @return 忽略的原因 41 | */ 42 | String value() default ""; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/IgnoreImport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Inherited; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * 忽略导入,标记有此注解的字段和方法导入时将被忽略 28 | * 29 | * @author guanquan.wang at 2018-10-24 09:29 30 | */ 31 | @Target({ ElementType.FIELD, ElementType.METHOD }) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Inherited 34 | @Documented 35 | public @interface IgnoreImport { 36 | /** 37 | * 填写忽略原因,无实际意义 38 | * 39 | * @return 忽略的原因 40 | */ 41 | String value() default ""; 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/MediaColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.annotation; 19 | 20 | import org.ttzero.excel.drawing.PresetPictureEffect; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Inherited; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * 指定当前列为"媒体"格式 30 | * 31 | *

默认情况下总是以"值"的形式导出,如果需要导出图片则必须添加{@code MediaColumn}注解, 32 | * 在指定属性的同时可以使用{@link #presetEffect()}设置预设图片效果

33 | * 34 | * @see PresetPictureEffect 35 | * @author guanquan.wang at 2023-08-06 09:15 36 | */ 37 | @Target({ ElementType.FIELD, ElementType.METHOD }) 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Inherited 40 | public @interface MediaColumn { 41 | /** 42 | * 设置预设图片效果,默认无效果 43 | * 44 | * @return {@link PresetPictureEffect} 45 | */ 46 | PresetPictureEffect presetEffect() default PresetPictureEffect.None; 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/RowNum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2021, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Inherited; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * 注入行号,可用于读取Excel时注入该行在文件中的绝对行号 28 | * 29 | *

注意:此行号是Excel的绝对行号,与打开Excel看到的行号完全一致,从1开始

30 | * 31 | * @author guanquan.wang at 2021-12-03 13:40 32 | */ 33 | @Target({ ElementType.FIELD, ElementType.METHOD }) 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Inherited 36 | @Documented 37 | public @interface RowNum { 38 | // /** 39 | // * Specify the beginning number, one-base default. 40 | // * 41 | // * @return the beginning number 42 | // */ 43 | // int begins() default 1; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/annotation/StyleDesign.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved. 3 | * and/or licensed to one or more contributor license agreements. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.ttzero.excel.annotation; 19 | 20 | import org.ttzero.excel.processor.StyleProcessor; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Inherited; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * 动态样式处理器 30 | * 31 | *

动态样式是指根据行数据为每个单元格或整行设置不同样式,这个功能可以极大丰富文件的可读性和多样性. 32 | * StyleDesign注解作用于{@code type}类时修改整行样式,作用于{@code field}和{@code method} 33 | * 时修改单个单元格样式。StyleDesign指定的样式处理器必须实现{@link StyleProcessor}接口,

34 | * 35 | *

参考文档:

36 | *

动态设置样式

37 | * 38 | * @see StyleProcessor 39 | * @author suyl at 2022-03-23 17:38 40 | * 41 | */ 42 | @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD}) 43 | @Retention(RetentionPolicy.RUNTIME) 44 | @Inherited 45 | public @interface StyleDesign { 46 | /** 47 | * 指定动态样式处理器 48 | * 49 | * @return 样式处理器 50 | */ 51 | Class using() default StyleProcessor.None.class; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/Bevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | import static org.ttzero.excel.drawing.Enums.PresetBevel; 21 | 22 | /** 23 | * 此元素定义与应用于表中单元格的3D效果关联的棱台的属性。 24 | * 25 | * @see Shape3D 26 | * @author guanquan.wang at 2023-07-25 09:24 27 | */ 28 | public class Bevel { 29 | /** 30 | * height: 指定棱台的高度,或者它所应用的形状上方有多远。 31 | * width: 指定棱台的宽度,或它所应用的形状的距离。 32 | */ 33 | public double width, height; 34 | /** 35 | * 预设棱台 36 | */ 37 | public PresetBevel prst; 38 | 39 | public double getWidth() { 40 | return width; 41 | } 42 | 43 | public Bevel setWidth(double width) { 44 | this.width = width; 45 | return this; 46 | } 47 | 48 | public double getHeight() { 49 | return height; 50 | } 51 | 52 | public Bevel setHeight(double height) { 53 | this.height = height; 54 | return this; 55 | } 56 | 57 | public PresetBevel getPrst() { 58 | return prst; 59 | } 60 | 61 | public Bevel setPrst(PresetBevel prst) { 62 | this.prst = prst; 63 | return this; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/Camera.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | import static org.ttzero.excel.drawing.Enums.PresetCamera; 21 | 22 | /** 23 | * @author guanquan.wang at 2023-07-26 15:21 24 | */ 25 | public class Camera { 26 | /** 27 | * Preset camera 28 | */ 29 | public PresetCamera presetCamera; 30 | /** 31 | * A zoom can be applied to the camera position by adding a zoom 32 | * attribute to the {@code camera} element. It is a percentage. 33 | */ 34 | public int zoom; 35 | /** 36 | * The field of view can be modified from the view set by the preset 37 | * camera setting by adding a fov attribute to the {@code camera} element. (0-180) 38 | */ 39 | public double fov; 40 | /** 41 | * The preset placement can be altered by specifying a child {@code rot} element. 42 | * The {@code rot} element defines a rotation by specifying a latitude coordinate (a lat attribute), 43 | * a longitude coordinate (a lon attribute), and a revolution (a rev attribute) about the axis. 44 | */ 45 | public double latitude, longitude, revolution; 46 | 47 | public PresetCamera getPresetCamera() { 48 | return presetCamera; 49 | } 50 | 51 | public Camera setPresetCamera(PresetCamera presetCamera) { 52 | this.presetCamera = presetCamera; 53 | return this; 54 | } 55 | 56 | public int getZoom() { 57 | return zoom; 58 | } 59 | 60 | public Camera setZoom(int zoom) { 61 | this.zoom = zoom; 62 | return this; 63 | } 64 | 65 | public double getFov() { 66 | return fov; 67 | } 68 | 69 | public Camera setFov(double fov) { 70 | this.fov = fov; 71 | return this; 72 | } 73 | 74 | public double getLatitude() { 75 | return latitude; 76 | } 77 | 78 | public Camera setLatitude(double latitude) { 79 | this.latitude = latitude; 80 | return this; 81 | } 82 | 83 | public double getLongitude() { 84 | return longitude; 85 | } 86 | 87 | public Camera setLongitude(double longitude) { 88 | this.longitude = longitude; 89 | return this; 90 | } 91 | 92 | public double getRevolution() { 93 | return revolution; 94 | } 95 | 96 | public Camera setRevolution(double revolution) { 97 | this.revolution = revolution; 98 | return this; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/EffectProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | 21 | /** 22 | * Effects Producer 23 | * 24 | * @author guanquan.wang at 2023-08-06 09:15 25 | */ 26 | public interface EffectProducer { 27 | /** 28 | * Returns an Excel effect entity 29 | * 30 | * @return {@link Effect} 31 | */ 32 | Effect getEffect(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/Fill.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | import java.awt.Color; 21 | 22 | /** 23 | * @author guanquan.wang at 2023-07-25 14:45 24 | */ 25 | public class Fill { 26 | 27 | /** 28 | * Solid file 29 | */ 30 | public static class SolidFill extends Fill { 31 | /** 32 | * Specifies fill color 33 | */ 34 | public Color color; 35 | /** 36 | * Specifies fill transparency (0-100) 37 | */ 38 | public int alpha; 39 | 40 | public int shade; 41 | 42 | public Color getColor() { 43 | return color; 44 | } 45 | 46 | public SolidFill setColor(Color color) { 47 | this.color = color; 48 | return this; 49 | } 50 | 51 | public int getAlpha() { 52 | return alpha; 53 | } 54 | 55 | public SolidFill setAlpha(int alpha) { 56 | this.alpha = alpha; 57 | return this; 58 | } 59 | 60 | public int getShade() { 61 | return shade; 62 | } 63 | 64 | public SolidFill setShade(int shade) { 65 | this.shade = shade; 66 | return this; 67 | } 68 | } 69 | 70 | // /** 71 | // * Pattern Fill 72 | // */ 73 | // public static class PatternFill extends Fill { 74 | // public Color bgColor, fgColor; 75 | // public PatternValues pattern; 76 | // } 77 | // 78 | // /** 79 | // * Gradient Fill 80 | // */ 81 | // public static class GradientFill extends Fill { 82 | // 83 | // } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/Glow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | import java.awt.Color; 21 | 22 | /** 23 | * @author guanquan.wang at 2023-08-01 19:44 24 | */ 25 | public class Glow { 26 | /** 27 | * Specifies shadow color 28 | */ 29 | public Color color; 30 | /** 31 | * Specifies shadow transparency (0-100) 32 | */ 33 | public int alpha; 34 | /** 35 | * Specifies how far to offset the glow (0-150) 36 | */ 37 | public double dist; 38 | 39 | public Color getColor() { 40 | return color; 41 | } 42 | 43 | public Glow setColor(Color color) { 44 | this.color = color; 45 | return this; 46 | } 47 | 48 | public int getAlpha() { 49 | return alpha; 50 | } 51 | 52 | public Glow setAlpha(int alpha) { 53 | this.alpha = alpha; 54 | return this; 55 | } 56 | 57 | public double getDist() { 58 | return dist; 59 | } 60 | 61 | public Glow setDist(double dist) { 62 | this.dist = dist; 63 | return this; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/LightRig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | import static org.ttzero.excel.drawing.Enums.Angle; 21 | import static org.ttzero.excel.drawing.Enums.Rig; 22 | 23 | /** 24 | * @author guanquan.wang at 2023-07-26 15:21 25 | */ 26 | public class LightRig { 27 | /** 28 | * Preset Properties 29 | */ 30 | public Rig rig; 31 | /** 32 | * alignment 33 | */ 34 | public Angle angle; 35 | /** 36 | * The preset placement can be altered by specifying a child {@code rot} element. 37 | * The {@code rot} element defines a rotation by specifying a latitude coordinate (a lat attribute), 38 | * a longitude coordinate (a lon attribute), and a revolution (a rev attribute) about the axis. 39 | */ 40 | public double latitude, longitude, revolution; 41 | 42 | public Rig getRig() { 43 | return rig; 44 | } 45 | 46 | public LightRig setRig(Rig rig) { 47 | this.rig = rig; 48 | return this; 49 | } 50 | 51 | public Angle getAngle() { 52 | return angle; 53 | } 54 | 55 | public LightRig setAngle(Angle angle) { 56 | this.angle = angle; 57 | return this; 58 | } 59 | 60 | public double getLatitude() { 61 | return latitude; 62 | } 63 | 64 | public LightRig setLatitude(double latitude) { 65 | this.latitude = latitude; 66 | return this; 67 | } 68 | 69 | public double getLongitude() { 70 | return longitude; 71 | } 72 | 73 | public LightRig setLongitude(double longitude) { 74 | this.longitude = longitude; 75 | return this; 76 | } 77 | 78 | public double getRevolution() { 79 | return revolution; 80 | } 81 | 82 | public LightRig setRevolution(double revolution) { 83 | this.revolution = revolution; 84 | return this; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/Outline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | import java.awt.Color; 21 | 22 | import static org.ttzero.excel.drawing.Enums.Cap; 23 | import static org.ttzero.excel.drawing.Enums.CompoundType; 24 | import static org.ttzero.excel.drawing.Enums.DashPattern; 25 | import static org.ttzero.excel.drawing.Enums.JoinType; 26 | 27 | /** 28 | * The style of the shape's outline is specified with the <a:ln> element. 29 | * The properties that are determined by this element include such things 30 | * as the size or weight of the outline, the color, the fill type, and the connector ends. 31 | * (The style of joints where lines connect is also determined by this element but is not covered here.) 32 | * 33 | * @author guanquan.wang at 2023-07-25 14:45 34 | */ 35 | public class Outline { 36 | public Color color; 37 | /** 38 | * Specifies line transparency (0-100) 39 | */ 40 | public int alpha; 41 | /** 42 | * Specifies line width 43 | */ 44 | public double width; 45 | public Cap cap; 46 | public CompoundType cmpd; 47 | public DashPattern dash; 48 | public JoinType joinType; 49 | /** 50 | * If the {@code JoinType} is set to the {@code Miter}, the MiterLimit property is 51 | * multiplied by half the {@code width} value to specify a distance at which the 52 | * intersection of lines is clipped. 53 | */ 54 | public double miterLimit; 55 | 56 | public Color getColor() { 57 | return color; 58 | } 59 | 60 | public Outline setColor(Color color) { 61 | this.color = color; 62 | return this; 63 | } 64 | 65 | public int getAlpha() { 66 | return alpha; 67 | } 68 | 69 | public Outline setAlpha(int alpha) { 70 | this.alpha = alpha; 71 | return this; 72 | } 73 | 74 | public double getWidth() { 75 | return width; 76 | } 77 | 78 | public Outline setWidth(double width) { 79 | this.width = width; 80 | return this; 81 | } 82 | 83 | public Cap getCap() { 84 | return cap; 85 | } 86 | 87 | public Outline setCap(Cap cap) { 88 | this.cap = cap; 89 | return this; 90 | } 91 | 92 | public CompoundType getCmpd() { 93 | return cmpd; 94 | } 95 | 96 | public Outline setCmpd(CompoundType cmpd) { 97 | this.cmpd = cmpd; 98 | return this; 99 | } 100 | 101 | public DashPattern getDash() { 102 | return dash; 103 | } 104 | 105 | public Outline setDash(DashPattern dash) { 106 | this.dash = dash; 107 | return this; 108 | } 109 | 110 | public JoinType getJoinType() { 111 | return joinType; 112 | } 113 | 114 | public Outline setJoinType(JoinType joinType) { 115 | this.joinType = joinType; 116 | return this; 117 | } 118 | 119 | public double getMiterLimit() { 120 | return miterLimit; 121 | } 122 | 123 | public Outline setMiterLimit(double miterLimit) { 124 | this.miterLimit = miterLimit; 125 | return this; 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/Reflection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | /** 21 | * Creates a partial image reflection near your picture, 22 | * with a few options for angles and degree of the reflection. 23 | * 24 | * @author guanquan.wang at 2023-07-25 09:24 25 | */ 26 | public class Reflection { 27 | /** 28 | * Specifies shadow transparency (0-100) 29 | */ 30 | public int alpha; 31 | /** 32 | * Specifies shadow size (0-100) 33 | */ 34 | public double size; 35 | /** 36 | * Specifies the radius of the blur (0-100) 37 | */ 38 | public double blur; 39 | /** 40 | * Specifies how far to offset the shadow (0-100) 41 | */ 42 | public double dist; 43 | /** 44 | * Specifies the direction to offset the shadow (0-360) 45 | */ 46 | public int direction = 90; 47 | 48 | public int getAlpha() { 49 | return alpha; 50 | } 51 | 52 | public Reflection setAlpha(int alpha) { 53 | this.alpha = alpha; 54 | return this; 55 | } 56 | 57 | public double getSize() { 58 | return size; 59 | } 60 | 61 | public Reflection setSize(double size) { 62 | this.size = size; 63 | return this; 64 | } 65 | 66 | public double getBlur() { 67 | return blur; 68 | } 69 | 70 | public Reflection setBlur(double blur) { 71 | this.blur = blur; 72 | return this; 73 | } 74 | 75 | public double getDist() { 76 | return dist; 77 | } 78 | 79 | public Reflection setDist(double dist) { 80 | this.dist = dist; 81 | return this; 82 | } 83 | 84 | public int getDirection() { 85 | return direction; 86 | } 87 | 88 | public Reflection setDirection(int direction) { 89 | this.direction = direction; 90 | return this; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/Scene3D.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | /** 21 | * 3D 场景属性 22 | * 23 | * @author guanquan.wang at 2023-07-26 15:21 24 | */ 25 | public class Scene3D { 26 | /** 27 | * The placement and properties of the camera in the 3D scene modify the view of the scene 28 | */ 29 | public Camera camera; 30 | 31 | /** 32 | * A light rig is relevant when there is a 3D bevel. The light rig defines 33 | * the lighting properties associated with a scene and is specified with the 34 | * {@code lightRig} element. It has a rig attribute which specifies a preset group of lights 35 | * oriented in a specific way relative to the scene. 36 | */ 37 | public LightRig lightRig; 38 | 39 | public Camera getCamera() { 40 | return camera; 41 | } 42 | 43 | public Scene3D setCamera(Camera camera) { 44 | this.camera = camera; 45 | return this; 46 | } 47 | 48 | public LightRig getLightRig() { 49 | return lightRig; 50 | } 51 | 52 | public Scene3D setLightRig(LightRig lightRig) { 53 | this.lightRig = lightRig; 54 | return this; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/drawing/Shape3D.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.drawing; 19 | 20 | import java.awt.Color; 21 | 22 | import static org.ttzero.excel.drawing.Enums.Material; 23 | 24 | /** 25 | * @author guanquan.wang at 2023-07-26 15:21 26 | */ 27 | public class Shape3D { 28 | /** 29 | * Both bevel elements are empty elements with three attributes 30 | * which define the characteristics of the bevel. 31 | */ 32 | public Bevel bevelTop, bevelBottom; 33 | /** 34 | * Specifies a preset material type, which is a combination 35 | * of lighting characteristics which are intended to mimic the material. 36 | */ 37 | public Material material; 38 | /** 39 | * A contour is a solid filled line that surrounds the outer edge of the shape. 40 | */ 41 | public Color contourColor; 42 | public double contourWidth; 43 | /** 44 | * An extrusion is an artificial height applied to the shape. 45 | */ 46 | public Color extrusionColor; 47 | public double extrusionHeight; 48 | 49 | public Bevel getBevelTop() { 50 | return bevelTop; 51 | } 52 | 53 | public Shape3D setBevelTop(Bevel bevelTop) { 54 | this.bevelTop = bevelTop; 55 | return this; 56 | } 57 | 58 | public Bevel getBevelBottom() { 59 | return bevelBottom; 60 | } 61 | 62 | public Shape3D setBevelBottom(Bevel bevelBottom) { 63 | this.bevelBottom = bevelBottom; 64 | return this; 65 | } 66 | 67 | public Material getMaterial() { 68 | return material; 69 | } 70 | 71 | public Shape3D setMaterial(Material material) { 72 | this.material = material; 73 | return this; 74 | } 75 | 76 | public Color getContourColor() { 77 | return contourColor; 78 | } 79 | 80 | public Shape3D setContourColor(Color contourColor) { 81 | this.contourColor = contourColor; 82 | return this; 83 | } 84 | 85 | public double getContourWidth() { 86 | return contourWidth; 87 | } 88 | 89 | public Shape3D setContourWidth(double contourWidth) { 90 | this.contourWidth = contourWidth; 91 | return this; 92 | } 93 | 94 | public Color getExtrusionColor() { 95 | return extrusionColor; 96 | } 97 | 98 | public Shape3D setExtrusionColor(Color extrusionColor) { 99 | this.extrusionColor = extrusionColor; 100 | return this; 101 | } 102 | 103 | public double getExtrusionHeight() { 104 | return extrusionHeight; 105 | } 106 | 107 | public Shape3D setExtrusionHeight(double extrusionHeight) { 108 | this.extrusionHeight = extrusionHeight; 109 | return this; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/CollectionSheet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | //package org.ttzero.excel.entity; 18 | // 19 | //import java.lang.reflect.Field; 20 | //import java.util.Collection; 21 | // 22 | ///** 23 | // * @author guanquan.wang at 2019-04-30 20:45 24 | // */ 25 | //public class CollectionSheet extends Sheet { 26 | // @SuppressWarnings("unused") 27 | // private Collection data; 28 | // @SuppressWarnings("unused") 29 | // private Field[] fields; 30 | // 31 | // /** 32 | // * Constructor worksheet 33 | // */ 34 | // public CollectionSheet() { 35 | // super(); 36 | // } 37 | // 38 | // /** 39 | // * Constructor worksheet 40 | // * 41 | // * @param name the worksheet name 42 | // */ 43 | // public CollectionSheet(String name) { 44 | // super(name); 45 | // } 46 | // 47 | // /** 48 | // * Constructor worksheet 49 | // * 50 | // * @param name the worksheet name 51 | // * @param columns the {@link Column} 52 | // */ 53 | // public CollectionSheet(String name, final Column... columns) { 54 | // super(name, columns); 55 | // } 56 | // 57 | // /** 58 | // * Constructor worksheet 59 | // * 60 | // * @param name the worksheet name 61 | // * @param waterMark the {@link WaterMark} 62 | // * @param columns the {@link Column} 63 | // */ 64 | // public CollectionSheet(String name, WaterMark waterMark, final Column... columns) { 65 | // super(name, waterMark, columns); 66 | // } 67 | // 68 | // public CollectionSheet setData(final Collection data) { 69 | // this.data = data; 70 | // return this; 71 | // } 72 | // 73 | // @Override 74 | // protected void resetBlockData() { 75 | // 76 | // } 77 | // 78 | //} 79 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/Comment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2020, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.entity; 19 | 20 | import org.ttzero.excel.entity.style.Font; 21 | 22 | /** 23 | * 批注,包含标题和内容且两者且少有一个不为空 24 | * 25 | * @author guanquan.wang at 2020-05-22 09:32 26 | */ 27 | public class Comment { 28 | /** 29 | * 标题,加粗显示 30 | */ 31 | public String title; 32 | /** 33 | * 内容 34 | */ 35 | public String value; 36 | /** 37 | * 指定批注框显示的宽和高 38 | */ 39 | public Double width, height; 40 | /** 41 | * 指定批注字体 42 | */ 43 | public Font titleFont, valueFont; 44 | /** 45 | * Styles 46 | */ 47 | public String style; 48 | 49 | public Comment() { } 50 | 51 | public Comment(String value) { 52 | this.value = value; 53 | } 54 | 55 | public Comment(String title, String value) { 56 | this(title, value, null, null); 57 | } 58 | 59 | public Comment(String value, Double width, Double height) { 60 | this(null, value, width, height); 61 | } 62 | 63 | public Comment(String title, String value, Double width, Double height) { 64 | this.title = title; 65 | this.value = value; 66 | this.width = width; 67 | this.height = height; 68 | } 69 | 70 | public String getTitle() { 71 | return title; 72 | } 73 | 74 | public Comment setTitle(String title) { 75 | this.title = title; 76 | return this; 77 | } 78 | 79 | public Comment setTitle(String title, Font titleFont) { 80 | this.title = title; 81 | this.titleFont = titleFont; 82 | return this; 83 | } 84 | 85 | public String getValue() { 86 | return value; 87 | } 88 | 89 | public Comment setValue(String value) { 90 | this.value = value; 91 | return this; 92 | } 93 | 94 | public Comment setValue(String value, Font valueFont) { 95 | this.value = value; 96 | this.valueFont = valueFont; 97 | return this; 98 | } 99 | 100 | public Double getWidth() { 101 | return width; 102 | } 103 | 104 | public Comment setWidth(Double width) { 105 | this.width = width; 106 | return this; 107 | } 108 | 109 | public Double getHeight() { 110 | return height; 111 | } 112 | 113 | public Comment setHeight(Double height) { 114 | this.height = height; 115 | return this; 116 | } 117 | 118 | public Font getTitleFont() { 119 | return titleFont; 120 | } 121 | 122 | public Comment setTitleFont(Font titleFont) { 123 | this.titleFont = titleFont; 124 | return this; 125 | } 126 | 127 | public Font getValueFont() { 128 | return valueFont; 129 | } 130 | 131 | public Comment setValueFont(Font valueFont) { 132 | this.valueFont = valueFont; 133 | return this; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/EmptySheet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | /** 23 | * 空工作表,可用于占位,如果指定表头则会输出表头 24 | * 25 | * @author guanquan.wang at 2018-01-29 16:05 26 | */ 27 | public class EmptySheet extends Sheet { 28 | 29 | /** 30 | * 实例化工作表,未指定工作表名称时默认以{@code 'Sheet'+id}命名 31 | */ 32 | public EmptySheet() { 33 | super(); 34 | } 35 | 36 | /** 37 | * 实例化工作表并指定工作表名称 38 | * 39 | * @param name 工作表名称 40 | */ 41 | public EmptySheet(String name) { 42 | super(name); 43 | } 44 | 45 | /** 46 | * 实例化工作表并指定表头信息 47 | * 48 | * @param columns 表头信息 49 | */ 50 | public EmptySheet(Column... columns) { 51 | super(columns); 52 | } 53 | 54 | /** 55 | * 实例化工作表并指定工作表名称和表头信息 56 | * 57 | * @param name 工作表名称 58 | * @param columns 表头信息 59 | */ 60 | public EmptySheet(String name, final Column... columns) { 61 | super(name, columns); 62 | } 63 | 64 | /** 65 | * 实例化工作表并指定工作表名称,水印和表头信息 66 | * 67 | * @param name 工作表名称 68 | * @param waterMark 水印 69 | * @param columns 表头信息 70 | */ 71 | public EmptySheet(String name, WaterMark waterMark, final Column... columns) { 72 | super(name, waterMark, columns); 73 | } 74 | 75 | /** 76 | * Reset the row-block data 77 | */ 78 | @Override 79 | protected void resetBlockData() { } 80 | 81 | /** 82 | * Returns total rows in this worksheet 83 | * 84 | * @return 0 85 | */ 86 | @Override 87 | public int size() { 88 | return 0; 89 | } 90 | 91 | /** 92 | * 设置表头信息,与Columns不同的是本方法只设置表头值并不带任何其它属性,可以看为{@link #setColumns(List)}的简化方法 93 | * 94 | * @param header 表头信息列表 95 | * @return 当前对象,支持链式调用 96 | */ 97 | public EmptySheet setHeader(List header) { 98 | Column[] columns; 99 | if (header == null || header.isEmpty()) columns = new Column[0]; 100 | else { 101 | columns = new Column[header.size()]; 102 | for (int i = 0, len = header.size(); i < len; columns[i] = new Column(header.get(i++)).setCellStyle(0)); 103 | } 104 | super.setColumns(columns); 105 | return this; 106 | } 107 | 108 | /** 109 | * 设置表头信息,与Columns不同的是本方法只设置表头值并不带任何其它属性,可以看为{@link #setColumns(Column...)}的简化方法 110 | * 111 | * @param header 表头信息列表 112 | * @return 当前对象,支持链式调用 113 | */ 114 | public EmptySheet setHeader(String ... header) { 115 | return setHeader(Arrays.asList(header)); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/ExcelWriteException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | /** 20 | * Excel导出异常,收集导出所需数据或者参数与预期不符时抛出此异常,通常它不用于写异常,写磁盘异常统一使用{@code IOException}, 21 | * 也就是说{@code ExcelWriteException}是在数据收集阶段它抛出的时机要早于{@code IOException} 22 | * 23 | * @author guanquan.wang on 2017/10/19. 24 | */ 25 | public class ExcelWriteException extends RuntimeException { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | public ExcelWriteException() { 30 | super(); 31 | } 32 | 33 | public ExcelWriteException(String s) { 34 | super(s); 35 | } 36 | 37 | public ExcelWriteException(String message, Throwable cause) { 38 | super(message, cause); 39 | } 40 | 41 | public ExcelWriteException(Throwable cause) { 42 | super(cause); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/IDrawingsWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.entity; 19 | 20 | import java.io.Closeable; 21 | import java.io.IOException; 22 | 23 | /** 24 | * 多媒体类型输出协议(目前只支持图片) 25 | * 26 | * @author guanquan.wang at 2023-03-07 09:09 27 | */ 28 | public interface IDrawingsWriter extends Closeable, Storable { 29 | /** 30 | * 添加图片 31 | * 32 | * @param picture 图片信息{@link Picture} 33 | * @throws IOException if I/O error occur. 34 | */ 35 | void drawing(Picture picture) throws IOException; 36 | 37 | /** 38 | * 异步添加图片 39 | * 40 | * @param picture 图片信息{@link Picture} 41 | * @throws IOException if I/O error occur. 42 | */ 43 | void asyncDrawing(Picture picture) throws IOException; 44 | 45 | /** 46 | * 通知图片已准备好,与{@link #asyncDrawing}搭配使用 47 | * 48 | * @param picture 已完成的图片{@link Picture} 49 | */ 50 | void complete(Picture picture); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/Panes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.entity; 19 | 20 | /** 21 | * Panes 22 | * 23 | * @author guanquan.wang at 2022-04-17 10:38 24 | */ 25 | public class Panes { 26 | /** 27 | * Panes row 28 | */ 29 | public int row; 30 | /** 31 | * Panes col 32 | */ 33 | public int col; 34 | 35 | public Panes() { } 36 | 37 | public Panes(int row, int col) { 38 | this.row = row; 39 | this.col = col; 40 | } 41 | 42 | public static Panes of(final int row, final int col) { 43 | return new Panes(row, col); 44 | } 45 | 46 | public static Panes row(final int row) { 47 | return new Panes(row, 0); 48 | } 49 | 50 | public static Panes col(final int col) { 51 | return new Panes(0, col); 52 | } 53 | 54 | public int getRow() { 55 | return row; 56 | } 57 | 58 | public void setRow(int row) { 59 | this.row = row; 60 | } 61 | 62 | public int getCol() { 63 | return col; 64 | } 65 | 66 | public void setCol(int col) { 67 | this.col = col; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/Relationship.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * 资源的关联关系,Excel将部分资源统一存放在一个公共区域,例如图片,图表,批注等。 23 | * 工作表添加图片,图表的时候只需要添加一个关联就可以引用到这些资源,这样做可以起到共享资源的目的。 24 | * 25 | *

每个{@code Relationship}都包含一个{@code Id}值,其它引用者通过该Id值确定唯一的源, 26 | * {@code Target}保存资源的相对位置,这里的位置是相对于引用者而不是当前关联表存放位置, 27 | * 最后一个{@code Type}属性是一个固定的{@code schema}值表示资源的类型,这里{@link org.ttzero.excel.manager.Const.Relationship} 28 | * 定义了当前支持的{@code schema}

29 | * 30 | *

{@code Relationship}并不会独立存在,它对应一个{@code rels}管理者,{@link org.ttzero.excel.manager.RelManager} 31 | * 就是关系管理器的角色,每个引用者都包含一个独立的关系管理器,所以每个关系管理器中{@code Relationship}的{@code Id}值都是从{@code 1}开始的, 32 | * 即使相同的资源在不同管理器中的{@code Id}值都可能不同

33 | * 34 | * @author guanquan.wang on 2017/9/30. 35 | */ 36 | public class Relationship implements Serializable, Cloneable { 37 | 38 | private static final long serialVersionUID = 1L; 39 | /** 40 | * 资源的相对位置,这里的位置是相对于引用者而不是当前关联表存放位置 41 | */ 42 | private String target; 43 | /** 44 | * 资源的一个固定{@code schema}值表示资源的类型 45 | */ 46 | private String type; 47 | /** 48 | * 引用者通过该Id查询对应的引用资源 49 | */ 50 | private String id; 51 | /** 52 | * Mode 53 | */ 54 | private String targetMode; 55 | 56 | public Relationship() { } 57 | 58 | public Relationship(String target, String type) { 59 | this(null, target, type, null); 60 | } 61 | 62 | public Relationship(String id, String target, String type) { 63 | this(id, target, type, null); 64 | } 65 | 66 | public Relationship(String id, String target, String type, String targetMode) { 67 | this.id = id; 68 | this.target = target; 69 | this.type = type; 70 | this.targetMode = targetMode; 71 | } 72 | 73 | public String getTarget() { 74 | return target; 75 | } 76 | 77 | public Relationship setTarget(String target) { 78 | this.target = target; 79 | return this; 80 | } 81 | 82 | public String getType() { 83 | return type; 84 | } 85 | 86 | public Relationship setType(String type) { 87 | this.type = type; 88 | return this; 89 | } 90 | 91 | public String getId() { 92 | return id; 93 | } 94 | 95 | public Relationship setId(String id) { 96 | this.id = id; 97 | return this; 98 | } 99 | 100 | public String getTargetMode() { 101 | return targetMode; 102 | } 103 | 104 | public Relationship setTargetMode(String targetMode) { 105 | this.targetMode = targetMode; 106 | return this; 107 | } 108 | 109 | @Override 110 | public Relationship clone() { 111 | Relationship r; 112 | try { 113 | r = (Relationship) super.clone(); 114 | } catch (CloneNotSupportedException e) { 115 | r = new Relationship(); 116 | r.id = id; 117 | r.target = target; 118 | r.type = type; 119 | r.targetMode = targetMode; 120 | } 121 | return r; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/Row.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import org.ttzero.excel.reader.Cell; 20 | 21 | /** 22 | * 行数据,每个{@code Row}对象包含一组连续的{@link Cell}单元格, 23 | * 它的设计与在Office中看到的结构完全一样 24 | * 25 | * @author guanquan.wang at 2019-04-23 09:57 26 | */ 27 | public class Row { 28 | // Index to row 29 | public int index = -1; 30 | // Index to first column (zero base) 31 | public int fc = 0; 32 | // Index to last column (zero base) 33 | public int lc = -1; 34 | // Share cell 35 | public Cell[] cells; 36 | // height 37 | public Double height; 38 | // Is row hidden 39 | public boolean hidden; 40 | // Outline level 41 | public Integer outlineLevel; 42 | 43 | public int getIndex() { 44 | return index; 45 | } 46 | 47 | public int getFc() { 48 | return fc; 49 | } 50 | 51 | public int getLc() { 52 | return lc; 53 | } 54 | 55 | public Cell[] getCells() { 56 | return cells; 57 | } 58 | 59 | /** 60 | * 分配指定大小的连续单元格 61 | * 62 | * @param n 单元格数量 63 | * @return 单元格数组 64 | */ 65 | public Cell[] malloc(int n) { 66 | return cells = new Cell[lc = n]; 67 | } 68 | 69 | /** 70 | * 分配指定大小的连续单元格并初始化 71 | * 72 | * @param n 单元格数量 73 | * @return 单元格数组 74 | */ 75 | public Cell[] calloc(int n) { 76 | malloc(n); 77 | for (int i = 0; i < n; i++) { 78 | cells[i] = new Cell(); 79 | } 80 | return cells; 81 | } 82 | 83 | /** 84 | * 比较并重分配连续{@code n}个单元格,此方法会比较传入的参数{@code n}与当前单元格数量比较, 85 | * 当{@code n}大于当前数量时才进行重分配 86 | * 87 | * @param n 单元格数量 88 | * @return 单元格数组 89 | */ 90 | public Cell[] realloc(int n) { 91 | if (lc < n) { 92 | calloc(n); 93 | } 94 | return cells; 95 | } 96 | 97 | /** 98 | * 获取行高 99 | * 100 | * @return 行高 101 | */ 102 | public Double getHeight() { 103 | return height; 104 | } 105 | 106 | /** 107 | * 设置行高 108 | * 109 | * @param height 行高 110 | * @return 当前行 111 | */ 112 | public Row setHeight(Double height) { 113 | this.height = height; 114 | return this; 115 | } 116 | 117 | /** 118 | * 判断当前行是否隐藏 119 | * 120 | * @return true: 隐藏 121 | */ 122 | public boolean isHidden() { 123 | return hidden; 124 | } 125 | 126 | /** 127 | * 设置当前行显示或隐藏 128 | * 129 | * @param hidden true:隐藏当前行 false: 显示 130 | */ 131 | public void setHidden(boolean hidden) { 132 | this.hidden = hidden; 133 | } 134 | 135 | /** 136 | * 获取行层级 137 | * 138 | * @return 层级 139 | */ 140 | public Integer getOutlineLevel() { 141 | return outlineLevel; 142 | } 143 | 144 | /** 145 | * 设置行层级 146 | * 147 | * @param outlineLevel 层级(不能为负数) 148 | */ 149 | public void setOutlineLevel(Integer outlineLevel) { 150 | this.outlineLevel = outlineLevel; 151 | } 152 | 153 | /** 154 | * 清除附加属性 155 | * 156 | * @return 当前行 157 | */ 158 | public Row clear() { 159 | hidden = false; 160 | outlineLevel = null; 161 | height = null; 162 | return this; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/Storable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import java.io.IOException; 20 | import java.nio.file.Path; 21 | 22 | /** 23 | * 持久化公共接口,默认落盘处理 24 | * 25 | * @author guanquan.wang at 2019-05-08 13:13 26 | */ 27 | public interface Storable { 28 | /** 29 | * 写入指定路径,传入的参数可以是一个文件也可以是文件夹,需要在实现类具体处理 30 | * 31 | * @param root 父级文件夹或文件绝对路径 32 | * @throws IOException 写失败异常 33 | */ 34 | void writeTo(Path root) throws IOException; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/TooManyColumnsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | /** 20 | * 列超过限制时抛此异常,xlsx文件中的最大列数为16_384 21 | * 22 | * @author guanquan.wang on 2017/10/19. 23 | */ 24 | public class TooManyColumnsException extends ExcelWriteException { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public TooManyColumnsException() { 29 | super(); 30 | } 31 | 32 | public TooManyColumnsException(int n, int m) { 33 | super("The max columns on sheet is " + m + ", current is " + n); 34 | } 35 | 36 | public TooManyColumnsException(String s) { 37 | super(s); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/e7/XMLCellValueAndStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity.e7; 18 | 19 | import org.ttzero.excel.entity.ICellValueAndStyle; 20 | 21 | /** 22 | * @author guanquan.wang at 2019-09-25 11:25 23 | */ 24 | public class XMLCellValueAndStyle implements ICellValueAndStyle { } 25 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/e7/XMLZebraLineCellValueAndStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity.e7; 18 | 19 | import org.ttzero.excel.entity.Column; 20 | import org.ttzero.excel.entity.Row; 21 | import org.ttzero.excel.entity.style.Fill; 22 | import org.ttzero.excel.entity.style.Styles; 23 | 24 | /** 25 | * 斑马线样式,默认情况下从数据行开始计算,每隔一行添加指定填充色,默认填充色为 {@code #E9EAEC}, 26 | * 如果该单元格已有填充样式则保持原填充样式 27 | * 28 | * @author guanquan.wang at 2023-02-24 11:12 29 | */ 30 | public class XMLZebraLineCellValueAndStyle extends XMLCellValueAndStyle { 31 | 32 | /** 33 | * 斑马线填充样值 34 | */ 35 | protected int zebraFillStyle = -1; 36 | /** 37 | * 斑马线填充样式 38 | */ 39 | protected Fill zebraFill; 40 | 41 | public XMLZebraLineCellValueAndStyle(int zebraFillStyle) { 42 | this.zebraFillStyle = zebraFillStyle; 43 | } 44 | 45 | public XMLZebraLineCellValueAndStyle(Fill zebraFill) { 46 | this.zebraFill = zebraFill; 47 | } 48 | 49 | /** 50 | * 获取单元格样式值,先通过{@code Column}获取基础样式并在偶数行添加斑马线填充, 51 | * 如果有动态样式转换则将基础样式做为参数进行二次制作 52 | * 53 | * @param row 行信息 54 | * @param hc 当前列的表头 55 | * @param o 单元格的值 56 | * @return 样式值 57 | */ 58 | @Override 59 | public int getStyleIndex(Row row, Column hc, Object o) { 60 | if (zebraFillStyle == -1 && zebraFill != null) 61 | zebraFillStyle = hc.styles.addFill(zebraFill); 62 | // Default style 63 | int style = hc.getCellStyle(); 64 | // 偶数行且无特殊填充样式时添加斑马线填充 65 | if (isOdd(row.getIndex()) && !Styles.hasFill(style)) style |= zebraFillStyle; 66 | // 处理动态样式 67 | if (hc.styleProcessor != null) { 68 | style = hc.styleProcessor.build(o, style, hc.styles); 69 | } 70 | return hc.styles.of(style); 71 | } 72 | 73 | 74 | /** 75 | * 检查是否需要添加斑马线样式 76 | * 77 | * @param rows 数据行的行号(zero base) 78 | * @return 数据行的偶数行返回 {@code true} 79 | */ 80 | public static boolean isOdd(int rows) { 81 | return (rows & 1) == 1; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/style/BorderStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity.style; 18 | 19 | /** 20 | * Border style 21 | * 22 | * @author guanquan.wang on 2018-02-06 08:55 23 | */ 24 | public enum BorderStyle { 25 | NONE("none"), 26 | THIN("thin"), 27 | MEDIUM("medium"), 28 | DASHED("dashed"), 29 | DOTTED("dotted"), 30 | THICK("thick"), 31 | DOUBLE("double"), 32 | HAIR("hair"), 33 | MEDIUM_DASHED("mediumDashed"), 34 | DASH_DOT("dashDot"), 35 | MEDIUM_DASH_DOT("mediumDashDot"), 36 | DASH_DOT_DOT("dashDotDot"), 37 | MEDIUM_DASH_DOT_DOT("mediumDashDotDot"), 38 | SLANTED_DASH_DOT("slantDashDot"); 39 | 40 | private final String name; 41 | 42 | BorderStyle(String name) { 43 | this.name = name; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public static BorderStyle getByName(String name) { 51 | BorderStyle[] borderStyles = values(); 52 | for (BorderStyle borderStyle : borderStyles) { 53 | if (borderStyle.name.equalsIgnoreCase(name)) { 54 | return borderStyle; 55 | } 56 | } 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/style/BuildInColor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.entity.style; 19 | 20 | import java.awt.Color; 21 | 22 | /** 23 | * OpenXML build in color 24 | * 25 | * @author guanquan.wang at 2023-01-18 16:51 26 | */ 27 | public class BuildInColor extends Color { 28 | // OpenXML color index 29 | private final int indexed; 30 | 31 | public BuildInColor(int indexed) { 32 | // Approximate processing, when indexed greater than 64 means automatic 33 | super(indexed >= 0 && indexed < 64 ? ColorIndex.indexedColors[indexed] : 0); 34 | this.indexed = indexed; 35 | } 36 | 37 | public int getIndexed() { 38 | return indexed; 39 | } 40 | 41 | // @Override 42 | // public int hashCode() { 43 | // return indexed; 44 | // } 45 | // 46 | // @Override 47 | // public boolean equals(Object o) { 48 | // return o instanceof BuildInColor && ((BuildInColor) o).indexed == indexed; 49 | // } 50 | 51 | @Override 52 | public String toString() { 53 | return "Color indexed=\"" + indexed + "\"" + " [r=" + getRed() + ",g=" + getGreen() + ",b=" + getBlue() + "]"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/style/Charset.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity.style; 18 | 19 | /** 20 | * 字符集 21 | * 22 | * @author guanquan.wang at 2018-02-08 17:05 23 | */ 24 | public class Charset { 25 | /** 26 | * 0 标准 Windows 字符 (ANSI) 27 | */ 28 | public static final int ANSI = 0x00; 29 | /** 30 | * 1 默认字符集 31 | * 不是真正的字符集;它是一个类似于NULL的常量,意思是“显示可用字符集中的字符” 32 | */ 33 | public static final int DEFAULT = 0x01; 34 | /** 35 | * 2 符号字符集 36 | */ 37 | public static final int SYMBOL = 0x02; 38 | /** 39 | * 128 日文字符集 40 | */ 41 | public static final int SHIFTJIS = 0x80; 42 | /** 43 | * 129 朝鲜语字符集(韩国、朝鲜) 44 | */ 45 | public static final int HANGUL = 0x81; 46 | /** 47 | * 130 朝鲜语字符集(Johab) 48 | */ 49 | public static final int JOHAB = 0x82; 50 | /** 51 | * 134 简体中文字符集 52 | */ 53 | public static final int GB2312 = 0x86; 54 | /** 55 | * 136 繁体中文字符集 56 | */ 57 | public static final int CHINESEBIG5 = 0x88; 58 | /** 59 | * 161 希腊字符集 60 | */ 61 | public static final int GREEK = 0xA1; 62 | /** 63 | * 162 土耳其字符集 64 | */ 65 | public static final int TURKISH = 0xA2; 66 | /** 67 | * 177 希伯来语字符集 68 | */ 69 | public static final int HEBREW = 0xB1; 70 | /** 71 | * 178 阿拉伯语字符集 72 | */ 73 | public static final int ARABIC = 0xB2; 74 | /** 75 | * 186 印欧语系中的)波罗的语族 76 | */ 77 | public static final int BALTIC = 0xBA; 78 | /** 79 | * 204 西里尔文 用于俄语、保加利亚语及其他一些中欧语言 80 | */ 81 | public static final int RUSSIAN = 0xCC; 82 | /** 83 | * 222 泰国字符集 84 | */ 85 | public static final int THAI = 0xDE; 86 | /** 87 | * 238 拉丁语II(中欧) 88 | */ 89 | public static final int EE = 0xEE; 90 | /** 91 | * 255 通常由 Microsoft MS-DOS 应用程序显示的扩展字符 92 | */ 93 | public static final int OEM = 0xFF; 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/style/Horizontals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity.style; 18 | 19 | /** 20 | * 水平对齐,在样式中位于第{@code 1-3}位 21 | * 22 | * @author guanquan.wang at 2018-02-11 15:02 23 | */ 24 | public class Horizontals { 25 | // General Horizontal Alignment( Text data is left-aligned. Numbers 26 | // , dates, and times are right-aligned.Boolean types are centered) 27 | public static final int GENERAL = 0 28 | , LEFT = 1 << Styles.INDEX_HORIZONTAL // Left Horizontal Alignment 29 | , RIGHT = 2 << Styles.INDEX_HORIZONTAL // Right Horizontal Alignment 30 | , CENTER = 3 << Styles.INDEX_HORIZONTAL // Centered Horizontal Alignment 31 | , CENTER_CONTINUOUS = 4 << Styles.INDEX_HORIZONTAL // (Center Continuous Horizontal Alignment 32 | , FILL = 5 << Styles.INDEX_HORIZONTAL // Fill 33 | , JUSTIFY = 6 << Styles.INDEX_HORIZONTAL // Justify 34 | , DISTRIBUTED = 7 << Styles.INDEX_HORIZONTAL // Distributed Horizontal Alignment 35 | ; 36 | 37 | public static final String[] _names = { 38 | "general" 39 | ,"left" 40 | ,"right" 41 | ,"center" 42 | ,"centerContinuous" 43 | ,"fill" 44 | ,"justify" 45 | ,"distributed" 46 | }; 47 | 48 | public static String of(int n) { 49 | return _names[n >> Styles.INDEX_HORIZONTAL]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/style/PatternType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity.style; 18 | 19 | /** 20 | * 2.4.53 ST_enmPattern 21 | * PatternType 22 | * 23 | * @author guanquan.wang at 2018-02-06 08:55 24 | */ 25 | public enum PatternType { 26 | none, 27 | solid, 28 | mediumGray, 29 | darkGray, 30 | lightGray, 31 | darkHorizontal, 32 | darkVertical, 33 | darkDown, 34 | darkUp, 35 | darkGrid, 36 | darkTrellis, 37 | lightHorizontal, 38 | lightVertical, 39 | lightDown, 40 | lightUp, 41 | lightGrid, 42 | lightTrellis, 43 | gray125, 44 | gray0625 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/entity/style/Verticals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity.style; 18 | 19 | /** 20 | * 垂直对齐,在样式中位于第{@code 4,5}位 21 | * 22 | * @author guanquan.wang at 2018-02-11 14:59 23 | */ 24 | public class Verticals { 25 | public static final int CENTER = 0 // Align Center 26 | , BOTTOM = 1 << Styles.INDEX_VERTICAL // Align Bottom 27 | , TOP = 2 << Styles.INDEX_VERTICAL // Align Top 28 | , BOTH = 3 << Styles.INDEX_VERTICAL // Vertical Justification 29 | ; 30 | 31 | public static final String[] _names = {"center", "bottom", "top", "both"}; 32 | 33 | public static String of(int n) { 34 | return _names[n >> Styles.INDEX_VERTICAL]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/manager/ExcelType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.manager; 18 | 19 | /** 20 | * Type of excel. Biff8 or XLSX(Office open xml) 21 | * 22 | * @author guanquan.wang at 2019-01-24 10:12 23 | */ 24 | public enum ExcelType { 25 | /** 26 | * BIFF8 only 27 | * Excel 8.0 Excel 97 28 | * Excel 9.0 Excel 2000 29 | * Excel 10.0 Excel XP 30 | * Excel 11.0 Excel 2003 31 | */ 32 | XLS, 33 | 34 | /** 35 | * Excel 12.0(2007) or later 36 | */ 37 | XLSX, 38 | 39 | /** 40 | * Others 41 | */ 42 | UNKNOWN 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/manager/NS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.manager; 18 | 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Inherited; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | * Namespace 29 | * 30 | * @author guanquan.wang on 2017/9/18. 31 | */ 32 | @Target(ElementType.FIELD) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Inherited 35 | @Documented 36 | public @interface NS { 37 | /** 38 | * The namespace value 39 | * 40 | * @return the value of namespace 41 | */ 42 | String value(); 43 | 44 | /** 45 | * The namespace uri 46 | * 47 | * @return the uri of namespace 48 | */ 49 | String uri() default ""; 50 | 51 | /** 52 | * Is Array, whether the collection class references current namespace 53 | * 54 | * @return true if sub-class inherited current {@link NS} 55 | */ 56 | boolean contentUse() default false; 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/manager/TopNS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.manager; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Inherited; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Top namespace 28 | * 29 | * @author guanquan.wang on 2017/9/21. 30 | */ 31 | @Target(ElementType.TYPE) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Inherited 34 | @Documented 35 | public @interface TopNS { 36 | /** 37 | * Specify the namespace prefix, it will mapping the {@link #uri()} values. 38 | * 39 | * @return prefix key array 40 | */ 41 | String[] prefix(); 42 | 43 | /** 44 | * Setting the namespace uri 45 | * 46 | * @return uri array 47 | */ 48 | String[] uri() default {}; 49 | 50 | /** 51 | * Setting the tag name 52 | * 53 | * @return the tag name 54 | */ 55 | String value(); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/manager/docProps/Tuple2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.manager.docProps; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | * @author guanquan.wang on 2017/9/26. 23 | */ 24 | public final class Tuple2 { 25 | public final V1 v1; 26 | public final V2 v2; 27 | 28 | public static Tuple2 of(V1 v1, V2 v2) { 29 | return new Tuple2<>(v1, v2); 30 | } 31 | 32 | public Tuple2(V1 v1, V2 v2) { 33 | this.v1 = v1; 34 | this.v2 = v2; 35 | } 36 | 37 | public V1 v1() { 38 | return v1; 39 | } 40 | 41 | public V2 v2() { 42 | return v2; 43 | } 44 | 45 | public String stringV1() { 46 | return v1 != null ? v1.toString() : null; 47 | } 48 | 49 | public String stringV2() { 50 | return v2 != null ? v2.toString() : null; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object o) { 55 | if (this == o) return true; 56 | if (!(o instanceof Tuple2)) return false; 57 | 58 | Tuple2 other = (Tuple2) o; 59 | 60 | return Objects.equals(v1, other.v1) && Objects.equals(v2, other.v2); 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return Objects.hashCode(v1) ^ Objects.hashCode(v2); 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "Tuple2 { v1= " + v1 + ", v2=" + v2 + '}'; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/manager/docProps/XmlEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.manager.docProps; 18 | 19 | import org.dom4j.Document; 20 | import org.dom4j.DocumentFactory; 21 | import org.dom4j.Element; 22 | import org.dom4j.Namespace; 23 | import org.ttzero.excel.manager.TopNS; 24 | import org.ttzero.excel.entity.Storable; 25 | import org.ttzero.excel.util.FileUtil; 26 | import org.ttzero.excel.util.StringUtil; 27 | 28 | import java.io.IOException; 29 | import java.nio.file.Path; 30 | import java.util.HashMap; 31 | import java.util.Map; 32 | 33 | /** 34 | * @author guanquan.wang on 2017/9/21. 35 | */ 36 | public abstract class XmlEntity implements Storable { 37 | @Override 38 | public void writeTo(Path path) throws IOException { 39 | TopNS topNs = getClass().getAnnotation(TopNS.class); 40 | if (topNs == null) throw new IOException(getClass() + " top namespace is required."); 41 | String[] prefixs = topNs.prefix(), uris = topNs.uri(); 42 | // Use the factory to create a root element 43 | DocumentFactory factory = DocumentFactory.getInstance(); 44 | Element rootElement = prefixs.length > 0 && StringUtil.isEmpty(prefixs[0]) ? factory.createElement(topNs.value(), uris[0]) : factory.createElement(topNs.value()); 45 | Map namespaceMap = new HashMap<>(prefixs.length); 46 | // Attach namespace 47 | for (int i = 0; i < prefixs.length; i++) { 48 | namespaceMap.put(prefixs[i], Namespace.get(prefixs[i], uris[i])); 49 | rootElement.add(Namespace.get(prefixs[i], uris[i])); 50 | } 51 | 52 | // 转dom树 53 | toDom(rootElement, namespaceMap); 54 | 55 | Document doc = factory.createDocument(rootElement); 56 | FileUtil.writeToDiskNoFormat(doc, path); // write to desk 57 | } 58 | 59 | /** 60 | * 对象转Dom树 61 | * 62 | * @param root 要节点 63 | * @param namespaceMap namespace 64 | */ 65 | abstract void toDom(Element root, Map namespaceMap); 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/processor/ConversionProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2021, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.processor; 18 | 19 | /** 20 | * 输出转换器,将Java数据类型转为Excel输出类型,通常用于将状态值、枚举值转换为文本 21 | * 22 | *
23 |  * new Workbook()
24 |  *   .addSheet(new ListSheet<>(
25 |  *      new Column("审核单号", "billNo"),
26 |  *      new Column("审核状态", "status", n -> AuditStatus.byVal((int)n).desc())
27 |  *   ))
28 |  *   .writeTo(Paths.get("/tmp/"));
29 | * 30 | * @author guanquan.wang on 2021-11-30 19:10 31 | */ 32 | @FunctionalInterface 33 | public interface ConversionProcessor { 34 | /** 35 | * 输出转换器,导出Excel时将数据转换后输出 36 | * 37 | * @param v 原始值 38 | * @return 转换后的值 39 | */ 40 | Object conversion(Object v); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/processor/Converter.java: -------------------------------------------------------------------------------- 1 | package org.ttzero.excel.processor; 2 | 3 | import org.ttzero.excel.reader.Cell; 4 | import org.ttzero.excel.reader.Row; 5 | 6 | /** 7 | * 转换器,包含{@link #conversion}和{@link #reversion}方法,前者用于输出时将Java数据转为Excel数据, 8 | * 后者正好相反输入时将Excel数据转为Java数据 9 | * 10 | * @author guanquan.wang on 2023-11-14 11:49 11 | */ 12 | public interface Converter extends ConversionProcessor { 13 | /** 14 | * 输入转换器,读取Excel时将单元格的值转为指定类型{@code T} 15 | * 16 | * @param row 当前行{@link Row} 17 | * @param cell 当前单元格{@link Cell} 18 | * @param destClazz 转换后的类型 19 | * @return 转换后的值 20 | */ 21 | T reversion(Row row, Cell cell, Class destClazz); 22 | 23 | /** 24 | * 无类型转换,默认 25 | */ 26 | final class None implements Converter { 27 | 28 | @Override 29 | public Object reversion(Row row, Cell cell, Class destClazz) { 30 | return row.getString(cell); 31 | } 32 | 33 | @Override 34 | public Object conversion(Object v) { 35 | return v; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/processor/ParamProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.processor; 18 | 19 | import java.sql.PreparedStatement; 20 | import java.sql.SQLException; 21 | 22 | /** 23 | * Setting the {@link PreparedStatement} parameters 24 | * 25 | * @author guanquan.wang on 2017/9/13. 26 | */ 27 | @FunctionalInterface 28 | public interface ParamProcessor { 29 | /** 30 | * Setting the {@link PreparedStatement} parameters 31 | * 32 | * @param ps the {@link PreparedStatement} 33 | * @throws SQLException if SQL error occur 34 | */ 35 | void build(PreparedStatement ps) throws SQLException; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/processor/StyleProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.processor; 18 | 19 | import org.ttzero.excel.entity.style.Styles; 20 | 21 | 22 | /** 23 | * 动态样式处理器,根据行数据动态修改样式,可以非常简单的实现高亮效果, 24 | * 对于预警类型的导出尤为实用。 25 | * 26 | *

处理器有3个重要的参数:

27 | *
    28 | *
  1. o: 单元格的值,作用于行级时o为一个Bean实体
  2. 29 | *
  3. style: 当前单元格样式值
  4. 30 | *
  5. sst: 全局的样式对象{@link Styles}
  6. 31 | *
32 | * 33 | *

{@code StyleProcessor}可作用于行级或者单元格,放在工作表上可修改整行样式, 34 | * 放在单个{@code Column}上作用于单个单元格,

35 | * 36 | * @author guanquan.wang on 2017/10/13. 37 | */ 38 | @FunctionalInterface 39 | public interface StyleProcessor { 40 | /** 41 | * 动态样式处理,修改样式请使用{@code Styles.modifyXX}方法 42 | * 43 | *
44 |      * StyleProcessor sp = (o, style, sst)
45 |      *     // 库存小于100时高亮显示 - 填充黄色
46 |      *     -> o < 100 ? style |= sst.modifyFill(style, new Fill(Color.yellow)) : style;
47 | * 48 | * @param o 单元格的值 49 | * @param style 当前单元格样式值 50 | * @param sst 全局的样式对象{@link Styles} 51 | * @return 新的样式值 52 | */ 53 | int build(T o, int style, Styles sst); 54 | 55 | /** 56 | * 无动态样式,默认 57 | */ 58 | final class None implements StyleProcessor { 59 | 60 | @Override 61 | public final int build(Object o, int style, Styles sst) { 62 | return style; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/Cache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.reader; 18 | 19 | /** 20 | * @author guanquan.wang at 2019-06-04 16:07 21 | */ 22 | public interface Cache extends Iterable> { 23 | 24 | /** 25 | * Returns the value to which the specified key is mapped, 26 | * or {@code null} if this cache contains no mapping for the key. 27 | * 28 | * @param k the key whose associated value is to be returned 29 | * @return the value to which the specified key is mapped, or 30 | * {@code null} if this cache contains no mapping for the key 31 | */ 32 | V get(K k); 33 | 34 | /** 35 | * Associates the specified value with the specified key in this cache. 36 | * If the cache previously contained a mapping for 37 | * the key, the old value is replaced by the specified value. 38 | * 39 | * @param k key with which the specified value is to be associated 40 | * the key must not be null 41 | * @param v value to be associated with the specified key 42 | */ 43 | void put(K k, V v); 44 | 45 | /** 46 | * Removes the mapping for a key from this cache if it is present 47 | * (optional operation). More formally, if this cache contains a mapping 48 | * from key k to value v, that mapping 49 | * is removed. 50 | * 51 | * @param k key whose mapping is to be removed from the cache 52 | * @return the previous value associated with key, or 53 | * null if there was no mapping for key. 54 | */ 55 | V remove(K k); 56 | 57 | /** 58 | * Removes all the mappings from this cache (optional operation). 59 | * The cache will be empty after this call returns. 60 | */ 61 | void clear(); 62 | 63 | /** 64 | * Returns the number of key-value mappings in this cache. 65 | * 66 | * @return the number of key-value mappings in this cache. 67 | */ 68 | int size(); 69 | 70 | /** 71 | * A map entry (key-value pair) 72 | */ 73 | interface Entry { 74 | /** 75 | * Returns the key corresponding to this entry. 76 | * 77 | * @return the key corresponding to this entry 78 | */ 79 | K getKey(); 80 | 81 | /** 82 | * Returns the value corresponding to this entry. If the mapping 83 | * has been removed from the backing cache (by the iterator's 84 | * remove operation), the results of this call are undefined. 85 | * 86 | * @return the value corresponding to this entry 87 | */ 88 | V getValue(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/CalcSheet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.reader; 19 | 20 | /** 21 | * 支持解析公式的工作表,可以通过{@link #asCalcSheet}将普通工作表转为{@code CalcSheet} 22 | * 23 | * @author guanquan.wang at 2020-01-11 11:36 24 | * @deprecated 使用 {@link FullSheet}代替,{@code FullSheet}包含{@code CalcSheet}所有功能 25 | */ 26 | @Deprecated 27 | public interface CalcSheet extends Sheet { } 28 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/CellType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.reader; 18 | 19 | /** 20 | * 单元格数据类型 21 | * 22 | * @author guanquan.wang at 2019-06-06 21:17 23 | */ 24 | public enum CellType { 25 | /* 26 | String 27 | */ 28 | STRING 29 | /* 30 | int, short, character 31 | */ 32 | , INTEGER 33 | /* 34 | long 35 | */ 36 | , LONG 37 | /* 38 | float, double 39 | */ 40 | , DOUBLE 41 | /* 42 | decimal 43 | */ 44 | , DECIMAL 45 | /* 46 | boolean 47 | */ 48 | , BOOLEAN 49 | /* 50 | date, time or date-time 51 | */ 52 | , DATE 53 | /* 54 | Null 55 | */ 56 | , BLANK 57 | /* 58 | UNALLOCATED 59 | */ 60 | , UNALLOCATED 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/Col.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.reader; 19 | 20 | 21 | /** 22 | * 列属性 23 | * 24 | * @author guanquan.wang at 2023-12-07 14:08 25 | */ 26 | public class Col { 27 | /** 28 | * 列索引范围(one base) 29 | */ 30 | public int min, max; 31 | /** 32 | * 列宽 33 | */ 34 | public double width; 35 | /** 36 | * 是否隐藏列 37 | */ 38 | public boolean hidden; 39 | /** 40 | * 样式索引 41 | */ 42 | public int styleIndex; 43 | 44 | public Col() { } 45 | public Col(int min, int max, double width) { 46 | this.min = min; 47 | this.max = max; 48 | this.width = width; 49 | } 50 | 51 | public Col(int min, int max, double width, boolean hidden) { 52 | this(min, max, width); 53 | this.hidden = hidden; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "min:" + min + ",max:" + max + ",width:" + width + ",hidden:" + hidden + (styleIndex > 0 ? ",xf:" + styleIndex : ""); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/Drawings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2021, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.reader; 19 | 20 | import org.ttzero.excel.drawing.Effect; 21 | import org.ttzero.excel.util.StringUtil; 22 | 23 | import java.nio.file.Path; 24 | import java.util.List; 25 | import java.util.stream.Collectors; 26 | 27 | /** 28 | * 读取Excel图片 29 | * 30 | * @author guanquan.wang at 2021-04-24 19:53 31 | * @see XMLDrawings 32 | */ 33 | public interface Drawings { 34 | /** 35 | * 列出所有工作表包含的图片 36 | * 37 | * @return 如果存在图片时返回 {@link Picture}数组, 不存在图片返回{@code null}. 38 | */ 39 | List listPictures(); 40 | 41 | /** 42 | * 列出指定工作表包含的图片 43 | * 44 | * @param sheet 指定工作表 45 | * @return 如果存在图片时返回 {@link Picture}数组, 不存在图片返回{@code null}. 46 | */ 47 | default List listPictures(final Sheet sheet) { 48 | List pictures = listPictures(); 49 | return pictures == null ? null : 50 | pictures.stream().filter(p -> p.getSheet().getId() == sheet.getId()).collect(Collectors.toList()); 51 | } 52 | 53 | class Picture { 54 | /** 55 | * 图片所在的工作表 {@link Sheet} 56 | */ 57 | public Sheet sheet; 58 | /** 59 | * 图片在工作表中的位置,记录图片左上角和右下角的行列坐标 60 | */ 61 | public Dimension dimension; 62 | /** 63 | * 图片的临时路径 64 | */ 65 | public Path localPath; 66 | /** 67 | * 如果是网络图片,则此属性保留网络图片的原始链接 68 | */ 69 | public String srcUrl; 70 | /** 71 | * 是否为背景图片,水印图片 72 | */ 73 | public boolean background; 74 | /** 75 | * 0: Move and size with cells 76 | * 1: Move but don't size with cells 77 | * 2: Don't move or size with cells 78 | */ 79 | public int property; 80 | /** 81 | * Revolve -360 ~ 360 82 | */ 83 | public int revolve; 84 | /** 85 | * Padding top | right | bottom | left 86 | */ 87 | public short[] padding; 88 | /** 89 | * Picture effects 90 | */ 91 | public Effect effect; 92 | 93 | public Sheet getSheet() { 94 | return sheet; 95 | } 96 | 97 | public Dimension getDimension() { 98 | return dimension; 99 | } 100 | 101 | public Path getLocalPath() { 102 | return localPath; 103 | } 104 | 105 | public String getSrcUrl() { 106 | return srcUrl; 107 | } 108 | 109 | public boolean isBackground() { 110 | return background; 111 | } 112 | 113 | public int getProperty() { 114 | return property; 115 | } 116 | 117 | public int getRevolve() { 118 | return revolve; 119 | } 120 | 121 | public short[] getPadding() { 122 | return padding; 123 | } 124 | 125 | public Effect getEffect() { 126 | return effect; 127 | } 128 | 129 | @Override 130 | public String toString() { 131 | return background ? "Background picture [" + localPath + "] in worksheet " + sheet.getName() + (StringUtil.isNotEmpty(srcUrl) ? " from internet url " + srcUrl : "") 132 | : "Picture [" + localPath + "] in worksheet " + sheet.getName() + " at " + dimension + (StringUtil.isNotEmpty(srcUrl) ? " from internet url " + srcUrl : ""); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/ExcelReadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.reader; 18 | 19 | /** 20 | * @author guanquan.wang at 2018-09-27 14:48 21 | */ 22 | public class ExcelReadException extends RuntimeException { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | public ExcelReadException(String message) { 27 | super(message); 28 | } 29 | 30 | public ExcelReadException(String message, Throwable cause) { 31 | super(message, cause); 32 | } 33 | 34 | public ExcelReadException(Throwable cause) { 35 | super(cause); 36 | } 37 | 38 | protected ExcelReadException(String message, Throwable cause, 39 | boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/FullSheet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.reader; 19 | 20 | import org.ttzero.excel.entity.Comment; 21 | import org.ttzero.excel.entity.Panes; 22 | 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * 全属性工作表,与普通工作表不同除了值以外{@code FullSheet}将会额外读取行高和列宽以及单元格公式, 28 | * 全属性工作表虽然继承{@code MergeSheet}但并不会主动在合并单元格复制值,如果需要复制值需要明确调用{@link #copyOnMerged}方法 29 | * 30 | * @author guanquan.wang at 2023-12-02 15:31 31 | */ 32 | public interface FullSheet extends MergeSheet, CalcSheet { 33 | /** 34 | * 复制合并单元格的值 35 | * 36 | *

通常合并单元格的值保存在左上角第一个单元格中其余单元格的值为{@code null},如果要读取这类合并单元的值就需要特殊处理, 37 | * 使用{@code copyOnMerged}方法就可以直接获取合并范围内的所有单元格的值,每个值均为首个单元格的值。 38 | * 本方法会有一定的性能损耗,数据量少时可忽略这种损耗

39 | *
 40 |      * |---------|     |---------|     |---------|
 41 |      * |         |     |  1 |    |     |  1 |  1 |
 42 |      * |    1    |  => |----|----|  => |----|----|
 43 |      * |         |     |    |    |     |  1 |  1 |
 44 |      * |---------|     |---------|     |---------|
 45 |      * Merged(A1:B2)     Default           Copy
 46 |      *                  Value in A1
 47 |      *                  others are
 48 |      *                  `null`
 49 |      * 
50 | * 51 | * @return 本工作表 52 | */ 53 | FullSheet copyOnMerged(); 54 | /** 55 | * 获取冻结信息 56 | * 57 | * @return 冻结的行列信息,无冻结时返回{@code null} 58 | */ 59 | Panes getFreezePanes(); 60 | 61 | /** 62 | * 获取列宽相Cols属性 63 | * 64 | * @return Cols列表,可以为{@code null} 65 | */ 66 | List getCols(); 67 | 68 | /** 69 | * 获取筛选区域,自动筛选的配置放在工作表最后,所以获取此值耗时较长 70 | * 71 | * @return 范围值,没有筛选时返回{@code null} 72 | */ 73 | Dimension getFilter(); 74 | 75 | /** 76 | * 获取预置列宽,该列宽优先级最低可以被{@link #getCols()}里的列宽覆盖,有效范围以外的列会展示此宽度 77 | * 78 | * @return 预置列宽,{@code -1}表示未知 79 | */ 80 | double getDefaultColWidth(); 81 | /** 82 | * 获取预置行高,暂不知道何种场景下此行高生交 83 | * 84 | * @return 预置行高,{@code -1}表示未知 85 | */ 86 | double getDefaultRowHeight(); 87 | 88 | /** 89 | * 工作表是否显示网络线 90 | * 91 | * @return true: 显示网络线 92 | */ 93 | boolean isShowGridLines(); 94 | 95 | /** 96 | * 获取工作表缩放比例,取值{@code 10-400} 97 | * 98 | * @return 百分比整数化,{@code null}表示未设置 99 | */ 100 | Integer getZoomScale(); 101 | 102 | /** 103 | * 获取批注 104 | * 105 | * @return key: 行列值 {@code col & 0x7FFF | ((long) row) << 16}, value: 批注 106 | */ 107 | Map getComments(); 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/GridFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.reader; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * @author guanquan.wang at 2022-07-04 11:56 24 | */ 25 | public class GridFactory { 26 | private GridFactory() { } 27 | public static Grid create(List mergeCells) { 28 | Dimension dim = mergeCells.get(0); 29 | int fr = dim.firstRow, lr = dim.lastRow; 30 | short fc = dim.firstColumn, lc = dim.lastColumn; 31 | int n = (lr - fr + 1) * (lc - fc + 1); 32 | for (int j = 1, len = mergeCells.size(); j < len; j++) { 33 | dim = mergeCells.get(j); 34 | n += (dim.lastRow - dim.firstRow + 1) * (dim.lastColumn - dim.firstColumn + 1); 35 | if (fr > dim.firstRow) fr = dim.firstRow; 36 | if (lr < dim.lastRow) lr = dim.lastRow; 37 | if (fc > dim.firstColumn) fc = dim.firstColumn; 38 | if (lc < dim.lastColumn) lc = dim.lastColumn; 39 | } 40 | 41 | Dimension range = new Dimension(fr, fc, lr, lc); 42 | int r = lr - fr + 1 43 | , c = lc - fc + 1; 44 | 45 | n = r * c; 46 | 47 | Grid grid = c <= 64 && r < 1 << 15 ? new Grid.FastGrid(range) 48 | : n > 1 << 17 ? new Grid.FractureGrid(range) : new Grid.IndexGrid(range, n); 49 | 50 | for (Dimension d : mergeCells) grid.mark(d); 51 | return grid; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/MergeSheet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.reader; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * 支持复制合并单元格的工作表,可以通过{@link #asMergeSheet}将普通工作表转为{@code MergeSheet} 24 | * 25 | *

通常合并单元格的值保存在左上角第一个单元格中其余单元格的值为{@code null},如果要读取这类合并单元的值就需要特殊处理, 26 | * 如果将工作表转为{@code MergeSheet}就可以直接获取合并范围内的所有单元格的值,每个值均为首个单元格的值。 27 | * 使用{@code MergeSheet}会有一定的性能损耗,数据量少时可忽略这种损耗

28 | *
29 |  * |---------|     |---------|     |---------|
30 |  * |         |     |  1 |    |     |  1 |  1 |
31 |  * |    1    |  => |----|----|  => |----|----|
32 |  * |         |     |    |    |     |  1 |  1 |
33 |  * |---------|     |---------|     |---------|
34 |  * Merged(A1:B2)     Default           Copy
35 |  *                  Value in A1
36 |  *                  others are
37 |  *                  `null`
38 |  * 
39 | * 40 | * @author guanquan.wang at 2022-08-10 11:36 41 | * @deprecated 使用 {@link FullSheet}代替,{@code FullSheet}包含{@code MergeSheet}所有功能 42 | */ 43 | @Deprecated 44 | public interface MergeSheet extends Sheet { 45 | /** 46 | * 获取抽象的合并表格,通过表格快速判断某个坐标是否为合并单元格的一部分 47 | * 48 | * @return merged {@link Grid} 49 | */ 50 | Grid getMergeGrid(); 51 | 52 | /** 53 | * 获取所有合并单元格的合并范围 54 | * 55 | * @return 如果存在合并单元格则返回所有合并单元格的范围,否则返回{@code null} 56 | */ 57 | List getMergeCells(); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/RowSetIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.reader; 18 | 19 | import java.util.Iterator; 20 | import java.util.NoSuchElementException; 21 | import java.util.function.Supplier; 22 | 23 | /** 24 | * 行迭代器 25 | * 26 | * @author guanquan.wang at 2019-04-17 19:03 27 | */ 28 | public class RowSetIterator implements Iterator { 29 | protected final Supplier supplier; 30 | protected Row nextRow = null; 31 | 32 | public RowSetIterator(Supplier supplier) { 33 | this.supplier = supplier; 34 | } 35 | 36 | @Override 37 | public boolean hasNext() { 38 | if (nextRow != null) { 39 | return true; 40 | } else { 41 | nextRow = supplier.get(); 42 | return (nextRow != null); 43 | } 44 | } 45 | 46 | @Override 47 | public Row next() { 48 | if (nextRow != null || hasNext()) { 49 | Row next = nextRow; 50 | nextRow = null; 51 | return next; 52 | } else { 53 | throw new NoSuchElementException(); 54 | } 55 | } 56 | 57 | public static class NonBlankIterator extends RowSetIterator { 58 | 59 | public NonBlankIterator(Supplier supplier) { 60 | super(supplier); 61 | } 62 | 63 | @Override 64 | public boolean hasNext() { 65 | if (nextRow != null) { 66 | return true; 67 | } else { 68 | // Skip blank rows 69 | for (; (nextRow = supplier.get()) != null && nextRow.isBlank(); ) ; 70 | return (nextRow != null); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/TypeCastException.java: -------------------------------------------------------------------------------- 1 | package org.ttzero.excel.reader; 2 | 3 | import static org.ttzero.excel.entity.Sheet.int2Col; 4 | import static org.ttzero.excel.entity.Sheet.toCoordinate; 5 | 6 | /** 7 | * 读取时类型转换异常 8 | * 9 | * @author nasoda on 2024-02-23 10 | */ 11 | public class TypeCastException extends IllegalArgumentException { 12 | 13 | /** 14 | * 行号,从1开始 15 | */ 16 | public final int row; 17 | 18 | /** 19 | * 列号,从1开始,可通过{@link #toColumnLetter()}转为字母 20 | */ 21 | public final int col; 22 | /** 23 | * Excel单元格类型 24 | */ 25 | public final CellType from; 26 | /** 27 | * 目标转换类型 28 | */ 29 | public final Class to; 30 | 31 | public TypeCastException(int row, int col, CellType from, Class to) { 32 | super("Can't cast " + from + "to " + to + " in cell '" + toCoordinate(row, col) + "'"); 33 | this.row = row; 34 | this.col = col; 35 | this.from = from; 36 | this.to = to; 37 | } 38 | 39 | public TypeCastException(int row, int col, CellType from, Class to, String message) { 40 | super(message); 41 | this.row = row; 42 | this.col = col; 43 | this.from = from; 44 | this.to = to; 45 | } 46 | 47 | public TypeCastException(int row, int col, CellType from, Class to, String message, Throwable cause) { 48 | super(message, cause); 49 | this.row = row; 50 | this.col = col; 51 | this.from = from; 52 | this.to = to; 53 | } 54 | 55 | public TypeCastException(int row, int col, CellType from, Class to, Throwable cause) { 56 | super(cause); 57 | this.row = row; 58 | this.col = col; 59 | this.from = from; 60 | this.to = to; 61 | } 62 | 63 | public int getRow() { 64 | return row; 65 | } 66 | 67 | public int getCol() { 68 | return col; 69 | } 70 | 71 | public CellType getFrom() { 72 | return from; 73 | } 74 | 75 | public Class getTo() { 76 | return to; 77 | } 78 | 79 | public String toColumnLetter() { 80 | return new String(int2Col(col)); 81 | } 82 | 83 | /** 84 | * 获取单位格坐标 85 | * 86 | * @return 单元格坐标 eg: {@code A10} 87 | */ 88 | public String getCoordinate() { 89 | return toCoordinate(row, col); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/reader/UncheckedTypeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.reader; 18 | 19 | import java.io.IOException; 20 | import java.io.InvalidObjectException; 21 | import java.io.ObjectInputStream; 22 | import java.util.Objects; 23 | 24 | /** 25 | * @author guanquan.wang at 2018-09-30 11:59 26 | */ 27 | public class UncheckedTypeException extends RuntimeException { 28 | private static final long serialVersionUID = -8134305061645241065L; 29 | 30 | /** 31 | * Constructs an instance of this class. 32 | * 33 | * @param message the detail message, can be null 34 | * @param thr the {@code TypeException} 35 | * @throws NullPointerException if the cause is {@code null} 36 | */ 37 | public UncheckedTypeException(String message, Throwable thr) { 38 | super(message, Objects.requireNonNull(thr)); 39 | } 40 | 41 | /** 42 | * Constructs an instance of this class. 43 | * 44 | * @param message the detail message 45 | * @throws NullPointerException if the cause is {@code null} 46 | */ 47 | public UncheckedTypeException(String message) { 48 | super(message); 49 | } 50 | 51 | /** 52 | * Called to read the object from a stream. 53 | * 54 | * @param s the {@link ObjectInputStream} 55 | * @throws InvalidObjectException 56 | * if the object is invalid or has a cause that is not 57 | * an {@code IOException} 58 | * @throws ClassNotFoundException if class not found 59 | */ 60 | private void readObject(ObjectInputStream s) 61 | throws IOException, ClassNotFoundException { 62 | s.defaultReadObject(); 63 | Throwable cause = super.getCause(); 64 | if (!(cause instanceof IOException)) 65 | throw new InvalidObjectException("Cause must be an UncheckTypeException"); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/util/ExtXMLWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.util; 18 | 19 | import org.dom4j.io.OutputFormat; 20 | import org.dom4j.io.XMLWriter; 21 | 22 | import java.io.IOException; 23 | import java.io.OutputStream; 24 | import java.io.UnsupportedEncodingException; 25 | 26 | /** 27 | * @author guanquan.wang on 2017/10/11. 28 | */ 29 | public class ExtXMLWriter extends XMLWriter { 30 | 31 | public ExtXMLWriter(OutputStream out) throws UnsupportedEncodingException { 32 | super(out); 33 | } 34 | 35 | public ExtXMLWriter(OutputStream out, OutputFormat format) 36 | throws UnsupportedEncodingException { 37 | super(out, format); 38 | } 39 | 40 | /** 41 | *

42 | * This will write the declaration to the given Writer. Assumes XML version 43 | * 1.0 since we don't directly know. 44 | *

45 | * 46 | * @throws IOException DOCUMENT ME! 47 | */ 48 | @Override 49 | protected void writeDeclaration() throws IOException { 50 | OutputFormat format = getOutputFormat(); 51 | String encoding = format.getEncoding(); 52 | 53 | // Only print of declaration is not suppressed 54 | if (!format.isSuppressDeclaration()) { 55 | // Assume 1.0 version 56 | if (encoding.equals("UTF8")) { 57 | writer.write(""); 64 | } else { 65 | writer.write(""); 72 | } 73 | 74 | if (format.isNewLineAfterDeclaration()) { 75 | println(); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/validation/DateValidation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@hotmail.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.validation; 19 | 20 | import org.ttzero.excel.util.DateUtil; 21 | import org.ttzero.excel.util.StringUtil; 22 | 23 | import java.text.ParsePosition; 24 | import java.util.Date; 25 | 26 | /** 27 | * 日期验证,限定起始和结束时间范围 28 | * 29 | * @author guanquan.wang at 2022-08-17 20:05:42 30 | */ 31 | public class DateValidation extends Tuple2Validation { 32 | public DateValidation between(Date from, Date to) { 33 | if (from != null) v1 = DateUtil.toDateValue(from); 34 | if (to != null) v2 = DateUtil.toDateValue(to); 35 | return this; 36 | } 37 | 38 | /** 39 | * @param from time in format "yyyy-MM-dd" 40 | * @param to time in format "yyyy-MM-dd" 41 | * @return DateValidation 42 | */ 43 | public DateValidation between(String from, String to) { 44 | if (StringUtil.isNotEmpty(from)) 45 | v1 = DateUtil.toDateValue(DateUtil.dateFormat.get().parse(from.substring(0, Math.min(from.length(), 10)), new ParsePosition(0))); 46 | if (StringUtil.isNotEmpty(to)) 47 | v2 = DateUtil.toDateValue(DateUtil.dateFormat.get().parse(to.substring(0, Math.min(to.length(), 10)), new ParsePosition(0))); 48 | return this; 49 | } 50 | 51 | @Override 52 | public String getType() { 53 | return "date"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/validation/ListValidation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@hotmail.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.validation; 19 | 20 | import org.ttzero.excel.reader.Dimension; 21 | 22 | import java.util.Arrays; 23 | import java.util.List; 24 | import java.util.stream.Collectors; 25 | 26 | /** 27 | * 序列验证,限定单元格的值只能在序列中选择 28 | * 29 | * @author guanquan.wang at 2022-08-17 20:05:42 30 | */ 31 | public class ListValidation extends Validation { 32 | /** 33 | * 可选的序列值 34 | */ 35 | public List options; 36 | /** 37 | * 引用其它可选序列的坐标 38 | */ 39 | public Dimension referer; 40 | 41 | public ListValidation in(List options) { 42 | this.options = options; 43 | return this; 44 | } 45 | 46 | @SafeVarargs 47 | public final ListValidation in(T... options) { 48 | this.options = Arrays.asList(options); 49 | return this; 50 | } 51 | 52 | public ListValidation in(Dimension referer) { 53 | this.referer = referer; 54 | return this; 55 | } 56 | 57 | public ListValidation in(String otherSheetName, Dimension referer) { 58 | this.otherSheetName = otherSheetName; 59 | this.referer = referer; 60 | return this; 61 | } 62 | 63 | @Override 64 | public String getType() { 65 | return "list"; 66 | } 67 | 68 | @Override 69 | public String validationFormula() { 70 | String val; 71 | if (isExtension()) { 72 | val = "" + otherSheetName + "!" + referer.toReferer() + "" + sqref + ""; 73 | } else if (options != null) { 74 | val = "\"" + options.stream().map(String::valueOf).collect(Collectors.joining(",")) + "\""; 75 | } else if (referer != null) { 76 | val = "" + referer.toReferer() + ""; 77 | } else { 78 | val = "\"\""; 79 | } 80 | return val; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/validation/TextLengthValidation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@hotmail.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.validation; 19 | 20 | /** 21 | * 文本长度验证 22 | * 23 | * @author guanquan.wang at 2022-08-17 20:05:42 24 | */ 25 | public class TextLengthValidation extends Tuple2Validation { 26 | @Override 27 | public String getType() { 28 | return "textLength"; 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/validation/TimeValidation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@hotmail.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.validation; 19 | 20 | import org.ttzero.excel.util.DateUtil; 21 | import org.ttzero.excel.util.StringUtil; 22 | 23 | import java.sql.Time; 24 | import java.util.Date; 25 | 26 | /** 27 | * 时间验证,限定起始和结束时间范围 28 | * 29 | * @author guanquan.wang at 2022-08-17 20:05:42 30 | */ 31 | public class TimeValidation extends Tuple2Validation { 32 | public TimeValidation between(Date from, Date to) { 33 | if (from != null) v1 = DateUtil.toTimeValue(from); 34 | if (to != null) v2 = DateUtil.toTimeValue(to); 35 | return this; 36 | } 37 | 38 | public TimeValidation between(Time from, Time to) { 39 | if (from != null) v1 = DateUtil.toTimeValue(from); 40 | if (to != null) v2 = DateUtil.toTimeValue(to); 41 | return this; 42 | } 43 | 44 | /** 45 | * @param from time in format "hh:mm:ss" 46 | * @param to time in format "hh:mm:ss" 47 | * @return DateValidation 48 | */ 49 | public TimeValidation between(String from, String to) { 50 | if (StringUtil.isNotEmpty(from)) v1 = DateUtil.toTimeValue(Time.valueOf(from)); 51 | if (StringUtil.isNotEmpty(to)) v2 = DateUtil.toTimeValue(Time.valueOf(to)); 52 | return this; 53 | } 54 | 55 | @Override 56 | public String getType() { 57 | return "time"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/validation/Tuple2Validation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@hotmail.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.validation; 19 | 20 | 21 | import org.ttzero.excel.reader.Dimension; 22 | 23 | /** 24 | * 范围验证,限定起始和结束值范围 25 | * 26 | * @see DateValidation 27 | * @see TimeValidation 28 | * @see TextLengthValidation 29 | * @see WholeValidation 30 | * @author guanquan.wang at 2022-08-17 20:05:42 31 | */ 32 | public abstract class Tuple2Validation extends Validation { 33 | public V1 v1; 34 | public V2 v2; 35 | 36 | public Tuple2Validation equal(V1 v1) { 37 | this.operator = Operator.equal; 38 | this.v1 = v1; 39 | return this; 40 | } 41 | 42 | public Tuple2Validation nowEqual(V1 v1) { 43 | this.operator = Operator.notEqual; 44 | this.v1 = v1; 45 | return this; 46 | } 47 | 48 | public Tuple2Validation greaterThan(V1 v1) { 49 | this.operator = Operator.greaterThan; 50 | this.v1 = v1; 51 | return this; 52 | } 53 | 54 | public Tuple2Validation greaterThanOrEqual(V1 v1) { 55 | this.operator = Operator.greaterThanOrEqual; 56 | this.v1 = v1; 57 | return this; 58 | } 59 | 60 | public Tuple2Validation lessThan(V2 v2) { 61 | this.operator = Operator.lessThan; 62 | this.v2 = v2; 63 | return this; 64 | } 65 | 66 | public Tuple2Validation lessThanOrEqual(V2 v2) { 67 | this.operator = Operator.lessThanOrEqual; 68 | this.v2 = v2; 69 | return this; 70 | } 71 | 72 | public Tuple2Validation between(V1 v1, V2 v2) { 73 | this.operator = Operator.between; 74 | this.v1 = v1; 75 | this.v2 = v2; 76 | return this; 77 | } 78 | 79 | public Tuple2Validation notBetween(V1 v1, V2 v2) { 80 | this.operator = Operator.notBetween; 81 | this.v1 = v1; 82 | this.v2 = v2; 83 | return this; 84 | } 85 | 86 | @Override 87 | public String validationFormula() { 88 | boolean ext = isExtension() 89 | , b1 = v1 != null && v1 instanceof Dimension 90 | , b2 = v2 != null && v2 instanceof Dimension; 91 | if (ext && !(b1 || b2)) 92 | throw new IllegalArgumentException("Extension validation must setting dimension values"); 93 | String v; 94 | if (operator == null) operator = Operator.between; 95 | switch (operator) { 96 | case equal: 97 | case notEqual: 98 | case greaterThan: 99 | case greaterThanOrEqual: v = ext && b1 ? "" + otherSheetName + ":" + ((Dimension) v1).toReferer() + " " : "" + v1 + ""; break; 100 | case lessThan: 101 | case lessThanOrEqual: v = ext && b2 ? "" + otherSheetName + ":" + ((Dimension) v2).toReferer() + " " : "" + v2 + ""; break; 102 | default: v = ext ? "" + otherSheetName + ":" + ((Dimension) v1).toReferer() + " " + otherSheetName + ":" + ((Dimension) v2).toReferer() + " ": "" + v1 + "" + v2 + ""; break; 103 | } 104 | if (ext) v += ""+ sqref +""; 105 | return v; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/validation/Validation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@hotmail.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.validation; 19 | 20 | import org.ttzero.excel.reader.Dimension; 21 | import org.ttzero.excel.util.StringUtil; 22 | 23 | /** 24 | * 数据验证 25 | * 26 | * @author guanquan.wang at 2022-08-17 20:05:42 27 | */ 28 | public abstract class Validation { 29 | /** 30 | * 允许为空 31 | */ 32 | public boolean allowBlank = true; 33 | /** 34 | * 显示下拉框 35 | */ 36 | public boolean showInputMessage = true; 37 | /** 38 | * 显示提示信息 39 | */ 40 | public boolean showErrorMessage = true; 41 | /** 42 | * 作用范围 43 | */ 44 | public Dimension sqref; 45 | /** 46 | * 操作符,不指定时默认between 47 | */ 48 | public Operator operator; 49 | /** 50 | * 引用工作表名 51 | */ 52 | public String otherSheetName; 53 | /** 54 | * 数据校验类型 55 | * 56 | * @return 数据验类型,包含 {@code list}序列, {@code whole}整数, {@code date}日期, {@code time}时间, {@code textLength}文本长度 57 | */ 58 | public abstract String getType(); 59 | 60 | /** 61 | * 校验内容 62 | * 63 | * @return 验证对象转xml文本 64 | */ 65 | public abstract String validationFormula(); 66 | 67 | /** 68 | * 是否为扩展节点 69 | * 70 | * @return {@code true} 扩展节点 71 | */ 72 | public boolean isExtension() { 73 | return StringUtil.isNotEmpty(otherSheetName); 74 | } 75 | 76 | public Validation dimension(Dimension sqref) { 77 | this.sqref = sqref; 78 | return this; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "<" + (isExtension() ? "x14:" : "" ) + "dataValidation type=\"" + getType() 84 | + (operator == null || operator == Operator.between ? "" : "\" operator=\"" + operator) 85 | + "\" allowBlank=\"" + (allowBlank ? 1 : 0) 86 | + "\" showInputMessage=\"" + (showInputMessage ? 1 : 0) 87 | + "\" showErrorMessage=\"" + (showErrorMessage ? 1 : 0) 88 | + (isExtension() ? "\">" : "\" sqref=\"" + sqref + "\">") 89 | + validationFormula() 90 | + ""; 91 | } 92 | 93 | public enum Operator { 94 | between, notBetween, equal, notEqual, greaterThan, lessThan, greaterThanOrEqual, lessThanOrEqual 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/org/ttzero/excel/validation/WholeValidation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@hotmail.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.validation; 19 | 20 | /** 21 | * 整数验证 22 | * 23 | * @author guanquan.wang at 2022-08-17 20:05:42 24 | */ 25 | public class WholeValidation extends Tuple2Validation { 26 | @Override 27 | public String getType() { 28 | return "whole"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/resources/numFmt: -------------------------------------------------------------------------------- 1 | 0 = 'General' 2 | 1 = '0' 3 | 2 = '0.00' 4 | 3 = '#,##0' 5 | 4 = '#,##0.00' 6 | 5 = '$#,##0_)($#,##0)' 7 | 6 = '$#,##0_)[Red]($#,##0)' 8 | 7 = '$#,##0.00_)($#,##0.00)' 9 | 8 = '$#,##0.00_)[Red]($#,##0.00)' 10 | 9 = '0%' 11 | 10 = '0.00%' 12 | 11 = '0.00E+00' 13 | 12 = '# ?/?' 14 | 13 = '# ??/??' 15 | 14 = 'mm-dd-yy' 16 | 15 = 'd-mmm-yy' 17 | 16 = 'd-mmm' 18 | 17 = 'mmm-yy' 19 | 18 = 'h:mm AM/PM' 20 | 19 = 'h:mm:ss AM/PM' 21 | 20 = 'h:mm' 22 | 21 = 'h:mm:ss' 23 | 22 = 'm/d/yy h:mm' 24 | 25 | 37 = '#,##0 (#,##0)' 26 | 38 = '#,##0 [Red](#,##0)' 27 | 39 = '#,##0.00(#,##0.00)' 28 | 40 = '#,##0.00[Red](#,##0.00)' 29 | 30 | 45 = 'mm:ss' 31 | 46 = '[h]:mm:ss' 32 | 47 = 'mmss.0' 33 | 48 = '##0.0E+0' 34 | 49 = '@' 35 | 36 | [zh-CN] 37 | 27 = 'yyyy"年"m"月"' 38 | 28 = 'm"月"d"日"' 39 | 29 = 'm"月"d"日"' 40 | 30 = 'm-d-yy' 41 | 31 = 'yyyy"年"m"月"d"日"' 42 | 32 = 'h"时"mm"分"' 43 | 33 = 'h"时"mm"分"ss"秒"' 44 | 34 = '上午/下午h"时"mm"分"' 45 | 35 = '上午/下午h"时"mm"分"ss"秒"' 46 | 36 = 'yyyy"年"m"月"' 47 | 48 | 50 = 'yyyy"年"m"月"' 49 | 51 = 'm"月"d"日"' 50 | 52 = 'yyyy"年"m"月"' 51 | 53 = 'm"月"d"日"' 52 | 54 = 'm"月"d"日"' 53 | 55 = '上午/下午h"时"mm"分"' 54 | 56 = '上午/下午h"时"mm"分"ss"秒"' 55 | 57 = 'yyyy"年"m"月"' 56 | 58 = 'm"月"d"日"' -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/Print.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel; 18 | 19 | public final class Print 20 | { 21 | public static void print(boolean b) { 22 | System.out.print(b); 23 | } 24 | public static void print(char c) { 25 | System.out.print(c); 26 | } 27 | public static void print(int i) { 28 | System.out.print(i); 29 | } 30 | public static void print(long l) { 31 | System.out.print(l); 32 | } 33 | public static void print(float f) { 34 | System.out.print(f); 35 | } 36 | public static void print(double d) { 37 | System.out.print(d); 38 | } 39 | public static void print(char[] s) { 40 | System.out.print(s); 41 | } 42 | public static void print(String s) { 43 | System.out.print(s); 44 | } 45 | public static void print(Object o) { 46 | System.out.print(o); 47 | } 48 | public static void println() { 49 | System.out.println(); 50 | } 51 | public static void println(boolean b) { 52 | System.out.println(b); 53 | } 54 | public static void println(char c) { 55 | System.out.println(c); 56 | } 57 | public static void println(int i) { 58 | System.out.println(i); 59 | } 60 | public static void println(long l) { 61 | System.out.println(l); 62 | } 63 | public static void println(float f) { 64 | System.out.println(f); 65 | } 66 | public static void println(double d) { 67 | System.out.println(d); 68 | } 69 | public static void println(char[] s) { 70 | System.out.println(s); 71 | } 72 | public static void println(String s) { 73 | System.out.println(s); 74 | } 75 | public static void println(Object o) { 76 | System.out.println(o); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/annotation/CellData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.annotation; 19 | 20 | import java.math.BigDecimal; 21 | 22 | /** 23 | * @author guanquan.wang at 2022-05-03 18:38 24 | */ 25 | public class CellData { 26 | 27 | private BigDecimal numberValue; 28 | 29 | private String stringValue; 30 | 31 | private Boolean booleanValue; 32 | 33 | /** 34 | * The resulting converted data. 35 | */ 36 | private T data; 37 | 38 | public CellData(CellData other) { 39 | this.numberValue = other.numberValue; 40 | this.stringValue = other.stringValue; 41 | this.booleanValue = other.booleanValue; 42 | this.data = other.data; 43 | } 44 | 45 | public CellData() {} 46 | 47 | public CellData(T data) { 48 | this.data = data; 49 | } 50 | 51 | public BigDecimal getNumberValue() { 52 | return numberValue; 53 | } 54 | 55 | public void setNumberValue(BigDecimal numberValue) { 56 | this.numberValue = numberValue; 57 | } 58 | 59 | public String getStringValue() { 60 | return stringValue; 61 | } 62 | 63 | public void setStringValue(String stringValue) { 64 | this.stringValue = stringValue; 65 | } 66 | 67 | public Boolean getBooleanValue() { 68 | return booleanValue; 69 | } 70 | 71 | public void setBooleanValue(Boolean booleanValue) { 72 | this.booleanValue = booleanValue; 73 | } 74 | 75 | public T getData() { 76 | return data; 77 | } 78 | 79 | public void setData(T data) { 80 | this.data = data; 81 | } 82 | 83 | 84 | @Override 85 | public String toString() { 86 | if (stringValue != null) { 87 | return stringValue; 88 | } 89 | if (numberValue != null) { 90 | return numberValue.toString(); 91 | } 92 | if (booleanValue != null) { 93 | return booleanValue.toString(); 94 | } 95 | return data.toString(); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/annotation/Converter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.annotation; 19 | 20 | /** 21 | * @author guanquan.wang at 2022-05-03 18:36 22 | */ 23 | public interface Converter { 24 | 25 | T convertToJavaData(CellData cellData) throws Exception; 26 | 27 | CellData convertToExcelData(T value) throws Exception; 28 | 29 | final class AutoConverter implements Converter { 30 | 31 | @Override 32 | public Object convertToJavaData(CellData cellData) { 33 | return null; 34 | } 35 | 36 | @Override 37 | public CellData convertToExcelData(Object value) { 38 | return null; 39 | } 40 | } 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/bloom/BloomFilterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.bloom; 18 | 19 | import org.ttzero.excel.hash.StringBloomFilter; 20 | import org.junit.Test; 21 | 22 | import static org.junit.Assert.assertTrue; 23 | 24 | /** 25 | * @author guanquan.wang at 2019-05-06 16:44 26 | */ 27 | public class BloomFilterTest { 28 | @Test public void testStringFilter() { 29 | StringBloomFilter filter = StringBloomFilter.create(100000, 0.003); 30 | 31 | for (int index = 0; index < 100000; index++) { 32 | filter.put("abc_test_" + index); 33 | } 34 | int n = 0; 35 | for (int i = 0; i < 100000; i++) { 36 | if (filter.mightContain("abc_test_" + i)) { 37 | n++; 38 | } 39 | } 40 | assertTrue(n >= 99997); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/customAnno/ExcelProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.customAnno; 19 | 20 | import org.ttzero.excel.annotation.Converter; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Inherited; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * @author guanquan.wang at 2022-05-03 18:36 30 | */ 31 | @Target(ElementType.FIELD) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Inherited 34 | public @interface ExcelProperty { 35 | 36 | String[] value() default {""}; 37 | 38 | int index() default -1; 39 | 40 | Class converter() default Converter.AutoConverter.class; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/entity/CustomizeDataSourceSheet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import org.ttzero.excel.service.StudentService; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * Custom data source worksheet, the data source can be 25 | * micro-services, Mybatis, JPA or any other source. If 26 | * the data source returns an array of json objects, please 27 | * convert to an object ArrayList or Map ArrayList, the object 28 | * ArrayList needs to inherit {@link ListSheet}, the Map ArrayList 29 | * needs to inherit {@link ListMapSheet} and implement 30 | * the {@link #more()} method. 31 | * 32 | * If other formats cannot be converted to ArrayList, you 33 | * need to inherit from the base class {@link Sheet} and implement the 34 | * {@link Sheet#resetBlockData()} and {@link Sheet#getHeaderColumns()} methods. 35 | * 36 | * @author guanquan.wang at 2019-04-30 15:12 37 | */ 38 | public class CustomizeDataSourceSheet extends ListSheet { 39 | 40 | private StudentService service; 41 | 42 | private int pageNo; 43 | private final int limit = 1 << 9; 44 | 45 | /** 46 | * Do not specify the worksheet name 47 | * Use the default worksheet name Sheet1,Sheet2... 48 | */ 49 | public CustomizeDataSourceSheet() { 50 | this(null); 51 | } 52 | 53 | /** 54 | * Specify the worksheet name 55 | * @param name the worksheet name 56 | */ 57 | public CustomizeDataSourceSheet(String name) { 58 | super(name); 59 | this.service = new StudentService(); 60 | } 61 | 62 | /** 63 | * This method is used for the worksheet to get the data. 64 | * This is a data source independent method. You can get data 65 | * from any data source. Since this method is stateless, you 66 | * should manage paging or other information in your custom Sheet. 67 | * 68 | * The more data you get each time, the faster write speed. You 69 | * should minimize the database query or network request, but the 70 | * excessive data will put pressure on the memory. Please balance 71 | * this value before the speed and memory. You can refer to {@code 2^8 ~ 2^10} 72 | * 73 | * This method is blocked 74 | * 75 | * @return The data output to the worksheet, if a null or empty 76 | * ArrayList returned, mean that the current worksheet is finished written. 77 | */ 78 | @Override 79 | public List more() { 80 | if (pageNo >= 10) { 81 | return null; 82 | } 83 | return service.getPageData(pageNo++, limit); 84 | } 85 | 86 | /** 87 | * The worksheet is written by units of row-block. The default size 88 | * of a row-block is 32, which means that 32 rows of data are 89 | * written at a time. If the data is not enough, the {@link #more()} 90 | * method will be called to get more data. 91 | * 92 | * @return the row-block size 93 | */ 94 | public int getRowBlockSize() { 95 | return 256; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/entity/HideColumnTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.entity; 19 | 20 | import org.junit.Test; 21 | import org.ttzero.excel.annotation.ExcelColumn; 22 | import org.ttzero.excel.reader.ExcelReader; 23 | 24 | import java.io.IOException; 25 | import java.util.List; 26 | import java.util.stream.Collectors; 27 | 28 | import static org.junit.Assert.assertEquals; 29 | 30 | /** 31 | * @author guanquan.wang at 2022-08-03 08:50 32 | */ 33 | public class HideColumnTest extends WorkbookTest { 34 | @Test public void testColumnHide() throws IOException { 35 | String fileName = "Hide Column.xlsx"; 36 | List expectList = ListObjectSheetTest.Item.randomTestData(10); 37 | Column[] columns = {new Column("ID", "id").hide(), new Column("NAME", "name")}; 38 | new Workbook().addSheet(new ListSheet<>(expectList, columns)) 39 | .writeTo(defaultTestPath.resolve(fileName)); 40 | 41 | try (ExcelReader reader = ExcelReader.read(defaultTestPath.resolve(fileName))) { 42 | List list = reader.sheet(0).headerColumnIgnoreCase().dataRows().map(row -> row.to(ListObjectSheetTest.Item.class)).collect(Collectors.toList()); 43 | assertEquals(expectList.size(), list.size()); 44 | for (int i = 0, len = expectList.size(); i < len; i++) { 45 | ListObjectSheetTest.Item expect = expectList.get(i), e = list.get(i); 46 | assertEquals(expect, e); 47 | } 48 | } 49 | } 50 | 51 | @Test public void testColumnAnnoHide() throws IOException { 52 | String fileName = "Hide Column Annotation.xlsx"; 53 | List expectList = HideColumnItem.randomTestData(10); 54 | new Workbook().addSheet(new ListSheet<>(expectList)) 55 | .writeTo(defaultTestPath.resolve(fileName)); 56 | 57 | try (ExcelReader reader = ExcelReader.read(defaultTestPath.resolve(fileName))) { 58 | List list = reader.sheet(0).dataRows().map(row -> row.to(ListObjectSheetTest.Item.class)).collect(Collectors.toList()); 59 | assertEquals(expectList.size(), list.size()); 60 | for (int i = 0, len = expectList.size(); i < len; i++) { 61 | ListObjectSheetTest.Item expect = expectList.get(i), e = list.get(i); 62 | assertEquals(expect, e); 63 | } 64 | } 65 | } 66 | 67 | public static class HideColumnItem extends ListObjectSheetTest.Item { 68 | public HideColumnItem() { 69 | } 70 | 71 | public HideColumnItem(int id, String name) { 72 | super(id, name); 73 | } 74 | 75 | @ExcelColumn(hide = true) 76 | @Override 77 | public int getId() { 78 | return super.getId(); 79 | } 80 | 81 | public static List randomTestData(int n) { 82 | return randomTestData(n, () -> new HideColumnItem(random.nextInt(100), getRandomString())); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/entity/ListMapPagingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import org.junit.Test; 20 | import org.ttzero.excel.reader.ExcelReader; 21 | import org.ttzero.excel.reader.HeaderRow; 22 | import org.ttzero.excel.reader.Row; 23 | import org.ttzero.excel.reader.Sheet; 24 | 25 | import java.io.IOException; 26 | import java.util.Iterator; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | import static org.junit.Assert.assertEquals; 31 | 32 | /** 33 | * @author guanquan.wang at 2019-04-29 11:14 34 | */ 35 | public class ListMapPagingTest extends WorkbookTest { 36 | 37 | @Test public void testPaging() throws IOException { 38 | String fileName = "test map paging.xlsx"; 39 | List> expectList = ListMapSheetTest.createTestData(301); 40 | Workbook workbook = new Workbook() 41 | .addSheet(new ListMapSheet<>(expectList)) 42 | .setWorkbookWriter(new ReLimitXMLWorkbookWriter()); 43 | workbook.writeTo(defaultTestPath.resolve(fileName)); 44 | 45 | int count = expectList.size(), rowLimit = workbook.getSheetAt(0).getSheetWriter().getRowLimit(); 46 | try (ExcelReader reader = ExcelReader.read(defaultTestPath.resolve(fileName))) { 47 | assertEquals(reader.getSheetCount(), (count % (rowLimit - 1) > 0 ? count / (rowLimit - 1) + 1 : count / (rowLimit - 1))); // Include header row 48 | 49 | for (int i = 0, len = reader.getSheetCount(), a = 0; i < len; i++) { 50 | Sheet sheet = reader.sheet(i).header(1); 51 | org.ttzero.excel.reader.HeaderRow header = (HeaderRow) sheet.getHeader(); 52 | assertEquals("id", header.get(0)); 53 | assertEquals("name", header.get(1)); 54 | Iterator iter = sheet.iterator(); 55 | while (iter.hasNext()) { 56 | Map expect = expectList.get(a++), e = iter.next().toMap(); 57 | assertEquals(expect, e); 58 | } 59 | } 60 | } 61 | } 62 | 63 | @Test public void testLessPaging() throws IOException { 64 | String fileName = "test map less paging.xlsx"; 65 | List> expectList = ListMapSheetTest.createTestData(29); 66 | Workbook workbook = new Workbook() 67 | .addSheet(new ListMapSheet<>(expectList)) 68 | .setWorkbookWriter(new ReLimitXMLWorkbookWriter()); 69 | workbook.writeTo(defaultTestPath.resolve(fileName)); 70 | 71 | int count = expectList.size(), rowLimit = workbook.getSheetAt(0).getSheetWriter().getRowLimit(); 72 | try (ExcelReader reader = ExcelReader.read(defaultTestPath.resolve(fileName))) { 73 | assertEquals(reader.getSheetCount(), (count % (rowLimit - 1) > 0 ? count / (rowLimit - 1) + 1 : count / (rowLimit - 1))); // Include header row 74 | 75 | for (int i = 0, len = reader.getSheetCount(), a = 0; i < len; i++) { 76 | Sheet sheet = reader.sheet(i).header(1); 77 | org.ttzero.excel.reader.HeaderRow header = (HeaderRow) sheet.getHeader(); 78 | assertEquals("id", header.get(0)); 79 | assertEquals("name", header.get(1)); 80 | Iterator iter = sheet.iterator(); 81 | while (iter.hasNext()) { 82 | Map expect = expectList.get(a++), e = iter.next().toMap(); 83 | assertEquals(expect, e); 84 | } 85 | } 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/entity/ReLimitXMLWorkbookWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import org.ttzero.excel.entity.e7.XMLWorkbookWriter; 20 | import org.ttzero.excel.entity.e7.XMLWorksheetWriter; 21 | 22 | /** 23 | * @author guanquan.wang at 2019-04-29 14:16 24 | */ 25 | public class ReLimitXMLWorkbookWriter extends XMLWorkbookWriter { 26 | 27 | @Override 28 | public IWorksheetWriter getWorksheetWriter(Sheet sheet) { 29 | return new ReLimitXMLWorksheetWriter(sheet); 30 | } 31 | } 32 | 33 | class ReLimitXMLWorksheetWriter extends XMLWorksheetWriter { 34 | 35 | ReLimitXMLWorksheetWriter(Sheet sheet) { 36 | super(sheet); 37 | } 38 | 39 | /** 40 | * The Worksheet row limit 41 | * @return the limit 42 | */ 43 | @Override 44 | public int getRowLimit() { 45 | return 256; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/entity/SharedStringTableTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import org.junit.Test; 20 | 21 | import java.io.IOException; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.ttzero.excel.entity.WorkbookTest.getRandomString; 27 | 28 | /** 29 | * @author guanquan.wang at 2019-05-08 17:04 30 | */ 31 | public class SharedStringTableTest { 32 | 33 | @Test public void testPutChar() throws IOException { 34 | try (SharedStringTable sst = new SharedStringTable()) { 35 | int n = sst.push('a'); 36 | 37 | assertEquals(n, 0); 38 | assertEquals(sst.size(), 1); 39 | 40 | int index = sst.find('a'); 41 | assertEquals(index, 0); 42 | 43 | index = sst.find('z'); 44 | assertEquals(index, -1); 45 | } 46 | } 47 | 48 | @Test public void testPutString() throws IOException { 49 | try (SharedStringTable sst = new SharedStringTable()) { 50 | int n = sst.push("abc"); 51 | assertEquals(n, 0); 52 | assertEquals(sst.size(), 1); 53 | 54 | sst.push("ab"); 55 | 56 | int index = sst.find("ab"); 57 | assertEquals(index, 1); 58 | 59 | index = sst.find("abc"); 60 | assertEquals(index, 0); 61 | 62 | index = sst.find("acc"); 63 | assertEquals(index, -1); 64 | 65 | index = sst.find("abd"); 66 | assertEquals(index, -1); 67 | 68 | index = sst.find("123"); 69 | assertEquals(index, -1); 70 | 71 | index = sst.push('a'); 72 | assertEquals(index, 2); 73 | 74 | index = sst.push('z'); 75 | assertEquals(index, 3); 76 | 77 | index = sst.push('阿'); 78 | assertEquals(index, 4); 79 | 80 | assertEquals(sst.find('z'), 3); 81 | 82 | assertEquals(sst.find('阿'), 4); 83 | } 84 | } 85 | 86 | @Test public void testFind() throws IOException { 87 | try (SharedStringTable sst = new SharedStringTable()) { 88 | int size = 10_000; 89 | Map indexMap = new HashMap<>(size); 90 | String v; 91 | for (int i = 0; i < size; i++) { 92 | v = getRandomString(); 93 | for (; indexMap.containsKey(v); v = getRandomString()) ; 94 | indexMap.put(v, sst.push(v)); 95 | } 96 | 97 | assertEquals(indexMap.size(), sst.size()); 98 | 99 | for (Map.Entry entry : indexMap.entrySet()) { 100 | assertEquals((int) entry.getValue(), sst.find(entry.getKey())); 101 | } 102 | } 103 | } 104 | 105 | @Test public void testNull() throws IOException { 106 | try (SharedStringTable sst = new SharedStringTable()) { 107 | int n; 108 | sst.push("a"); 109 | n = sst.push(null); 110 | 111 | assertEquals(n, 1); 112 | assertEquals(sst.find(null), n); 113 | } 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/entity/SharedStringsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import org.junit.Test; 20 | 21 | import java.io.IOException; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.ttzero.excel.entity.WorkbookTest.author; 27 | import static org.ttzero.excel.entity.WorkbookTest.getRandomString; 28 | 29 | 30 | /** 31 | * @author guanquan.wang at 2019-05-07 17:41 32 | */ 33 | public class SharedStringsTest { 34 | @Test public void testGet() throws IOException { 35 | try (SharedStrings sst = new SharedStrings().init()) { 36 | int index = sst.get("abc"); 37 | assertEquals(index, 0); 38 | 39 | index = sst.get(author); 40 | assertEquals(index, 1); 41 | 42 | index = sst.get("abc"); 43 | assertEquals(index, 0); 44 | 45 | index = sst.get(author); 46 | assertEquals(index, 1); 47 | 48 | index = sst.get(author); 49 | assertEquals(index, 1); 50 | 51 | index = sst.get("test"); 52 | assertEquals(index, 2); 53 | } 54 | } 55 | 56 | @Test public void testGetChar() throws IOException { 57 | try (SharedStrings sst = new SharedStrings().init()) { 58 | for (int i = 0; i <= 0x7F; i++) { 59 | sst.get((char) i); 60 | } 61 | 62 | for (int i = 0; i < 0x7FFFFFFF; i++) { 63 | char c = (char) (i & 0x7F); 64 | int index = sst.get(c); 65 | assertEquals(index, c); 66 | } 67 | } 68 | } 69 | 70 | @Test public void testFind() throws IOException { 71 | try (SharedStrings sst = new SharedStrings().init()) { 72 | int size = 10_000; 73 | Map indexMap = new HashMap<>(size); 74 | String v; 75 | for (int i = 0; i < size; i++) { 76 | v = getRandomString(); 77 | 78 | indexMap.put(v, sst.get(v)); 79 | } 80 | 81 | for (Map.Entry entry : indexMap.entrySet()) { 82 | assertEquals((int) entry.getValue(), sst.get(entry.getKey())); 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/entity/StatementPagingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import org.junit.Test; 20 | import org.ttzero.excel.reader.ExcelReader; 21 | import org.ttzero.excel.reader.Row; 22 | 23 | import java.io.IOException; 24 | import java.sql.Connection; 25 | import java.sql.PreparedStatement; 26 | import java.sql.ResultSet; 27 | import java.sql.SQLException; 28 | import java.util.Iterator; 29 | 30 | import static org.junit.Assert.assertEquals; 31 | import static org.junit.Assert.assertTrue; 32 | 33 | /** 34 | * @author guanquan.wang at 2019-04-28 22:47 35 | */ 36 | public class StatementPagingTest extends SQLWorkbookTest { 37 | @Test public void testPaging() throws SQLException, IOException { 38 | try (Connection con = getConnection()) { 39 | String fileName = "statement paging.xlsx", 40 | sql = "select id, name, age, create_date, update_date from student"; 41 | 42 | Workbook workbook = new Workbook() 43 | .addSheet(new StatementSheet(con, sql)) 44 | .setWorkbookWriter(new ReLimitXMLWorkbookWriter()); 45 | workbook.writeTo(defaultTestPath.resolve(fileName)); 46 | 47 | int rowLimit = workbook.getSheetAt(0).getSheetWriter().getRowLimit(); 48 | 49 | PreparedStatement ps = con.prepareStatement("select count(*) from student"); 50 | ResultSet rs = ps.executeQuery(); 51 | int count = rs.getInt(1); 52 | rs.close(); 53 | ps.close(); 54 | 55 | ps = con.prepareStatement(sql); 56 | rs = ps.executeQuery(); 57 | try (ExcelReader reader = ExcelReader.read(defaultTestPath.resolve(fileName))) { 58 | assertEquals(reader.getSheetCount(), (count % (rowLimit - 1) > 0 ? count / (rowLimit - 1) + 1 : count / (rowLimit - 1))); // Include header row 59 | 60 | for (int i = 0, len = reader.getSheetCount(); i < len; i++) { 61 | Iterator iter = reader.sheet(i).iterator(); 62 | assertTrue(iter.hasNext()); 63 | org.ttzero.excel.reader.Row header = iter.next(); 64 | assertEquals("id", header.getString(0)); 65 | assertEquals("name", header.getString(1)); 66 | assertEquals("age", header.getString(2)); 67 | assertEquals("create_date", header.getString(3)); 68 | assertEquals("update_date", header.getString(4)); 69 | int x = 1; 70 | while (rs.next()) { 71 | assertTrue(iter.hasNext()); 72 | org.ttzero.excel.reader.Row row = iter.next(); 73 | 74 | assertEquals(rs.getInt(1), (int) row.getInt(0)); 75 | assertEquals(rs.getString(2), row.getString(1)); 76 | assertEquals(rs.getInt(3), (int) row.getInt(2)); 77 | assertTrue(rs.getTimestamp(4) != null ? rs.getTimestamp(4).getTime() / 1000 == row.getTimestamp(3).getTime() / 1000 : row.getTimestamp(0) == null); 78 | assertTrue(rs.getTimestamp(5) != null ? rs.getTimestamp(5).getTime() / 1000 == row.getTimestamp(4).getTime() / 1000 : row.getTimestamp(4) == null); 79 | 80 | if (++x >= rowLimit) break; 81 | } 82 | } 83 | } 84 | rs.close(); 85 | ps.close(); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/entity/ValidationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.entity; 19 | 20 | import org.junit.Test; 21 | import org.ttzero.excel.manager.Const; 22 | import org.ttzero.excel.reader.Dimension; 23 | import org.ttzero.excel.util.DateUtil; 24 | import org.ttzero.excel.validation.DateValidation; 25 | import org.ttzero.excel.validation.ListValidation; 26 | import org.ttzero.excel.validation.TimeValidation; 27 | import org.ttzero.excel.validation.Validation; 28 | import org.ttzero.excel.validation.WholeValidation; 29 | 30 | import java.io.IOException; 31 | import java.sql.Time; 32 | import java.util.ArrayList; 33 | import java.util.Arrays; 34 | import java.util.List; 35 | 36 | 37 | /** 38 | * @author guanquan.wang at 2022-08-17 20:05:42 39 | */ 40 | public class ValidationTest extends WorkbookTest { 41 | @Test public void testValidation() throws IOException { 42 | List expectValidations = new ArrayList<>(); 43 | // 下拉框选择“男”,“女” 44 | expectValidations.add(new ListValidation<>().in("男", "女").dimension(Dimension.of("A1"))); 45 | // B1:E1 单元格只能输入大于1的数 46 | expectValidations.add(new WholeValidation().greaterThan(1).dimension(Dimension.of("B1:E1"))); 47 | // 限制日期在2022年 48 | expectValidations.add(new DateValidation().between("2022-01-01", "2022-12-31").dimension(Dimension.of("A2"))); 49 | // 限制时间小于下午6点(因为此时下班...) 50 | expectValidations.add(new TimeValidation().lessThan(DateUtil.toTimeValue(Time.valueOf("18:00:00"))).dimension(Dimension.of("B2"))); 51 | // 引用 52 | expectValidations.add(new ListValidation<>().in(Dimension.of("A10:A12")).dimension(Dimension.of("D5"))); 53 | final String fileName = "Validation Test.xlsx"; 54 | new Workbook() 55 | .addSheet(new ListSheet<>(Arrays.asList("北京", "天津", "上海")) 56 | .setStartRowIndex(10, false) 57 | .putExtProp(Const.ExtendPropertyKey.DATA_VALIDATION, expectValidations)) 58 | .writeTo(defaultTestPath.resolve(fileName)); 59 | } 60 | 61 | @Test public void testValidationExtension() throws IOException { 62 | List expectValidations = new ArrayList<>(); 63 | // 引用 64 | expectValidations.add(new ListValidation<>().in("Sheet2", Dimension.of("A1:A3")).dimension(Dimension.of("D1:D5"))); 65 | final String fileName = "Validation Extension Test.xlsx"; 66 | new Workbook() 67 | .addSheet(new ListSheet<>().putExtProp(Const.ExtendPropertyKey.DATA_VALIDATION, expectValidations)) 68 | .addSheet(new ListSheet<>(Arrays.asList("未知","男","女"))) 69 | .writeTo(defaultTestPath.resolve(fileName)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/entity/WorkbookTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.entity; 18 | 19 | import org.ttzero.excel.util.FileUtil; 20 | 21 | import java.io.IOException; 22 | import java.nio.file.Files; 23 | import java.nio.file.Path; 24 | import java.nio.file.Paths; 25 | import java.util.Random; 26 | import java.util.zip.CRC32; 27 | 28 | import static org.ttzero.excel.util.FileUtil.exists; 29 | 30 | /** 31 | * @author guanquan.wang at 2019-04-26 17:40 32 | */ 33 | public class WorkbookTest { 34 | /** 35 | * The default output path 36 | */ 37 | public static Path defaultTestPath = Paths.get("target/excel/"); 38 | public static String author = System.getProperty("user.name"); 39 | public static Random random = new Random(); 40 | 41 | public static char[] charArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890❤不逢北国之秋,已将近十余年了。在南方每年到了秋天,总要想起陶然亭(1)的芦花,钓鱼台(2)的柳影,西山(3)的虫唱,玉泉(4)的夜月,潭柘寺(5)的钟声。在北平即使不出门去吧,就是在皇城人海之中,租人家一椽(6)破屋来住着,早晨起来,泡一碗浓茶,向院子一坐,你也能看得到很高很高的碧绿的天色,听得到青天下驯鸽的飞声。从槐树叶底,朝东细数着一丝一丝漏下来的日光,或在破壁腰中,静对着像喇叭似的牵牛花(朝荣)的蓝朵,自然而然地也能够感觉到十分的秋意。说到了牵牛花,我以为以蓝色或白色者为佳,紫黑色次之,淡红色最下。最好,还要在牵牛花底,叫长着几根疏疏落落的尖细且长的秋草,使作陪衬。".toCharArray(); 42 | private static final char[] cache = new char[32]; 43 | 44 | public static String getRandomAssicString() { 45 | return getRandomAssicString(20); 46 | } 47 | 48 | public static String getRandomAssicString(int maxlen) { 49 | int n = random.nextInt(maxlen) + 1, size = 62; 50 | for (int i = 0; i < n; i++) { 51 | cache[i] = charArray[random.nextInt(size)]; 52 | } 53 | return new String(cache, 0, n); 54 | } 55 | 56 | public static String getRandomString(int maxLen) { 57 | int n = random.nextInt(maxLen) + 1, size = charArray.length; 58 | for (int i = 0; i < n; i++) { 59 | cache[i] = charArray[random.nextInt(size)]; 60 | } 61 | return new String(cache, 0, n); 62 | } 63 | 64 | public static String getRandomString() { 65 | return getRandomString(cache.length); 66 | } 67 | 68 | public static Path getOutputTestPath() throws IOException { 69 | if (!exists(defaultTestPath)) { 70 | FileUtil.mkdir(defaultTestPath); 71 | } 72 | return defaultTestPath; 73 | } 74 | 75 | public static long crc32(Path path) { 76 | if (!Files.exists(path)) return 0L; 77 | CRC32 crc32 = new CRC32(); 78 | try { 79 | crc32.update(Files.readAllBytes(path)); 80 | } catch (IOException e) { 81 | return 0L; 82 | } 83 | return crc32.getValue(); 84 | } 85 | 86 | public static long crc32(byte[] bytes) { 87 | CRC32 crc32 = new CRC32(); 88 | crc32.update(bytes); 89 | return crc32.getValue(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/reader/CacheTesterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2020, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.reader; 19 | 20 | import org.junit.Test; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | import static org.junit.Assert.assertFalse; 24 | import static org.junit.Assert.assertTrue; 25 | 26 | /** 27 | * @author guanquan.wang at 2020-03-11 15:39 28 | */ 29 | public class CacheTesterTest { 30 | @Test public void test() { 31 | Tester tester = new Tester.BinaryTester(1024); 32 | assertFalse(tester.test(0)); 33 | assertFalse(tester.test(1)); 34 | assertFalse(tester.test(9)); 35 | assertTrue(tester.test(1)); 36 | assertTrue(tester.test(9)); 37 | assertFalse(tester.test(5)); 38 | assertTrue(tester.test(0)); 39 | 40 | for (int i = 0; i < 63; tester.test(i++)) ; 41 | 42 | assertFalse(tester.test(1000)); 43 | 44 | assertEquals(tester.size(), 16); 45 | 46 | assertTrue(tester.test(32)); 47 | assertTrue(tester.test(1000)); 48 | assertFalse(tester.test(64)); 49 | 50 | assertFalse(tester.test(63)); 51 | assertFalse(tester.test(1024)); 52 | 53 | assertEquals(tester.size(), 16); 54 | assertEquals(tester.limit(), 1087); 55 | 56 | assertTrue(tester.test(1024)); 57 | assertFalse(tester.test(1087)); 58 | 59 | assertEquals(tester.size(), 16); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/reader/DimensionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2021, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.reader; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | /** 24 | * @author guanquan.wang at 2021-03-25 00:54 25 | */ 26 | public class DimensionTest { 27 | 28 | @Test public void testFirstDim() { 29 | Dimension d = Dimension.of("A1"); 30 | assertEquals(d.firstColumn, 1); 31 | assertEquals(d.firstRow, 1); 32 | assertEquals(d.lastColumn, 1); 33 | assertEquals(d.lastRow, 1); 34 | assertEquals(d.width, 1); 35 | assertEquals(d.height, 1); 36 | 37 | assertEquals(d.toReferer(), "$A$1"); 38 | } 39 | 40 | @Test public void testFirstDim2() { 41 | Dimension d = Dimension.of("B3:"); 42 | assertEquals(d.firstColumn, 2); 43 | assertEquals(d.firstRow, 3); 44 | assertEquals(d.lastColumn, 2); 45 | assertEquals(d.lastRow, 1048576); 46 | assertEquals(d.width, 1); 47 | assertEquals(d.height, 1048574); 48 | 49 | assertEquals(d.toReferer(), "$B$3:$B$1048576"); 50 | } 51 | 52 | @Test public void testLastDim() { 53 | Dimension d = Dimension.of(":C2"); 54 | assertEquals(d.firstColumn, 1); 55 | assertEquals(d.firstRow, 1); 56 | assertEquals(d.lastColumn, 3); 57 | assertEquals(d.lastRow, 2); 58 | assertEquals(d.width, 3); 59 | assertEquals(d.height, 2); 60 | 61 | assertEquals(d.toReferer(), "$A$1:$C$2"); 62 | } 63 | 64 | @Test public void testFullDim() { 65 | Dimension d = Dimension.of("AZ103:CCA63335"); 66 | assertEquals(d.firstColumn, 52); 67 | assertEquals(d.firstRow, 103); 68 | assertEquals(d.lastColumn, 2107); 69 | assertEquals(d.lastRow, 63335); 70 | assertEquals(d.width, 2056); 71 | assertEquals(d.height, 63233); 72 | 73 | assertEquals(d.toReferer(), "$AZ$103:$CCA$63335"); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/reader/FormulasLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | 18 | package org.ttzero.excel.reader; 19 | 20 | import java.io.BufferedReader; 21 | import java.io.IOException; 22 | import java.nio.charset.StandardCharsets; 23 | import java.nio.file.Files; 24 | import java.nio.file.Path; 25 | import java.util.Collections; 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | 29 | /** 30 | * 装载formulas预期文件 31 | * 32 | * @author guanquan.wang at 2023-11-06 19:05 33 | */ 34 | public class FormulasLoader { 35 | /** 36 | * 解析expect文件夹下以$formulas结尾的文件 37 | * 38 | * @param path 预期文件路径 39 | * @return 行列坐标:公式字符串 40 | */ 41 | public static Map load(Path path) { 42 | if (!Files.exists(path)) return Collections.emptyMap(); 43 | Map map = new HashMap<>(); 44 | try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { 45 | String line; 46 | while ((line = reader.readLine()) != null) { 47 | int i = line.indexOf('='); 48 | if (i > 0) map.put(ExcelReader.coordinateToLong(line.substring(0, i)), line.substring(i + 1)); 49 | } 50 | } catch (IOException ex) { 51 | ex.printStackTrace(); 52 | } 53 | return map; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/reader/IndexSharedStringTableTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.reader; 18 | 19 | import org.junit.Test; 20 | 21 | import java.io.IOException; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | import static org.ttzero.excel.entity.WorkbookTest.getRandomString; 25 | 26 | /** 27 | * @author guanquan.wang at 2019-05-10 21:42 28 | */ 29 | public class IndexSharedStringTableTest { 30 | 31 | @Test public void test1() throws IOException { 32 | try (IndexSharedStringTable sst = new IndexSharedStringTable()) { 33 | sst.push('a'); 34 | sst.push('b'); 35 | 36 | String value; 37 | value = sst.get(0); 38 | assertEquals(value, "a"); 39 | 40 | value = sst.get(1); 41 | assertEquals(value, "b"); 42 | 43 | String[] array = new String[2]; 44 | int n = sst.get(0, array); 45 | assertEquals(n, 2); 46 | assertEquals("a", array[0]); 47 | assertEquals("b", array[1]); 48 | } 49 | } 50 | 51 | @Test public void test2() throws IOException { 52 | try (IndexSharedStringTable sst = new IndexSharedStringTable()) { 53 | int length = 10000; 54 | String[] buf = new String[length]; 55 | for (int i = 0; i < length; i++) 56 | buf[i] = getRandomString(); 57 | 58 | for (String s : buf) { 59 | sst.push(s); 60 | } 61 | 62 | for (int i = 0; i < length; i++) { 63 | String s = sst.get(i); 64 | assertEquals(s, buf[i]); 65 | } 66 | 67 | int fromIndex = 0, size = length; 68 | String[] _buf = new String[size]; 69 | size = sst.get(fromIndex, _buf); 70 | assertEquals(size, length - fromIndex); 71 | for (int i = 0; i < size; i++) { 72 | assertEquals(_buf[i], buf[fromIndex + i]); 73 | } 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/reader/MultiStyleInCellTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.reader; 18 | 19 | import org.junit.Test; 20 | 21 | import java.io.IOException; 22 | import java.util.Arrays; 23 | import java.util.Objects; 24 | 25 | import static org.junit.Assert.assertArrayEquals; 26 | import static org.ttzero.excel.reader.ExcelReaderTest.testResourceRoot; 27 | 28 | /** 29 | * @author guanquan.wang at 2019-06-12 17:26 30 | */ 31 | public class MultiStyleInCellTest { 32 | @Test public void testMulti() throws IOException { 33 | try (ExcelReader reader = ExcelReader.read(testResourceRoot().resolve("multi-style In cell.xlsx"))) { 34 | String[] array = reader.sheet(0).rows().map(row -> row.getString(2)).filter(Objects::nonNull).toArray(String[]::new); 35 | String[] expectArray = {"abred中文","IM8zc","B6tw","JWGv25V","fTY56z","nxWnqE","RyyJ8o","UgkTgnx","JDrYdU","Bl7Lh","w2vc9","4xbrwu","5A8RN","LUYhEG","y1Ee5Sl","fyM1","p6Dn","tMMWp","P1coCD","Ej2vXbZ","aUkcla","z2aLkN8","ljjaD8","r6T1hEP","qu5iO","TJt8C","sJlIYKN","Lt9NMp","D7bVWFk","1BwJHPP","S7Pf8hG","bHXsj49","EqXOeS","exyeBe","FtKjhf","KVs8LWt","uEkSmmj","1DxEoJ","tP3d","Nb2fu","nPJ6","2CrTk17","JWbwVD","aaX7p","NkFL","9j0xsxt","6rcGpax","h0blSId","gCPR","JO1rz","m5ZEpB3","WPpB77c","iEct","Tfuq","cHv9n3Y","TX9dhf","1Ueoj7","1EY9V","0ruA","XCXhJRp","uD36","Iat3fJE","1YsnAY","yrN9e","sSIM7G","gDXE","uamheu","ZXMN","8MymZBX","ic9aLbJ","e1QuI","bEQYyk","3DKbi0k","NRjW2","vz9HLE","aBYIMi","7Xe2lQz","d95SDS","jUfZ","ODrB2"}; 36 | assertArrayEquals(expectArray, array); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/reader/PreCalcTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2020, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.reader; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | /** 24 | * @author guanquan.wang at 2020-01-05 20:35 25 | */ 26 | public class PreCalcTest { 27 | @Test public void testSimple() { 28 | Row row = new Row(); 29 | row.addRef(0, "B2:B8"); 30 | row.setCalc(0, "A89"); 31 | String calc = row.getCalc(0, 5 << 14 | 2); 32 | assertEquals("A92", calc); 33 | } 34 | 35 | @Test public void testPlus() { 36 | Row row = new Row(); 37 | row.addRef(0, "B2:B8"); 38 | row.setCalc(0, "(A2+A3)+1"); 39 | String calc = row.getCalc(0, 4 << 14 | 2); 40 | assertEquals("(A4+A5)+1", calc); 41 | } 42 | 43 | @Test public void testRange() { 44 | Row row = new Row(); 45 | row.addRef(0, "B2:D8"); 46 | row.setCalc(0, "(A2+B3)+1"); 47 | String calc = row.getCalc(0, 4 << 14 | 3); 48 | assertEquals("(B4+C5)+1", calc); 49 | } 50 | 51 | @Test public void testDoubleQuotes() { 52 | Row row = new Row(); 53 | row.addRef(0, "B2:D8"); 54 | row.setCalc(0, "\"AB12\".substring(3)"); 55 | String calc = row.getCalc(0, 4 << 14 | 3); 56 | assertEquals("\"AB12\".substring(3)", calc); 57 | } 58 | 59 | @Test public void testDoubleQuotes2() { 60 | Row row = new Row(); 61 | row.addRef(0, "B2:D8"); 62 | row.setCalc(0, "\"AB12.substring(3)"); 63 | String calc = row.getCalc(0, 4 << 14 | 3); 64 | assertEquals("\"AB12.substring(3)", calc); 65 | } 66 | 67 | @Test public void testRows() { 68 | Row row = new Row(); 69 | row.addRef(1, "B9:B65"); 70 | row.setCalc(1, "A9+1"); 71 | String calc = row.getCalc(1, 10 << 14 | 2); 72 | assertEquals("A10+1", calc); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/service/StudentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019, guanquan.wang@yandex.com All Rights Reserved. 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 | */ 16 | 17 | package org.ttzero.excel.service; 18 | 19 | import org.ttzero.excel.entity.ListObjectSheetTest; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author guanquan.wang at 2019-04-30 15:17 25 | */ 26 | public class StudentService { 27 | 28 | public List getPageData(int pageNo, int limit) { 29 | return ListObjectSheetTest.Student.randomTestData(pageNo, limit); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/ttzero/excel/util/DateUtilTest.java: -------------------------------------------------------------------------------- 1 | package org.ttzero.excel.util; 2 | 3 | import org.junit.Test; 4 | import java.sql.Timestamp; 5 | import java.time.LocalDate; 6 | import java.time.LocalDateTime; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | import static org.ttzero.excel.util.DateUtil.DAYS_1900_TO_1970; 10 | 11 | /** 12 | * 13 | * 14 | * @author CarlJia 15 | * @since 2023-03-27 16 | */ 17 | public class DateUtilTest { 18 | 19 | @Test 20 | public void toLocalDate() { 21 | LocalDate localDate = DateUtil.toLocalDate(24014); 22 | LocalDate expectedLocalDate = LocalDate.of(1965, 9, 29); 23 | assertEquals(expectedLocalDate, localDate); 24 | 25 | LocalDate localDate1 = DateUtil.toLocalDate(-25567 + DAYS_1900_TO_1970); 26 | LocalDate expectedLocalDate1 = LocalDate.of(1900, 1, 1); 27 | assertEquals(expectedLocalDate1, localDate1); 28 | 29 | LocalDate ts = DateUtil.toLocalDate(-86890 + DAYS_1900_TO_1970); 30 | assertEquals(ts, LocalDate.of(1732, 2, 8)); 31 | } 32 | 33 | @Test 34 | public void toLocalDateTime() { 35 | LocalDateTime localDateTime = DateUtil.toLocalDateTime(24014); 36 | LocalDateTime expectedLocalDateTime = LocalDateTime.of(1965, 9, 29, 0, 0, 0); 37 | assertEquals(expectedLocalDateTime, localDateTime); 38 | 39 | LocalDateTime localDateTime1 = DateUtil.toLocalDateTime(44927.00000579861); 40 | assertEquals(localDateTime1, LocalDateTime.of(2023, 1, 1, 0, 0, 1)); 41 | 42 | LocalDateTime localDateTime2 = DateUtil.toLocalDateTime(44927.000011516204); 43 | assertEquals(localDateTime2, LocalDateTime.of(2023, 1, 1, 0, 0, 1)); 44 | 45 | LocalDateTime localDateTime3 = DateUtil.toLocalDateTime(44927.000011516204); 46 | assertEquals(localDateTime3, LocalDateTime.of(2023, 1, 1, 0, 0, 1)); 47 | 48 | LocalDateTime localDateTime4 = DateUtil.toLocalDateTime(44727.99998842592); 49 | assertEquals(localDateTime4, LocalDateTime.of(2022, 6, 15, 23, 59, 59)); 50 | 51 | LocalDateTime localDateTime5 = DateUtil.toLocalDateTime(44728.99998836806); 52 | assertEquals(localDateTime5, LocalDateTime.of(2022, 6, 16, 23, 59, 59)); 53 | } 54 | 55 | @Test public void toTimestamp() { 56 | Timestamp ts = DateUtil.toTimestamp(-86890 + DAYS_1900_TO_1970); 57 | assertEquals(ts, Timestamp.valueOf("1732-02-08 00:00:00")); 58 | 59 | Timestamp ts2 = DateUtil.toTimestamp(44927.000011516204); 60 | assertEquals(ts2, Timestamp.valueOf("2023-01-01 00:00:01")); 61 | 62 | Timestamp ts3 = DateUtil.toTimestamp(44728.99998836806); 63 | assertEquals(ts3, Timestamp.valueOf("2022-06-16 23:59:59")); 64 | 65 | Timestamp ts4 = DateUtil.toTimestamp(2); 66 | assertEquals(ts4, Timestamp.valueOf("1900-01-01 00:00:00")); 67 | 68 | Timestamp ts5 = DateUtil.toTimestamp("2023-01-01"); 69 | assertEquals(ts5, Timestamp.valueOf("2023-01-01 00:00:00")); 70 | 71 | Timestamp ts6 = DateUtil.toTimestamp("2023-01-01 1"); 72 | assertEquals(ts6, Timestamp.valueOf("2023-01-01 01:00:00")); 73 | 74 | Timestamp ts7 = DateUtil.toTimestamp("2023-01-01 1:"); 75 | assertEquals(ts7, Timestamp.valueOf("2023-01-01 01:00:00")); 76 | 77 | Timestamp ts8 = DateUtil.toTimestamp("2023-01-01 1:2"); 78 | assertEquals(ts8, Timestamp.valueOf("2023-01-01 01:02:00")); 79 | 80 | Timestamp ts9 = DateUtil.toTimestamp("2023-01-01 1:2:"); 81 | assertEquals(ts9, Timestamp.valueOf("2023-01-01 01:02:00")); 82 | 83 | Timestamp ts10 = DateUtil.toTimestamp("2023-01-01 1:2:3"); 84 | assertEquals(ts10, Timestamp.valueOf("2023-01-01 01:02:03")); 85 | } 86 | } -------------------------------------------------------------------------------- /src/test/resources/#145.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/#145.xlsx -------------------------------------------------------------------------------- /src/test/resources/#148.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/#148.xlsx -------------------------------------------------------------------------------- /src/test/resources/#150.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/#150.xlsx -------------------------------------------------------------------------------- /src/test/resources/#169.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/#169.xlsx -------------------------------------------------------------------------------- /src/test/resources/#175.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/#175.xlsx -------------------------------------------------------------------------------- /src/test/resources/#226.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/#226.xlsx -------------------------------------------------------------------------------- /src/test/resources/#238.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/#238.xlsx -------------------------------------------------------------------------------- /src/test/resources/#354.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/#354.xlsx -------------------------------------------------------------------------------- /src/test/resources/#81.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/#81.xlsx -------------------------------------------------------------------------------- /src/test/resources/1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/1.xlsx -------------------------------------------------------------------------------- /src/test/resources/247&249.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/247&249.xlsx -------------------------------------------------------------------------------- /src/test/resources/4.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/4.xlsx -------------------------------------------------------------------------------- /src/test/resources/Number2Excel.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/Number2Excel.xlsx -------------------------------------------------------------------------------- /src/test/resources/all type.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/all type.xlsx -------------------------------------------------------------------------------- /src/test/resources/drawing.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/drawing.xlsx -------------------------------------------------------------------------------- /src/test/resources/elven-eyes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/elven-eyes.jpg -------------------------------------------------------------------------------- /src/test/resources/expect/#145$plu.txt: -------------------------------------------------------------------------------- 1 | plu编号,plu名称,单位,单价,货号,商品条码,保质期天数,皮重,条码类型 2 | 1,麻辣烫,件,11,1,,,,2 3 | 2,麻辣拌,件,11,2,,,,2 -------------------------------------------------------------------------------- /src/test/resources/expect/#148$Sheet1.txt: -------------------------------------------------------------------------------- 1 | "新华社北京12月17日电 题:嫦娥五号:创造五项“中国首次” 44年来再获月球样品——权威专家解读中国航天里程碑式新跨越 2 | 3 |   新华社记者张泉、彭韵佳 4 | 5 |   十年磨剑,载誉归来!17日1时59分,嫦娥五号返回器携带月球样品成功着陆。 6 | 7 |   过去的23个日夜,嫦娥五号完成了1次对接、6次分离,两种方式采样、5次样品转移,经历了11个重大阶段和关键步骤,环环相连、丝丝入扣。 8 | 9 |   嫦娥五号任务圆满成功对我国航天事业发展具有怎样的意义?嫦娥五号带回的月球样品将怎样储存、研究?17日下午举行的国新办发布会上,权威专家第一时间作出解读。 10 | 11 |   五项“中国首次” 中国航天实现里程碑式新跨越 12 | 13 |   11月24日,长征五号准时并成功发射,之后探测器地月转移、近月制动、两两分离、平稳落月、钻表取样、月面起飞、交会对接及样品转移、环月等待、月地转移,今天再入返回、安全着陆,整个工程任务现在转入科学研究的新阶段。 14 | 15 |   国家航天局副局长、探月工程副总指挥吴艳华说,嫦娥五号任务创造了五项“中国首次”,一是在地外天体的采样与封装;二是地外天体上的点火起飞、精准入轨;三是月球轨道无人交会对接和样品转移;四是携带月球样品以近第二宇宙速度再入返回;五是建立我国月球样品的存储、分析和研究系统。 16 | 17 |   “此次任务的成功实施,是我国航天事业发展中里程碑式的新跨越。”吴艳华说,标志着我国具备了地月往返的能力,实现了“绕、落、回”三步走规划完美收官,为我国未来月球与行星探测奠定了坚实基础。 18 | 19 |   求索寰宇开新篇。据介绍,以嫦娥五号任务圆满成功为起点,我国探月工程四期和行星探测工程将接续实施。目前,首次火星探测任务“天问一号”正在奔火的征程;嫦娥六号、七号、八号,小行星探测、火星取样返回、木星系探测等工程任务也将按计划陆续实施。 20 | 21 |   多项创新支撑 带动我国航天科技整体发展 22 | 23 |   怎样实现在月球上可靠地采样并封装到真空容器中?如何实现月面起飞并精准入轨?如何确保月球轨道无人交会对接精准完成…… 24 | 25 |   “五个‘中国首次’都是嫦娥五号任务所面临的新挑战。实际上,对整个工程来讲,恐怕还不止这五个方面。”国家航天局探月工程三期总设计师胡浩说,作为探月工程三期的嫦娥五号任务,和前期任务比,技术跨度是比较大的。 26 | 27 |   新研制的3000牛的发动机在到达月球制动和从月面起飞时表现良好;基于视觉的月面采样区快速分析,以及采样、放样、装罐、放罐过程的快速定位,为机械臂快速调整提供支持;对飞行轨道、飞行程序等进行快速设计,支撑任务中可能遇到的天上或者地面的应急情况…… 28 | 29 |   “作为国家重大科技专项,自主创新是我们的目标,也是我们的主旨。”胡浩说,我们设计了整个一套工程体系,建立了深空测控网,使我们深空测控能够达到全球布局,支撑整个任务的完成。从某种意义上来讲,探月工程系统地带动了我国航天科技的整体发展。 30 | 31 |   吴艳华说,探月工程建设提升了我国深空探测核心能力,培养造就了一支专业化、年轻化、能打硬仗的人才队伍,完善形成了组织实施复杂航天工程的系统方法。 32 | 33 |   44年来再获月球样品 鼓励国内外科学家参与研究 34 | 35 |   伴随着嫦娥五号任务圆满成功,人类44年以来再次获得月球样品,此次月球样品的研究备受关注。 36 | 37 |   中国科学院国家天文台研究员、探月工程三期副总设计师李春来介绍,嫦娥五号的采样点选择了风暴洋东北角的玄武岩区域,这是全新的采样区域,全新的样品研究,对月球表面的风化作用、火山作用和区域地质背景、区域地质演化方面应该能作出很多科研贡献。 38 | 39 |   “绝大部分样品会用于科学研究,我们会在实验室进行长期的、系统的对月球样品的研究工作,包括它的结构构造、物理特性、化学成分、同位素组成、矿物特点和地质演化方面,希望能够深化我们对月球的起源、演化方面的认识。”李春来说。 40 | 41 |   月球样品是人类共同的财富。吴艳华说,后续,将依据月球样品及数据管理办法,广泛征集合作方案,鼓励国内外更多科学家参与科学研究,力争获得更多科学成果。 42 | 43 |   “除了位于北京的中科院国家天文台作为主要存储地点以外,还将在湖南韶山毛主席的故乡进行异地灾备,他提出的‘可上九天揽月’的夙愿实现了。”吴艳华说。" -------------------------------------------------------------------------------- /src/test/resources/expect/#354$人员导入模版说明.txt: -------------------------------------------------------------------------------- 1 | 备注说明,姓名;必填;最多10位字符,工号;只能输入英文字母和数字的组合;必填;最多30位字符,用户账号;非必填;最多15位字符,身份:下拉选择;非必填,人员所属部门编码;必填,人员所属岗位;必填,性别:下拉选择;非必填,人员类型;下拉选择;非必填,民族;下拉选择;非必填,学历;下拉选择;非必填,证件类型;下拉选择;非必填,证件号;非必填;最多20位字符,联系电话;非必填; 最多11位字符,办公室电话;非必填;最多20位字符,邮箱;非必填;最多64位字符,健康状态;下拉选择;非必填,政治面貌;下拉选;非必填,入职日期;年-月-日;非必填,邮编;非必填;最多 20位字符,通讯地址;非必填;最多64字符,34;非必填;最多32位字符,这是单行文本;非必填;最多32位字符,二;非必填;最多32位字符,标签;非必填;最多32位字符 2 | 字段名称,*姓名,*工号,用户账号,身份,*部门编码,*岗位,性别,人员类型,民族,学历,证件类型,证件号,联系电话,办公室电话,邮箱,健康状况,政治面貌,入职日期,邮编,通讯地址,34,这是单行文本,二,标签 3 | 示例,张三,2022121200,zhangsan,员工,SCBM,生产统计员,男,车间主任,汉,本科,身份证,36010119741220935X,15639467983,0512-82345678,26f2@4hl7h.net,健康,党员,2022-03-10,215000,江苏省南京市鼓楼区热河南路街道,动态字段示例值,动态字段示例值,动态字段示例值,动态字段示例值 -------------------------------------------------------------------------------- /src/test/resources/expect/#81$Sheet1.txt: -------------------------------------------------------------------------------- 1 | 客户编码,人员工号 2 | ,566 3 | 952261313, 4 | 952261312,568 5 | 952261222,569 6 | 952261058,570 7 | -------------------------------------------------------------------------------- /src/test/resources/expect/4$用户注册.txt: -------------------------------------------------------------------------------- 1 | ID,产品ID,渠道ID,AID,注册账号,注册时间,CPS用户ID,渠道类型 2 | 1,0,aTDM,1000,FWGq6,1970-01-01 08:00:00,0,0 3 | 2,1,GweX,1001,sbcH7d,1970-01-01 08:00:10,1,1 4 | 3,2,Vq7f,1002,118jVXn,1970-01-01 08:00:20,2,2 5 | 4,3,OhdG,1003,B4B0,1970-01-01 08:00:30,3,3 6 | 5,4,bmGq,1004,Ba8rt,1970-01-01 08:00:40,4,4 7 | 6,5,POUm,1005,sN0xq1,1970-01-01 08:00:50,5,5 8 | 7,6,uoX8,1006,LtCEkU,1970-01-01 08:01:00,6,6 9 | 8,7,dumL,1007,wHXZ,1970-01-01 08:01:10,7,7 10 | 9,8,BLi3,1008,sMy2F,1970-01-01 08:01:20,8,8 11 | 10,9,Q5bQ,1009,xcKclG,1970-01-01 08:01:30,9,9 -------------------------------------------------------------------------------- /src/test/resources/expect/formula$Sheet1$formulas.txt: -------------------------------------------------------------------------------- 1 | B1=(A1+A2)+1 2 | F1=B2-A2 3 | B2=(A2+A3)+1 4 | B3=(A3+A4)+1 5 | C3=SUM(A1:A10) 6 | B4=(A4+A5)+1 7 | B5=(A5+A6)+1 8 | B6=(A6+A7)+1 9 | B7=(A7+A8)+1 10 | C7=A6 2 | 3 | 5 | 6 | 7 | ${LOG_PATTERN} 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/resources/mark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/mark.png -------------------------------------------------------------------------------- /src/test/resources/merge.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/merge.xlsx -------------------------------------------------------------------------------- /src/test/resources/multi-style In cell.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/multi-style In cell.xlsx -------------------------------------------------------------------------------- /src/test/resources/template.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/template.xlsx -------------------------------------------------------------------------------- /src/test/resources/template2.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/template2.xlsx -------------------------------------------------------------------------------- /src/test/resources/test-fixed-row.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangguanquan/eec/5bdd2a56b0e90f03f484dfee06c8538a2e565358/src/test/resources/test-fixed-row.xlsx -------------------------------------------------------------------------------- /src/test/resources/test.properties: -------------------------------------------------------------------------------- 1 | #sqlite3 2 | dataSource.driverClassName = org.sqlite.JDBC 3 | dataSource.url = jdbc:sqlite:target/eec-test.db 4 | dataSource.username = 5 | dataSource.password = --------------------------------------------------------------------------------