|
12 | 12 |
|
13 | 13 | import java.io.FileOutputStream;
|
14 | 14 | import java.util.HashMap;
|
| 15 | +import java.util.Map; |
15 | 16 |
|
16 | 17 | class PoiExcelWriterTest {
|
17 | 18 |
|
@@ -39,55 +40,49 @@ void testWrite() {
|
39 | 40 | @Test
|
40 | 41 | @SneakyThrows
|
41 | 42 | 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 | + |
42 | 51 | ReactorExcel
|
43 | 52 | .xlsxWriter()
|
44 | 53 | .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(); |
70 | 68 |
|
71 |
| - style.setAlignment(HorizontalAlignment.CENTER); |
72 |
| - style.setVerticalAlignment(VerticalAlignment.CENTER); |
| 69 | + style.setAlignment(HorizontalAlignment.CENTER); |
| 70 | + style.setVerticalAlignment(VerticalAlignment.CENTER); |
73 | 71 |
|
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); |
77 | 75 |
|
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 | + })) |
91 | 86 | .write(new FileOutputStream("./target/test.xlsx"))
|
92 | 87 | .as(StepVerifier::create)
|
93 | 88 | .expectComplete()
|
|
0 commit comments