Skip to content

Commit

Permalink
Merge pull request #5 from ochedru/issue_4
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
Olivier Chédru committed Apr 19, 2016
2 parents fa41014 + 7749e0e commit bfcc8df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/dhatim/fastexcel/Workbook.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ int getIndex(Worksheet ws) {
public Worksheet newWorksheet(String name) {
// Replace chars forbidden in worksheet names (backslahses and colons) by dashes
String sheetName = name.replaceAll("[/\\\\\\?\\*\\]\\[\\:]", "-");

// Maximum length worksheet name is 31 characters
if (sheetName.length() > 31) {
sheetName = sheetName.substring(0, 31);
}
Worksheet worksheet = new Worksheet(this, sheetName);
synchronized (worksheets) {
worksheets.add(worksheet);
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/dhatim/fastexcel/Correctness.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public void singleEmptyWorksheet() throws Exception {
byte[] data = writeWorkbook(wb -> wb.newWorksheet("Worksheet 1"));
}

@Test
public void worksheetWithNameLongerThan31Chars() throws Exception {
byte[] data = writeWorkbook(wb -> {
Worksheet ws = wb.newWorksheet("01234567890123456789012345678901");
assertThat(ws.getName()).isEqualTo("0123456789012345678901234567890");
});
}

@Test
public void checkMaxRows() throws Exception {
byte[] data = writeWorkbook(wb -> wb.newWorksheet("Worksheet 1").value(Worksheet.MAX_ROWS - 1, 0, "test"));
Expand Down

0 comments on commit bfcc8df

Please sign in to comment.