Browse Source

Merge pull request #3440 from alibaba/bugfix

Bugfix
pull/3500/head
Jiaju Zhuang 1 year ago committed by GitHub
parent
commit
e8b79540fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      README.md
  2. 2
      easyexcel-test/pom.xml
  3. 104
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java
  4. 14
      easyexcel-test/src/test/resources/logback.xml

3
README.md

@ -67,13 +67,13 @@ easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析
## 也可以加入钉钉&QQ群来解决问题
加入钉钉或QQ群,看完公告可以获得帮助 。
比较推荐钉钉群,`QQ` 公司不让用,当然QQ群也会有热心网友帮忙解决。
[QQ1群(已满): 662022184](https://jq.qq.com/?_wv=1027&k=1T21jJxh)
[QQ2群(已满): 1097936804](https://jq.qq.com/?_wv=1027&k=j5zEy6Xl)
[QQ3群(已满): 453928496](https://qm.qq.com/cgi-bin/qm/qr?k=e2ULsA5A0GldhV2CXJ8sIbAyu9I6qqs7&jump_from=webapi)
[QQ4群(已满): 496594404](https://qm.qq.com/cgi-bin/qm/qr?k=e_aVG1Q7gi0PJUBkbrUGAgbeO3kUEInK&jump_from=webapi)
[QQ5群(已满): 451925680](https://jq.qq.com/?_wv=1027&k=6VHhvxyf)
[QQ6群: 784741035](https://jq.qq.com/?_wv=1027&k=BbLBIo9P)
[QQ7群: 667889383](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=XdTLw3Z3pr63VT0IkyoY-2t25TG7WxbG&authKey=gQKvTXipsjfUO1aNfL9zdHTfOmkqC6E%2BQ2zDg2jym8h3qXuQ7RtkpeAHeg9I4UhL&noverify=0&group_code=667889383)
[钉钉1群(已满): 21960511](https://qr.dingtalk.com/action/joingroup?code=v1,k1,cchz6k12ci9B08NNqhNRFGXocNVHrZtW0kaOtTKg/Rk=&_dt_no_comment=1&origin=11)
[钉钉2群(已满): 32796397](https://qr.dingtalk.com/action/joingroup?code=v1,k1,jyU9GtEuNU5S0QTyklqYcYJ8qDZtUuTPMM7uPZTS8Hs=&_dt_no_comment=1&origin=11)
[钉钉3群(已满): 33797247](https://qr.dingtalk.com/action/joingroup?code=v1,k1,3UGlEScTGQaHpW2cIRo+gkxJ9EVZ5fz26M6nW3uFP30=&_dt_no_comment=1&origin=11)
@ -85,6 +85,7 @@ easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析
[钉钉9群(已满): 11045002277](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dinge338d2215891c0459c13cd6b2cb108a6&6972d=b92f9&cbdbhh=qwertyuiop)
[钉钉10群(已满): 27360019755](https://qr.dingtalk.com/action/joingroup?code=v1,k1,v25LHn2liWmrWUKlkhIzOTcK7s7onp/sZP8mO5oIYSs=&_dt_no_comment=1&origin=11)
[钉钉11群:24330026964](https://qr.dingtalk.com/action/joingroup?code=v1,k1,63PjvTncu81oQ3X6XmGEJqnwQHCQxi/jaVlbUStq79o=&_dt_no_comment=1&origin=11)
[钉钉12群:27210038956](https://qr.dingtalk.com/action/joingroup?code=v1,k1,3mKi7VTGlYO+IsDX5n7sYYm2Qrlm220kMBPsJFzKRis=&_dt_no_comment=1&origin=11)
# 维护者

2
easyexcel-test/pom.xml

@ -60,7 +60,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.7</version>
<version>1.2.12</version>
</dependency>
</dependencies>

104
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java

@ -1,17 +1,35 @@
package com.alibaba.easyexcel.test.temp;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.easyexcel.test.core.large.LargeData;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
import org.apache.poi.hssf.eventusermodel.HSSFListener;
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.BoundSheetRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.SSTRecord;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.junit.jupiter.api.Test;
@ -24,6 +42,7 @@ import org.slf4j.LoggerFactory;
* @author Jiaju Zhuang
**/
@Slf4j
public class WriteLargeTest {
private static final Logger LOGGER = LoggerFactory.getLogger(WriteLargeTest.class);
@ -64,6 +83,91 @@ public class WriteLargeTest {
}
@Test
public void read() throws Exception {
log.info("start");
String fileName = "/Users/zhuangjiaju/Downloads/1e9e0578a9634abbbbd9b67f338f142a.xls";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
// 这里默认每次会读取100条数据 然后返回过来 直接调用使用数据就行
// 具体需要返回多少行可以在`PageReadListener`的构造函数设置
EasyExcel.read(fileName, new PageReadListener<List<Map<String, String>>>(dataList -> {
log.info("SIZEL:{}", dataList.size());
})).sheet().doRead();
log.info("test");
}
@Test
public void read2() throws Exception {
// 使用输入的文件创建一个新的文件输入流
//FileInputStream fin = new FileInputStream("/Users/zhuangjiaju/Downloads/1e9e0578a9634abbbbd9b67f338f142a
// .xls");
// 创建一个新的org.apache.poi.poifs.filesystem.Filesystem
POIFSFileSystem poifs = new POIFSFileSystem(
new File("/Users/zhuangjiaju/Downloads/1e9e0578a9634abbbbd9b67f338f142a.xls"));
// 在InputStream中获取Workbook流
InputStream din = poifs.createDocumentInputStream("Workbook");
// 构造出HSSFRequest对象
HSSFRequest req = new HSSFRequest();
// 注册全部的监听器
req.addListenerForAllRecords(new EventExample());
// 创建事件工厂
HSSFEventFactory factory = new HSSFEventFactory();
// 根据文档输入流处理我们监听的事件
factory.processEvents(req, din);
// 关闭文件输入流
//fin.close();
// 关闭文档输入流
din.close();
System.out.println("读取结束");
}
@Test
public void read3() throws Exception {
HSSFWorkbook hwb = new HSSFWorkbook(
new FileInputStream("/Users/zhuangjiaju/Downloads/1e9e0578a9634abbbbd9b67f338f142a.xls"));
HSSFSheet sheet = hwb.getSheetAt(0);
HSSFRow row = null;
HSSFCell cell = null;
for (int i = sheet.getFirstRowNum(); i <= sheet.getPhysicalNumberOfRows(); i++) {
row = sheet.getRow(i);
if(row!=null){
log.info("r:{}",row.getRowNum());
}
}
log.info("end");
}
public static class EventExample implements HSSFListener {
private SSTRecord sstrec;
/**
* 此方法监听传入记录并根据需要处理它们
*
* @param record读取时找到的记录
*/
public void processRecord(Record record) {
switch (record.getSid()) {
//BOFRecord可以表示工作表或工作簿的开头
case BOFRecord.sid:
BOFRecord bof = (BOFRecord)record;
if (bof.getType() == bof.TYPE_WORKBOOK) {
System.out.println("监听到工作表");
} else if (bof.getType() == bof.TYPE_WORKSHEET) {
System.out.println("监听到工作簿");
}
break;
case BoundSheetRecord.sid:
BoundSheetRecord bsr = (BoundSheetRecord)record;
System.out.println("工作簿名称: " + bsr.getSheetname());
break;
}
}
}
@Test
public void test2() throws Exception {
// 方法2 如果写到不同的sheet 同一个对象

14
easyexcel-test/src/test/resources/logback.xml

@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread] %class:%line - %msg%n"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}</pattern>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
<appender-ref ref="CONSOLE"/>
</root>
</configuration>

Loading…
Cancel
Save