>
-```
-ExcelListener excelListener = new ExcelListener();
-EasyExcelFactory.readBySax(inputStream, new Sheet(1, 1), excelListener);
+```java
+ /**
+ * 最简单的读
+ * 1. 创建excel对应的实体对象 参照{@link DemoData}
+ *
2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
+ *
3. 直接读即可
+ */
+ @Test
+ public void simpleRead() {
+ String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
+ // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
+ EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();
+ }
```
-读07版大于1000行数据返回List extend BaseRowModel>
-```
-ExcelListener excelListener = new ExcelListener();
-EasyExcelFactory.readBySax(inputStream, new Sheet(2, 1,JavaModel.class), excelListener);
-```
-读03版方法同上
### 写Excel
-测试代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/WriteTest.java](/src/test/java/com/alibaba/easyexcel/test/WriteTest.java)
-没有模板
-```OutputStream out = new FileOutputStream("/Users/jipengfei/2007.xlsx");
-ExcelWriter writer = EasyExcelFactory.getWriter(out);
-
-//写第一个sheet, sheet1 数据全是List 无模型映射关系
-Sheet sheet1 = new Sheet(1, 3);
-sheet1.setSheetName("第一个sheet");
-//设置列宽 设置每列的宽度
-Map columnWidth = new HashMap();
-columnWidth.put(0,10000);columnWidth.put(1,40000);columnWidth.put(2,10000);columnWidth.put(3,10000);
-sheet1.setColumnWidthMap(columnWidth);
-sheet1.setHead(createTestListStringHead());
-//or 设置自适应宽度
-//sheet1.setAutoWidth(Boolean.TRUE);
-writer.write1(createTestListObject(), sheet1);
-
-//写第二个sheet sheet2 模型上打有表头的注解,合并单元格
-Sheet sheet2 = new Sheet(2, 3, JavaModel1.class, "第二个sheet", null);
-sheet2.setTableStyle(createTableStyle());
-writer.write(createTestListJavaMode(), sheet2);
-
-//写第三个sheet包含多个table情况
-Sheet sheet3 = new Sheet(3, 0);
-sheet3.setSheetName("第三个sheet");
-Table table1 = new Table(1);
-table1.setHead(createTestListStringHead());
-writer.write1(createTestListObject(), sheet3, table1);
-
-//写sheet2 模型上打有表头的注解
-Table table2 = new Table(2);
-table2.setTableStyle(createTableStyle());
-table2.setClazz(JavaModel1.class);
-writer.write(createTestListJavaMode(), sheet3, table2);
-
-//关闭资源
-writer.finish();
-out.close();
-```
-有模板
-```InputStream inputStream = new BufferedInputStream(new FileInputStream("/Users/jipengfei/temp.xlsx"));
-OutputStream out = new FileOutputStream("/Users/jipengfei/2007.xlsx");
-ExcelWriter writer = EasyExcelFactory.getWriterWithTemp(inputStream,out,ExcelTypeEnum.XLSX,true);
-
-//写第一个sheet, sheet1 数据全是List 无模型映射关系
-Sheet sheet1 = new Sheet(1, 3);
-sheet1.setSheetName("第一个sheet");
-//设置列宽 设置每列的宽度
-Map columnWidth = new HashMap();
-columnWidth.put(0,10000);columnWidth.put(1,40000);columnWidth.put(2,10000);columnWidth.put(3,10000);
-sheet1.setColumnWidthMap(columnWidth);
-sheet1.setHead(createTestListStringHead());
-//or 设置自适应宽度
-//sheet1.setAutoWidth(Boolean.TRUE);
-writer.write1(createTestListObject(), sheet1);
-
-//写第二个sheet sheet2 模型上打有表头的注解,合并单元格
-Sheet sheet2 = new Sheet(2, 3, JavaModel1.class, "第二个sheet", null);
-sheet2.setTableStyle(createTableStyle());
-writer.write(createTestListJavaMode(), sheet2);
-
-//写第三个sheet包含多个table情况
-Sheet sheet3 = new Sheet(3, 0);
-sheet3.setSheetName("第三个sheet");
-Table table1 = new Table(1);
-table1.setHead(createTestListStringHead());
-writer.write1(createTestListObject(), sheet3, table1);
-
-//写sheet2 模型上打有表头的注解
-Table table2 = new Table(2);
-table2.setTableStyle(createTableStyle());
-table2.setClazz(JavaModel1.class);
-writer.write(createTestListJavaMode(), sheet3, table2);
-
-//关闭资源
-writer.finish();
-out.close();
+DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java](/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java)
+```java
+ /**
+ * 最简单的写
+ * 1. 创建excel对应的实体对象 参照{@link com.alibaba.easyexcel.test.demo.write.DemoData}
+ *
2. 直接写即可
+ */
+ @Test
+ public void simpleWrite() {
+ String fileName = TestFileUtil.getPath() + "write" + System.currentTimeMillis() + ".xlsx";
+ // 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
+ // 如果这里想使用03 则 传入excelType参数即可
+ EasyExcel.write(fileName, DemoData.class).sheet("模板").doWrite(data());
+ }
```
-### web下载实例写法
-```
-public class Down {
- @GetMapping("/a.htm")
- public void cooperation(HttpServletRequest request, HttpServletResponse response) {
- ServletOutputStream out = response.getOutputStream();
- response.setContentType("multipart/form-data");
+### web上传、下载
+DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java](/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java)
+```java
+ /**
+ * 文件下载
+ *
1. 创建excel对应的实体对象 参照{@link DownloadData}
+ *
2. 设置返回的 参数
+ *
3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
+ */
+ @GetMapping("download")
+ public void download(HttpServletResponse response) throws IOException {
+ response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
- response.setHeader("Content-disposition", "attachment;filename="+fileName+".xlsx");
- ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX, true);
- String fileName = new String(("UserInfo " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
- .getBytes(), "UTF-8");
- Sheet sheet1 = new Sheet(1, 0);
- sheet1.setSheetName("第一个sheet");
- writer.write0(getListString(), sheet1);
- writer.finish();
-
- out.flush();
- }
+ response.setHeader("Content-disposition", "attachment;filename=demo.xlsx");
+ EasyExcel.write(response.getOutputStream(), DownloadData.class).sheet("模板").doWrite(data());
+ }
+
+ /**
+ * 文件上传
+ *
1. 创建excel对应的实体对象 参照{@link UploadData}
+ *
2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link UploadDataListener}
+ *
3. 直接读即可
+ */
+ @PostMapping("upload")
+ @ResponseBody
+ public String upload(MultipartFile file) throws IOException {
+ EasyExcel.read(file.getInputStream(), UploadData.class, new UploadDataListener()).sheet().doRead();
+ return "success";
}
-}
```
### 联系我们
有问题阿里同事可以通过钉钉找到我,阿里外同学可以通过git留言。其他技术非技术相关的也欢迎一起探讨。
### 招聘&交流
-阿里巴巴新零售事业部--诚招JAVA资深开发、技术专家。有意向可以微信联系,简历可以发我邮箱jipengfei.jpf@alibaba-inc.com
-或者加QQ群: 662022184
+阿里巴巴新零售事业部--诚招JAVA资深开发、技术专家。有意向可以微信联系,简历可以发我邮箱jipengfei.jpf@alibaba-inc.com
\ No newline at end of file
diff --git a/img/WechatIMG8.png b/img/WechatIMG8.png
deleted file mode 100644
index a87e52e..0000000
Binary files a/img/WechatIMG8.png and /dev/null differ
diff --git a/img/readme/quickstart/read/demo.png b/img/readme/quickstart/read/demo.png
new file mode 100644
index 0000000..8bd1413
Binary files /dev/null and b/img/readme/quickstart/read/demo.png differ
diff --git a/img/readme/quickstart/write/complexHeadWrite.png b/img/readme/quickstart/write/complexHeadWrite.png
new file mode 100644
index 0000000..995ffc3
Binary files /dev/null and b/img/readme/quickstart/write/complexHeadWrite.png differ
diff --git a/img/readme/quickstart/write/converterWrite.png b/img/readme/quickstart/write/converterWrite.png
new file mode 100644
index 0000000..5c9f289
Binary files /dev/null and b/img/readme/quickstart/write/converterWrite.png differ
diff --git a/img/readme/quickstart/write/customHandlerWrite.png b/img/readme/quickstart/write/customHandlerWrite.png
new file mode 100644
index 0000000..41916c3
Binary files /dev/null and b/img/readme/quickstart/write/customHandlerWrite.png differ
diff --git a/img/readme/quickstart/write/dynamicHeadWrite.png b/img/readme/quickstart/write/dynamicHeadWrite.png
new file mode 100644
index 0000000..3b25ad7
Binary files /dev/null and b/img/readme/quickstart/write/dynamicHeadWrite.png differ
diff --git a/img/readme/quickstart/write/imageWrite.png b/img/readme/quickstart/write/imageWrite.png
new file mode 100644
index 0000000..c6a0c67
Binary files /dev/null and b/img/readme/quickstart/write/imageWrite.png differ
diff --git a/img/readme/quickstart/write/indexWrite.png b/img/readme/quickstart/write/indexWrite.png
new file mode 100644
index 0000000..8dbec17
Binary files /dev/null and b/img/readme/quickstart/write/indexWrite.png differ
diff --git a/img/readme/quickstart/write/longestMatchColumnWidthWrite.png b/img/readme/quickstart/write/longestMatchColumnWidthWrite.png
new file mode 100644
index 0000000..c8a0604
Binary files /dev/null and b/img/readme/quickstart/write/longestMatchColumnWidthWrite.png differ
diff --git a/img/readme/quickstart/write/mergeWrite.png b/img/readme/quickstart/write/mergeWrite.png
new file mode 100644
index 0000000..b631e59
Binary files /dev/null and b/img/readme/quickstart/write/mergeWrite.png differ
diff --git a/img/readme/quickstart/write/repeatedWrite.png b/img/readme/quickstart/write/repeatedWrite.png
new file mode 100644
index 0000000..fb204a4
Binary files /dev/null and b/img/readme/quickstart/write/repeatedWrite.png differ
diff --git a/img/readme/quickstart/write/simpleWrite.png b/img/readme/quickstart/write/simpleWrite.png
new file mode 100644
index 0000000..e5924b1
Binary files /dev/null and b/img/readme/quickstart/write/simpleWrite.png differ
diff --git a/img/readme/quickstart/write/styleWrite.png b/img/readme/quickstart/write/styleWrite.png
new file mode 100644
index 0000000..356c3a7
Binary files /dev/null and b/img/readme/quickstart/write/styleWrite.png differ
diff --git a/img/readme/quickstart/write/tableWrite.png b/img/readme/quickstart/write/tableWrite.png
new file mode 100644
index 0000000..0006a9e
Binary files /dev/null and b/img/readme/quickstart/write/tableWrite.png differ
diff --git a/img/readme/quickstart/write/templateWrite.png b/img/readme/quickstart/write/templateWrite.png
new file mode 100644
index 0000000..75f7cb1
Binary files /dev/null and b/img/readme/quickstart/write/templateWrite.png differ
diff --git a/img/readme/quickstart/write/widthAndHeightWrite.png b/img/readme/quickstart/write/widthAndHeightWrite.png
new file mode 100644
index 0000000..d59d897
Binary files /dev/null and b/img/readme/quickstart/write/widthAndHeightWrite.png differ
diff --git a/img/readme/wechat.png b/img/readme/wechat.png
new file mode 100644
index 0000000..b805760
Binary files /dev/null and b/img/readme/wechat.png differ
diff --git a/img/style/eclipse/step.jpg b/img/style/eclipse/step.jpg
new file mode 100644
index 0000000..fcbb857
Binary files /dev/null and b/img/style/eclipse/step.jpg differ
diff --git a/img/style/idea/step1.png b/img/style/idea/step1.png
new file mode 100644
index 0000000..d4a39f5
Binary files /dev/null and b/img/style/idea/step1.png differ
diff --git a/img/style/idea/step2.png b/img/style/idea/step2.png
new file mode 100644
index 0000000..2dd0414
Binary files /dev/null and b/img/style/idea/step2.png differ
diff --git a/img/style/idea/step3.png b/img/style/idea/step3.png
new file mode 100644
index 0000000..2fbde4a
Binary files /dev/null and b/img/style/idea/step3.png differ
diff --git a/mvnw b/mvnw
new file mode 100644
index 0000000..d560832
--- /dev/null
+++ b/mvnw
@@ -0,0 +1,305 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven2 Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+# JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+# M2_HOME - location of maven2's installed home dir
+# MAVEN_OPTS - parameters passed to the Java VM when running Maven
+# e.g. to debug Maven itself, use
+# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+ if [ -f /etc/mavenrc ] ; then
+ . /etc/mavenrc
+ fi
+
+ if [ -f "$HOME/.mavenrc" ] ; then
+ . "$HOME/.mavenrc"
+ fi
+
+fi
+
+# OS specific support. $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+ CYGWIN*) cygwin=true ;;
+ MINGW*) mingw=true;;
+ Darwin*) darwin=true
+ # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
+ # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
+ if [ -z "$JAVA_HOME" ]; then
+ if [ -x "/usr/libexec/java_home" ]; then
+ export JAVA_HOME="`/usr/libexec/java_home`"
+ else
+ export JAVA_HOME="/Library/Java/Home"
+ fi
+ fi
+ ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+ if [ -r /etc/gentoo-release ] ; then
+ JAVA_HOME=`java-config --jre-home`
+ fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+ ## resolve links - $0 may be a link to maven's home
+ PRG="$0"
+
+ # need this for relative symlinks
+ while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG="`dirname "$PRG"`/$link"
+ fi
+ done
+
+ saveddir=`pwd`
+
+ M2_HOME=`dirname "$PRG"`/..
+
+ # make it fully qualified
+ M2_HOME=`cd "$M2_HOME" && pwd`
+
+ cd "$saveddir"
+ # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --unix "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Mingw, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME="`(cd "$M2_HOME"; pwd)`"
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+ javaExecutable="`which javac`"
+ if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+ # readlink(1) is not available as standard on Solaris 10.
+ readLink=`which readlink`
+ if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+ if $darwin ; then
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+ else
+ javaExecutable="`readlink -f \"$javaExecutable\"`"
+ fi
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+ JAVA_HOME="$javaHome"
+ export JAVA_HOME
+ fi
+ fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+ if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ else
+ JAVACMD="`which java`"
+ fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+ echo "Error: JAVA_HOME is not defined correctly." >&2
+ echo " We cannot execute $JAVACMD" >&2
+ exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+ echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+
+ if [ -z "$1" ]
+ then
+ echo "Path not specified to find_maven_basedir"
+ return 1
+ fi
+
+ basedir="$1"
+ wdir="$1"
+ while [ "$wdir" != '/' ] ; do
+ if [ -d "$wdir"/.mvn ] ; then
+ basedir=$wdir
+ break
+ fi
+ # workaround for JBEAP-8937 (on Solaris 10/Sparc)
+ if [ -d "${wdir}" ]; then
+ wdir=`cd "$wdir/.."; pwd`
+ fi
+ # end of workaround
+ done
+ echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+ if [ -f "$1" ]; then
+ echo "$(tr -s '\n' ' ' < "$1")"
+ fi
+}
+
+BASE_DIR=`find_maven_basedir "$(pwd)"`
+if [ -z "$BASE_DIR" ]; then
+ exit 1;
+fi
+
+##########################################################################################
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
+##########################################################################################
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found .mvn/wrapper/maven-wrapper.jar"
+ fi
+else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
+ fi
+ if [ -n "$MVNW_REPOURL" ]; then
+ jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
+ else
+ jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
+ fi
+ while IFS="=" read key value; do
+ case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
+ esac
+ done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Downloading from: $jarUrl"
+ fi
+ wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
+ if $cygwin; then
+ wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
+ fi
+
+ if command -v wget > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found wget ... using wget"
+ fi
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ wget "$jarUrl" -O "$wrapperJarPath"
+ else
+ wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
+ fi
+ elif command -v curl > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found curl ... using curl"
+ fi
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ curl -o "$wrapperJarPath" "$jarUrl" -f
+ else
+ curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
+ fi
+
+ else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Falling back to using Java to download"
+ fi
+ javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
+ # For Cygwin, switch paths to Windows format before running javac
+ if $cygwin; then
+ javaClass=`cygpath --path --windows "$javaClass"`
+ fi
+ if [ -e "$javaClass" ]; then
+ if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Compiling MavenWrapperDownloader.java ..."
+ fi
+ # Compiling the Java class
+ ("$JAVA_HOME/bin/javac" "$javaClass")
+ fi
+ if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ # Running the downloader
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Running MavenWrapperDownloader.java ..."
+ fi
+ ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
+ fi
+ fi
+ fi
+fi
+##########################################################################################
+# End of extension
+##########################################################################################
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
+if [ "$MVNW_VERBOSE" = true ]; then
+ echo $MAVEN_PROJECTBASEDIR
+fi
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --path --windows "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+ [ -n "$MAVEN_PROJECTBASEDIR" ] &&
+ MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
+fi
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+ $MAVEN_OPTS \
+ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+ "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+ ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
diff --git a/mvnw.cmd b/mvnw.cmd
new file mode 100644
index 0000000..d06ac67
--- /dev/null
+++ b/mvnw.cmd
@@ -0,0 +1,172 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM https://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Maven2 Start Up Batch script
+@REM
+@REM Required ENV vars:
+@REM JAVA_HOME - location of a JDK home dir
+@REM
+@REM Optional ENV vars
+@REM M2_HOME - location of maven2's installed home dir
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
+@REM e.g. to debug Maven itself, use
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+@REM ----------------------------------------------------------------------------
+
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
+@echo off
+@REM set title of command window
+title %0
+@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
+@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
+
+@REM set %HOME% to equivalent of $HOME
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
+
+@REM Execute a user defined script before this one
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
+if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
+:skipRcPre
+
+@setlocal
+
+set ERROR_CODE=0
+
+@REM To isolate internal variables from possible post scripts, we use another setlocal
+@setlocal
+
+@REM ==== START VALIDATION ====
+if not "%JAVA_HOME%" == "" goto OkJHome
+
+echo.
+echo Error: JAVA_HOME not found in your environment. >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+:OkJHome
+if exist "%JAVA_HOME%\bin\java.exe" goto init
+
+echo.
+echo Error: JAVA_HOME is set to an invalid directory. >&2
+echo JAVA_HOME = "%JAVA_HOME%" >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+@REM ==== END VALIDATION ====
+
+:init
+
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
+@REM Fallback to current working directory if not found.
+
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
+
+set EXEC_DIR=%CD%
+set WDIR=%EXEC_DIR%
+:findBaseDir
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
+cd ..
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
+set WDIR=%CD%
+goto findBaseDir
+
+:baseDirFound
+set MAVEN_PROJECTBASEDIR=%WDIR%
+cd "%EXEC_DIR%"
+goto endDetectBaseDir
+
+:baseDirNotFound
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
+cd "%EXEC_DIR%"
+
+:endDetectBaseDir
+
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
+
+@setlocal EnableExtensions EnableDelayedExpansion
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
+
+:endReadAdditionalConfig
+
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
+
+FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
+ IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
+)
+
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
+if exist %WRAPPER_JAR% (
+ echo Found %WRAPPER_JAR%
+) else (
+ if not "%MVNW_REPOURL%" == "" (
+ SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
+ )
+ echo Couldn't find %WRAPPER_JAR%, downloading it ...
+ echo Downloading from: %DOWNLOAD_URL%
+
+ powershell -Command "&{"^
+ "$webclient = new-object System.Net.WebClient;"^
+ "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
+ "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
+ "}"^
+ "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
+ "}"
+ echo Finished downloading %WRAPPER_JAR%
+)
+@REM End of extension
+
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
+if ERRORLEVEL 1 goto error
+goto end
+
+:error
+set ERROR_CODE=1
+
+:end
+@endlocal & set ERROR_CODE=%ERROR_CODE%
+
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
+:skipRcPost
+
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
+
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
+
+exit /B %ERROR_CODE%
diff --git a/pom.xml b/pom.xml
index f0270b6..f85fd40 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,10 +1,10 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.alibaba
easyexcel
- 1.1.2-beta5
+ 2.0.0-beta1
jar
easyexcel
@@ -26,11 +26,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -59,25 +59,65 @@
org.apache.poi
poi
- 3.17
+ 4.0.1
org.apache.poi
poi-ooxml
- 3.17
+ 4.0.1
cglib
cglib
3.1
+
+ org.slf4j
+ slf4j-api
+ 1.7.26
+
+
+ org.ehcache
+ ehcache
+ 3.7.1
+
+
+
+ ch.qos.logback
+ logback-classic
+ 1.2.3
+ test
+
+
+ com.alibaba
+ fastjson
+ 1.2.58
+ test
+
+
+ org.projectlombok
+ lombok
+ 1.18.8
+ test
+
+
+ org.springframework.boot
+ spring-boot
+ 1.5.21.RELEASE
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ 1.5.21.RELEASE
+ test
+
junit
junit
4.12
test
-
@@ -92,6 +132,48 @@
+
+
+ org.apache.maven.plugins
+ maven-pmd-plugin
+ 3.12.0
+
+ true
+ true
+
+ rulesets/java/ali-comment.xml
+ rulesets/java/ali-concurrent.xml
+ rulesets/java/ali-constant.xml
+ rulesets/java/ali-exception.xml
+ rulesets/java/ali-flowcontrol.xml
+ rulesets/java/ali-naming.xml
+ rulesets/java/ali-oop.xml
+ rulesets/java/ali-orm.xml
+ rulesets/java/ali-other.xml
+ rulesets/java/ali-set.xml
+
+
+ com/alibaba/excel/event/AnalysisEventListener.java
+
+
+
+
+
+ pmd-check-verify
+ validate
+
+ check
+
+
+
+
+
+ com.alibaba.p3c
+ p3c-pmd
+ 2.0.0
+
+
+
org.apache.maven.plugins
maven-compiler-plugin
@@ -132,7 +214,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 2.9.1
+ 3.1.0
attach-javadocs
@@ -144,4 +226,4 @@
-
\ No newline at end of file
+
diff --git a/quickstart.md b/quickstart.md
index afba795..6312800 100644
--- a/quickstart.md
+++ b/quickstart.md
@@ -1,365 +1,902 @@
# easyexcel核心功能
+## 目录
+### 读
+DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/demo/read/ReadTest.java](/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java)
+* [最简单的读](#simpleRead)
+* [指定列的下标或者列名](#indexOrNameRead)
+* [读多个sheet](#repeatedRead)
+* [日期、数字或者自定义格式转换](#converterRead)
+* [多行头](#complexHeaderRead)
+* [同步的返回](#synchronousRead)
+* [web中的读](#webRead)
+### 写
+DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java](/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java)
+* [最简单的写](#simpleWrite)
+* [指定写入的列](#indexWrite)
+* [复杂头写入](#complexHeadWrite)
+* [重复多次写入](#repeatedWrite)
+* [日期、数字或者自定义格式转换](#converterWrite)
+* [图片导出](#imageWrite)
+* [根据模板写入](#templateWrite)
+* [列宽、行高](#widthAndHeightWrite)
+* [自定义样式](#styleWrite)
+* [合并单元格](#mergeWrite)
+* [使用table去写入](#tableWrite)
+* [动态头,实时生成头写入](#dynamicHeadWrite)
+* [自动列宽(不太精确)](#longestMatchColumnWidthWrite)
+* [自定义拦截器(下拉,超链接等上面几点都不符合但是要对单元格进行操作的参照这个)](#customHandlerWrite)
+* [web中的写](#webWrite)
+
+## 读excel样例
+### 最简单的读
+##### excel示例
+![img](img/readme/quickstart/read/demo.png)
+##### 对象
+```java
+@Data
+public class DemoData {
+ private String string;
+ private Date date;
+ private Double doubleData;
+}
+```
+##### 监听器
+```java
+public class DemoDataListener extends AnalysisEventListener {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class);
+ /**
+ * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
+ */
+ private static final int BATCH_COUNT = 5;
+ List list = new ArrayList();
+
+ @Override
+ public void invoke(DemoData data, AnalysisContext context) {
+ LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data));
+ list.add(data);
+ if (list.size() >= BATCH_COUNT) {
+ saveData();
+ list.clear();
+ }
+ }
-## *读任意大小的03、07版Excel不会OO]
-## *读Excel自动通过注解,把结果映射为java模型
-## *读Excel支持多sheet
-## *读Excel时候是否对Excel内容做trim()增加容错
-## *写小量数据的03版Excel(不要超过2000行)
-## *写任意大07版Excel不会OOM
-## *写Excel通过注解将表头自动写入Excel
-## *写Excel可以自定义Excel样式 如:字体,加粗,表头颜色,数据内容颜色
-## *写Excel到多个不同sheet
-## *写Excel时一个sheet可以写多个Table
-## *写Excel时候自定义是否需要写表头
-
-## 二方包依赖
-
-使用前最好咨询下最新版,或者到mvn仓库搜索先easyexcel的最新版
+ @Override
+ public void doAfterAllAnalysed(AnalysisContext context) {
+ saveData();
+ LOGGER.info("所有数据解析完成!");
+ }
+ /**
+ * 加上存储数据库
+ */
+ private void saveData() {
+ LOGGER.info("{}条数据,开始存储数据库!", list.size());
+ LOGGER.info("存储数据库成功!");
+ }
+}
```
-
- com.alibaba
- easyexcel
- 1.0.0-RELEASE
-
+##### 代码
+```java
+ /**
+ * 最简单的读
+ * 1. 创建excel对应的实体对象 参照{@link DemoData}
+ *
2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
+ *
3. 直接读即可
+ */
+ @Test
+ public void simpleRead() {
+ // 写法1:
+ String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
+ // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
+ EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();
+
+ // 写法2:
+ fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
+ ExcelReader excelReader = EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).build();
+ ReadSheet readSheet = EasyExcel.readSheet(0).build();
+ excelReader.read(readSheet);
+ // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
+ excelReader.finish();
+ }
```
-## 读Excel
-使用easyexcel解析03、07版本的Excel只是ExcelTypeEnum不同,其他使用完全相同,使用者无需知道底层解析的差异。
-
-### 无java模型直接把excel解析的每行结果以List<String>返回 在ExcelListener获取解析结果
-
-读excel代码示例如下:
+### 指定列的下标或者列名
+##### excel示例
+参照:[excel示例](#simpleReadExcel)
+##### 对象
+```java
+@Data
+public class IndexOrNameData {
+ /**
+ * 强制读取第三个 这里不建议 index 和 name 同时用,要么一个对象只用index,要么一个对象只用name去匹配
+ */
+ @ExcelProperty(index = 2)
+ private Double doubleData;
+ /**
+ * 用名字去匹配,这里需要注意,如果名字重复,会导致只有一个字段读取到数据
+ */
+ @ExcelProperty("字符串标题")
+ private String string;
+ @ExcelProperty("日期标题")
+ private Date date;
+}
```
+##### 监听器
+参照:[监听器](#simpleReadListener) 只是泛型变了而已
+##### 代码
+```java
+ /**
+ * 指定列的下标或者列名
+ *
+ *
1. 创建excel对应的实体对象,并使用{@link ExcelProperty}注解. 参照{@link IndexOrNameData}
+ *
2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link IndexOrNameDataListener}
+ *
3. 直接读即可
+ */
@Test
- public void testExcel2003NoModel() {
- InputStream inputStream = getInputStream("loan1.xls");
- try {
- // 解析每行结果在listener中处理
- ExcelListener listener = new ExcelListener();
-
- ExcelReader excelReader = new ExcelReader(inputStream, ExcelTypeEnum.XLS, null, listener);
- excelReader.read();
- } catch (Exception e) {
-
- } finally {
- try {
- inputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ public void indexOrNameRead() {
+ String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
+ // 这里默认读取第一个sheet
+ EasyExcel.read(fileName, IndexOrNameData.class, new IndexOrNameDataListener()).sheet().doRead();
}
```
-ExcelListener示例代码如下:
-```
- /* 解析监听器,
- * 每解析一行会回调invoke()方法。
- * 整个excel解析结束会执行doAfterAllAnalysed()方法
- *
- * 下面只是我写的一个样例而已,可以根据自己的逻辑修改该类。
- * @author jipengfei
- * @date 2017/03/14
- */
-public class ExcelListener extends AnalysisEventListener {
- //自定义用于暂时存储data。
- //可以通过实例获取该值
- private List