Skip to content

Commit 945469a

Browse files
VedranVedran
Vedran
authored and
Vedran
committed
#23 multiple sheets fix
1 parent 7525932 commit 945469a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/main/java/com/vgv/xls/XsWorkbook.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void saveTo(final String path) throws IOException {
145145

146146
@Override
147147
public EWorkbook with(final ESheet sheet) {
148-
return new XsWorkbook(this.sheets.with(sheet));
148+
return new XsWorkbook(this.sheets.with(sheet), this.workbook);
149149
}
150150

151151
@Override
@@ -154,7 +154,7 @@ public EWorkbook with(final Style style) {
154154
for (final ESheet sheet : this.sheets) {
155155
elements.add(sheet.with(style));
156156
}
157-
return new XsWorkbook(elements);
157+
return new XsWorkbook(elements, this.workbook);
158158
}
159159

160160
/**

src/test/java/com/vgv/xls/XsWorkbookTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,28 @@ public void createsWorkbookWithStyles() throws IOException {
8686
Matchers.equalTo(IndexedColors.GOLD.getIndex())
8787
);
8888
}
89+
90+
/**
91+
* Creates workbook with multiple sheets.
92+
* @throws IOException If fails
93+
*/
94+
@Test
95+
public void createsWorkbookWithMultipleSheets() throws IOException {
96+
final String fsheet = "sheet1";
97+
final String ssheet = "sheet2";
98+
final Workbook wbook = new XsWorkbook()
99+
.with(new XsSheet(new XsRow(new TextCell(fsheet))))
100+
.with(new XsSheet(new XsRow(new TextCell(ssheet))))
101+
.asWorkbook();
102+
MatcherAssert.assertThat(
103+
wbook.getSheetAt(0).getRow(1).getCell(0)
104+
.getStringCellValue(),
105+
Matchers.equalTo(fsheet)
106+
);
107+
MatcherAssert.assertThat(
108+
wbook.getSheetAt(1).getRow(1).getCell(0)
109+
.getStringCellValue(),
110+
Matchers.equalTo(ssheet)
111+
);
112+
}
89113
}

0 commit comments

Comments
 (0)