Bug 57171

Summary: Moving the active sheet and deleting the others results in a corrupted file
Product: POI Reporter: Philippe Lhoste <PhiLho>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.11-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: The file used in my tests
Show bugs
Proposed fix which adjusts the active sheet in setSheetOrder() and removeSheet()

Description Philippe Lhoste 2014-10-31 11:25:17 UTC
Created attachment 32171 [details]
The file used in my tests

Same use case as in bug #57165.

To keep only a selected sheet, I have to move it at first position, then delete the others.
But if this sheet is the active one (or, perhaps, the selected one), Excel 2010 then complains about the file it opens.

Looking at the file it points out, I found out that the reference to the active sheet has not been updated, so it points now to a non-existing sheet.

French Excel error message is:
Enregistrements supprimés: Affichage dans la partie /xl/workbook.xml (Classeur)

which can be roughly translated to:
Removed records: Display in the /xl/workbook.xml part (Workbook)

When I open the pointed out file, I see:

<?xml version="1.0" encoding="UTF-8"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><fileVersion appName="xl" lastEdited="5" lowestEdited="5" rupBuild="9303"/><workbookPr filterPrivacy="1" defaultThemeVersion="124226"/><bookViews><workbookView xWindow="120" yWindow="210" windowWidth="21075" windowHeight="7680" activeTab="5"/></bookViews><sheets><sheet name="Informative" sheetId="7" r:id="rId6"/></sheets><calcPr calcId="125725"/></workbook>

Notice the activeTab="5" part.
Also notice the sheetId="7" r:id="rId6" part, which might be part of the bug above mentioned.
Comment 1 Philippe Lhoste 2014-10-31 11:30:50 UTC
Created attachment 32175 [details]
Show bugs
Comment 2 Philippe Lhoste 2014-10-31 11:33:04 UTC
Added a standalone class that loads the sample Excel file and reproduce the bugs (three bugs are shown, I numbered them with the Bugzilla id).
You might need to adjust the path to the sample.
Comment 3 Dominik Stadler 2014-11-09 22:20:33 UTC
Created attachment 32199 [details]
Proposed fix which adjusts the active sheet in setSheetOrder() and removeSheet()

FYI, I have a proposed fix for this and bug 57163, but would like to postpone checkin until after release 3.11 as it runs a slight risk of breaking stuff.
Comment 4 Dominik Stadler 2014-12-22 09:00:51 UTC
Fixed this and Bug 57163 via r1647264