Bug 57462

Summary: Problem with autofilter when reordering sheets.
Product: POI Reporter: Thomas <thomas.kuhlmann>
Component: HSSFAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: normal CC: thomas.kuhlmann
Priority: P2    
Version: 3.11-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Resulting Excel-File
workbook with autofilter

Description Thomas 2015-01-19 12:33:18 UTC
Created attachment 32379 [details]
Resulting Excel-File

I create a new workbook with
1. "Sheet 1" with autofilter 0,0,0,2
2. "Sheet 2" with autofilter 0,0,0,5
3. "Sheet 3" with no autofilter.
4. Set Order of "Sheet 3" to 0.
5. Saving XLS.
=> "Sheet 1" becomes autofilter of "Sheet 2" 0,0,0,5

Here is the used JAVA-Code:

	HSSFWorkbook wb = new HSSFWorkbook();
	HSSFSheet sheet1 = wb.createSheet("Sheet 1");
	HSSFSheet sheet2 = wb.createSheet("Sheet 2");
	HSSFSheet sheet3 = wb.createSheet("Sheet 3");
	sheet1.setAutoFilter(new CellRangeAddress(0, 0, 0, 2));
	sheet2.setAutoFilter(new CellRangeAddress(0, 0, 0, 5));
	wb.setSheetOrder("Sheet 3", 0);
	wb.setSheetOrder("Sheet 1", 1); // Optional ?
	wb.setSheetOrder("Sheet 2", 2); // Optional ?
	FileOutputStream fos = new FileOutputStream("POI-TEST.XLS");
	wb.write(fos);
	fos.close();

I have attached the resulting XLS.

Thanks in advance for fixing!
Comment 1 Dominik Stadler 2015-02-11 20:13:28 UTC
Seems the autofilter is not adjusted when sheet order changes, this is stored as getSpecificBuiltinRecord() in the Workbook, but not adjusted for setSheetOrder(). I tried to adjust this, but it was non-trivial to get this to work.

Note: removeSheet() is likely also affected, similar adjusting of sheetIndexes is likely necessary there as well.
Comment 2 albfan 2018-01-16 09:01:14 UTC
Created attachment 35681 [details]
workbook with autofilter

just open the file with excel an libreoffice.
Comment 3 albfan 2018-01-16 09:02:24 UTC
Adding an autofilter to a sheet from file 1, and shifting first rows, on excel 2016 autofilter is shown correctly from file 2 but on libreoffice 5 it shows the autofilter on file 3

After save autofilter with libreoffice, both programs show autofilter correctly
Comment 4 albfan 2018-01-16 09:03:08 UTC
Adding an autofilter to a sheet from file 1, and shifting first rows, on excel 2016 autofilter is shown correctly from file 2 but on libreoffice 5 it shows the autofilter on file 3

After save autofilter with libreoffice, both programs show autofilter correctly