You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "KrisPatAU (via GitHub)" <gi...@apache.org> on 2025/12/08 23:14:02 UTC
[I] Workbook::getSheetName() returning null due to sheet name truncation to 31 characters. [poi]
KrisPatAU opened a new issue, #966:
URL: https://github.com/apache/poi/issues/966
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
}
}
}
`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [I] Workbook::getSheetName() returning null due to sheet name truncation to 31 characters. [poi]
Posted by "Satwik-Bhardwaj (via GitHub)" <gi...@apache.org>.
Satwik-Bhardwaj commented on issue #966:
URL: https://github.com/apache/poi/issues/966#issuecomment-3649136436
You are correct. If POI silently truncates the sheet name, it should not return null when attempting to access the sheet using the full name. This behavior indicates an inconsistency. To address this issue, we should throw an exception when trying to get the sheet if the name exceeds 31 characters.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org