apache / apache/poi

Workbook::getSheetName() returning null due to sheet name truncation to 31 characters.

Open
#966 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
844
Avg merge
5h 52m
Merged PRs (30d)
47

Description

In 5.x versions, while creating a sheet, it was decided to truncate its name:

`String sn = (sheetname.length() > 31) ? sheetname.substring(0, 31) : sheetname;`

But as a consequence, trying to get the sheet using the same original name results in null.

```import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class ApachePOISheetNameTest {
private static final String LONG_SHEET_NAME = "ThisSheetNameIsMoreThan31Characters";

public static void main(String[] args) throws Exception {
try (Workbook workbook = new HSSFWorkbook()) {
workbook.createSheet(LONG_SHEET_NAME);
Sheet sheet = workbook.getSheet(LONG_SHEET_NAME);
System.out.println(sheet); // null
sheet = workbook.getSheet(LONG_SHEET_NAME.substring(0, 31));
System.out.println(sheet); // works
}
}

}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the Workbook.createSheet(String) and Workbook.getSheet(String) entry points involved in the example, including the 31-character truncation described in the issue. Reproduce the HSSFWorkbook case and add coverage showing the expected result when the original long sheet name is used for lookup.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.