Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #4 #5

Merged
merged 2 commits into from
Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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