Skip to content

Commit 4a14296

Browse files
committed
优化
1 parent ca19825 commit 4a14296

File tree

2 files changed

+40
-44
lines changed

2 files changed

+40
-44
lines changed

src/main/java/org/hswebframework/reactor/excel/poi/PoiExcelReader.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.apache.poi.ss.usermodel.Sheet;
55
import org.apache.poi.ss.usermodel.Workbook;
66
import org.apache.poi.ss.usermodel.WorkbookFactory;
7+
import org.hswebframework.reactor.excel.BoundedCell;
78
import org.hswebframework.reactor.excel.InSheetCell;
89
import org.hswebframework.reactor.excel.ExcelOption;
910
import org.hswebframework.reactor.excel.spi.ExcelReader;
@@ -18,7 +19,7 @@ public String[] getSupportFormat() {
1819
}
1920

2021
@Override
21-
public Flux<? extends InSheetCell> read(InputStream inputStream, ExcelOption... options) {
22+
public Flux<BoundedCell> read(InputStream inputStream, ExcelOption... options) {
2223

2324
return Flux.create(sink -> {
2425
try {

src/test/java/org/hswebframework/reactor/excel/poi/PoiExcelWriterTest.java

+38-43
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.io.FileOutputStream;
1414
import java.util.HashMap;
15+
import java.util.Map;
1516

1617
class PoiExcelWriterTest {
1718

@@ -39,55 +40,49 @@ void testWrite() {
3940
@Test
4041
@SneakyThrows
4142
void testWriteMultiSheet() {
43+
44+
Flux<Map<String, Object>> dataStream = Flux.range(0, 1000)
45+
.map(i -> new HashMap<String, Object>() {{
46+
put("id", i);
47+
put("name", "test" + i);
48+
put("a", null);
49+
}});
50+
4251
ReactorExcel
4352
.xlsxWriter()
4453
.multiSheet()
45-
.sheet(sheet -> {
46-
sheet.name("S1")
47-
.header("id", "ID")
48-
.header("name", "姓名")
49-
.rows(Flux.range(0, 1000)
50-
.map(i -> new HashMap<String, Object>() {{
51-
put("id", i);
52-
put("name", "test" + i);
53-
put("a", null);
54-
}}));
55-
})
56-
.sheet(sheet -> {
57-
sheet.name("S2")
58-
.firstRowIndex(1)
59-
.header("id", "ID")
60-
.header("name", "姓名")
61-
.rows(Flux.range(0, 1000)
62-
.map(i -> new HashMap<String, Object>() {{
63-
put("id", "s2:" + i);
64-
put("name", "test:" + i);
65-
put("a", null);
66-
}}))
67-
.cell(0, 0, "大标题")
68-
.option(sheet_ -> {
69-
CellStyle style = sheet_.getWorkbook().createCellStyle();
54+
.sheet(spec -> spec
55+
.name("S1")
56+
.header("id", "ID")
57+
.header("name", "姓名")
58+
.rows(dataStream))
59+
.sheet(spec -> spec
60+
.name("S2")
61+
.firstRowIndex(1)
62+
.header("id", "ID")
63+
.header("name", "姓名")
64+
.rows(dataStream)
65+
.cell(0, 0, "大标题")
66+
.option(sheet -> {
67+
CellStyle style = sheet.getWorkbook().createCellStyle();
7068

71-
style.setAlignment(HorizontalAlignment.CENTER);
72-
style.setVerticalAlignment(VerticalAlignment.CENTER);
69+
style.setAlignment(HorizontalAlignment.CENTER);
70+
style.setVerticalAlignment(VerticalAlignment.CENTER);
7371

74-
sheet_.createRow(0);
75-
sheet_.addMergedRegion(CellRangeAddress.valueOf("A1:B1"));
76-
sheet_.getRow(0).createCell(0).setCellStyle(style);
72+
sheet.createRow(0);
73+
sheet.addMergedRegion(CellRangeAddress.valueOf("A1:B1"));
74+
sheet.getRow(0).createCell(0).setCellStyle(style);
7775

78-
})
79-
;
80-
})
81-
.sheet(sheet -> {
82-
sheet.cell(0, 0, "NameA")
83-
.cell(1, 0, "Age")
84-
.cell(0, 1, "Test")
85-
.cell(1, 1, 1)
86-
.option(sheet_ -> {
87-
sheet_.addMergedRegion(CellRangeAddress.valueOf("A3:B3"));
88-
sheet_.addMergedRegion(CellRangeAddress.valueOf("C1:C3"));
89-
});
90-
})
76+
}))
77+
.sheet(spec -> spec
78+
.cell(0, 0, "NameA")
79+
.cell(1, 0, "Age")
80+
.cell(0, 1, "Test")
81+
.cell(1, 1, 1)
82+
.option(sheet -> {
83+
sheet.addMergedRegion(CellRangeAddress.valueOf("A3:B3"));
84+
sheet.addMergedRegion(CellRangeAddress.valueOf("C1:C3"));
85+
}))
9186
.write(new FileOutputStream("./target/test.xlsx"))
9287
.as(StepVerifier::create)
9388
.expectComplete()

0 commit comments

Comments
 (0)