Bug 64811 - autoSizeColumn too small if cell contains special characters
Summary: autoSizeColumn too small if cell contains special characters
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 4.1.2-FINAL
Hardware: PC All
: P2 minor (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-13 14:45 UTC by W T
Modified: 2024-02-25 19:38 UTC (History)
0 users



Attachments
Screenshot Excel 2016 (Windows 10) (14.13 KB, image/png)
2020-10-13 14:45 UTC, W T
Details

Note You need to log in before you can comment on or make changes to this bug.
Description W T 2020-10-13 14:45:35 UTC
Created attachment 37499 [details]
Screenshot Excel 2016 (Windows 10)

I am facing a problem, when using autoSizeColumn and an arrow character (U+279D) appears in cell content, the column will be sized too small.
This code will produce a file containing the problem:

@Test
void excelColWidthStreamedTest() throws IOException {
	final SXSSFWorkbook wb = new SXSSFWorkbook(null, 5000, false, true);
	SXSSFSheet listSheet = wb.createSheet("List");
	listSheet.trackAllColumnsForAutoSizing();

	Row headerRow = listSheet.createRow(0);
	headerRow.createCell(0).setCellValue("MyLongLongString ➝");
	headerRow.createCell(1).setCellValue("➝ MyLongLongString");
	headerRow.createCell(2).setCellValue("My➝Long➝Long➝String");
	headerRow.createCell(3).setCellValue("MyShortString");

	for (int i = 0; i < 4; i++) {
		listSheet.autoSizeColumn(i);
	}
	File excelFile = new File("testFileStreamed.xlsx");
	try (OutputStream fileOut = new FileOutputStream(excelFile)) {
		wb.write(fileOut);
	}
}
Comment 1 Dominik Stadler 2020-12-30 22:25:12 UTC
When running this locally on Linux Ubuntu 20.04, the width of the cells is fine, so it may be related to the fonts that are installed on the system where you run the auto-size operation (OS rendering functionality is used to draw the actual characters of the Font of the cell). 

Please verify if default fonts and some basic X-window libraries are installed as those might be needed for proper execution of the auto-sizing functionality.
Comment 2 Dominik Stadler 2024-02-25 19:38:01 UTC
No response for a long time, thus closing.