Bug 50315

Summary: XSSF sheet.setAutoFilter() crashes Excel by sorting.
Product: POI Reporter: Jack <duanxingjian>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: yo.shady
Priority: P2    
Version: 3.7-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: two .xlsx files, one's autofilter created by POI, the other one's created manually.

Description Jack 2010-11-22 11:13:33 UTC
Created attachment 26330 [details]
two .xlsx files, one's autofilter created by POI, the other one's created manually.

Steps to Reproduce: 
After using the following code to generate a XLSX file, if you open that generated file (I attached here as "AutofilterGeneratedWithPOI.xlsx" in the zip file) and click autofilter to sort any of the columns, MS Excel would crash. However, if you delete the autofilter and using Excel to add it back again (I attached here as "AutofilterGeneratedWithinExcel.xlsx"), everything would work just fine. I recreated this scenario on two boxes and two separated projects.

Actual Results: 
Excel Application Crashes.

Build Date & Platform: 
Windows XP, NetBean, Excel 2007, 10/28/2011

Additional Builds and Platforms:
Windows XP, RAD 7.5 11/15/2011, samething happens.

#####################################################################

import java.io.FileOutputStream;

import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class RptJobController {

	public static void main(String args[]) 
	{	
		FileOutputStream fileOut = null;
		try {
			XSSFWorkbook wb = new XSSFWorkbook();
			fileOut = new FileOutputStream("c:\\workbook.xlsx");
			XSSFSheet sheet = wb.createSheet("new sheet");
			// Create a row and put some cells in it.
			XSSFRow row = sheet.createRow((short) 0);
			// Create a cell and put a value in it.
			row.createCell(0).setCellValue("irrelevant");
			row.createCell(1).setCellValue("Number");
			row.createCell(2).setCellValue("String");

			row = sheet.createRow((short) 1);
			row.createCell(1).setCellValue(1);
			row.createCell(2).setCellValue("This is a string");

			row = sheet.createRow((short) 2);
			row.createCell(1).setCellValue(2);
			row.createCell(2).setCellValue("This is a string");

			row = sheet.createRow((short) 3);
			row.createCell(1).setCellValue(3);
			row.createCell(2).setCellValue("This is a string");

			sheet.setAutoFilter(CellRangeAddress.valueOf("B1:C1"));
			sheet.autoSizeColumn((short) 2);
			wb.write(fileOut);
			fileOut.close();
		} catch (Exception ex) {

		}	
	}
}
Comment 1 Jack 2010-11-22 11:21:26 UTC
*** Bug 50314 has been marked as a duplicate of this bug. ***
Comment 2 Yegor Kozlov 2010-12-02 10:28:47 UTC
Fixed in r1041407

It turned out that autofilters must be registered in workbook.xml. Without registering Excel recognizes the autofilter but crashes when you try to use it.

Yegor