Skip to content

Commit

Permalink
⚡ improving performance
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Mar 20, 2018
1 parent 667d90a commit 55f334f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package io.github.biezhi.excel.plus.writer;

import io.github.biezhi.excel.plus.Constant;
import io.github.biezhi.excel.plus.enums.ExcelType;
import io.github.biezhi.excel.plus.exception.ExcelException;
import io.github.biezhi.excel.plus.utils.ExcelUtils;
import io.github.biezhi.excel.plus.utils.Pair;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.InputStream;
import java.io.OutputStream;
Expand Down
34 changes: 22 additions & 12 deletions src/test/java/io/github/biezhi/excel/plus/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -28,23 +30,31 @@ public class Examples {

private ExcelPlus excelPlus = new ExcelPlus();

private InputStream getCardStream() {
return Examples.class.getResourceAsStream("/卡密列表.xlsx");
}

@Test
public void testReadExcel() throws ExcelException {
List<CardSecret> cardSecrets = excelPlus.read(new File("卡密列表.xls"), CardSecret.class).asList();
System.out.println(cardSecrets);

List<CardSecret> cardSecrets = excelPlus.read(getCardStream(), CardSecret.class).asList();
Assert.assertNotNull(cardSecrets);
Assert.assertEquals(4, cardSecrets.size());
}

@Test
public void testReadFilter() throws ExcelException {
List<CardSecret> cardSecrets = excelPlus.read(new File("卡密列表.xls"), CardSecret.class)
.filter(cardSecret -> cardSecret.getAmount().doubleValue() > 10)
List<CardSecret> cardSecrets = excelPlus.read(getCardStream(), CardSecret.class)
.filter(cardSecret -> cardSecret.getAmount().doubleValue() > 50)
.asList();
System.out.println(cardSecrets);

Assert.assertNotNull(cardSecrets);
Assert.assertEquals(3, cardSecrets.size());
}

@Test
public void testReadValid() throws ExcelException {
ExcelResult<CardSecret> excelResult = excelPlus.read(new File("卡密列表.xls"), CardSecret.class)
ExcelResult<CardSecret> excelResult = excelPlus.read(getCardStream(), CardSecret.class)
.startRow(2)
.valid(cardSecret -> {
BigDecimal amount = cardSecret.getAmount();
Expand All @@ -58,16 +68,16 @@ public void testReadValid() throws ExcelException {
if (!excelResult.isValid()) {
excelResult.errors().forEach(System.out::println);
} else {
System.out.println(excelResult.rows().size());
Assert.assertEquals(3, excelResult.rows().size());
}
}

@Test
public void testReadCounter() throws ExcelException {
ExcelResult<CardSecret> excelResult = excelPlus.read(new File("卡密列表.xls"), CardSecret.class)
ExcelResult<CardSecret> excelResult = excelPlus.read(getCardStream(), CardSecret.class)
.startRow(2)
.valid(cardSecret -> {
if(cardSecret.getCardType().equals(1)){
if (cardSecret.getCardType().equals(1)) {
return ValidRow.ok().addCounter("CARD_TYPE_1");
}
return ValidRow.ok();
Expand All @@ -77,14 +87,14 @@ public void testReadCounter() throws ExcelException {
if (!excelResult.isValid()) {
excelResult.errors().forEach(System.out::println);
} else {
System.out.println(excelResult.rows().size());
Assert.assertEquals(3, excelResult.rows().size());
}
}

@Test
public void testExport() throws ExcelException {
List<CardSecret> cardSecrets = this.buildCardSecrets();
excelPlus.export(cardSecrets).writeAsFile(new File("卡密列表.xls"));
excelPlus.export(cardSecrets).writeAsFile(new File("export.xls"));
}

@Test
Expand Down Expand Up @@ -128,7 +138,7 @@ public void testExportByTpl() throws ExcelException {
).writeAsFile(new File("template_rows.xls"));
}

@Test
// @Test
public void testDownload() throws ExcelException {
List<CardSecret> cardSecrets = this.buildCardSecrets();
excelPlus.export(cardSecrets).writeAsResponse(ResponseWrapper.create(null, "xxx表格.xls"));
Expand Down
Binary file added src/test/resources/卡密列表.xlsx
Binary file not shown.

0 comments on commit 55f334f

Please sign in to comment.