Bug 564616 - OLEClientSite.save corrupts the file in Excel 2016
Summary: OLEClientSite.save corrupts the file in Excel 2016
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.7.3   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-24 07:24 EDT by Bogdanescu Mihai CLA
Modified: 2021-06-10 10:55 EDT (History)
1 user (show)

See Also:


Attachments
Original and Corrupted files (7.67 KB, application/octet-stream)
2020-06-24 07:24 EDT, Bogdanescu Mihai CLA
no flags Details
SWT-Test (Excel Bug) (2.56 KB, application/octet-stream)
2021-06-10 10:39 EDT, Mirko Steffen CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bogdanescu Mihai CLA 2020-06-24 07:24:20 EDT
Created attachment 283392 [details]
Original and Corrupted files

We have a problem with the Excel integration on Excel 2016 Windows 10, the file gets corrupted if it is saved twice in the same session.
We use org.eclipse.swt.ole.win32.OleClientSite.save(File, boolean) to save the file.

Sceanario:
 1. Open Excel editor
 2. Modify content and save - Everything is ok, content is saved.
 3. Modify again and save - The resulting file is corrupted and can't be open in Excel.
It only happens in Excel 2016 on older Excel version it works.
The problem can be reproduced also if call twice  org.eclipse.swt.ole.win32.OleClientSite.save consecutively

Note: We observed that if the user press Save in the Excel toolbar after OleClientSite.save call the problem doesn't occur.


I attached some test files, if the corrupted file is unpacked we can see that some internal sheet files are missing 


We integrated it using:
        File exportFile = getExcelFile();
        Preconditions.checkArgument(exportFile != null, "Excel could not be opened, file was null");
        oleSite = new OleControlSite(frame, SWT.NONE, PROGRAM_ID, exportFile);        
        oleSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
        OleAutomation excelSheet = new OleAutomation(oleSite);
        int[] dispIDs = excelSheet.getIDsOfNames(new String[] {APPLICATION_ID });
        Variant pVarResult = excelSheet.getProperty(dispIDs[0]);
        oleApplication = pVarResult.getAutomation();
        pVarResult.dispose();
        excelSheet.dispose();
Comment 1 Mirko Steffen CLA 2021-06-10 10:36:24 EDT
I have the same issue with target platform 4.19 and added a SWT-Test to show the Bug.
Comment 2 Mirko Steffen CLA 2021-06-10 10:39:36 EDT
Created attachment 286561 [details]
SWT-Test (Excel Bug)

File size is different after sec. save call of excel files:
		
// Word
// 391419 =?= 391285	// 1. OK 
// 391419 =?= 391212	// 2. OK
// 391419 =?= 391212	// 3. OK 

// Excel
// 11861 =?= 15018		// 1. OK
// 11861 =?= 4103		// 2. Bug 
// 11861 =?= 4103		// 3. Bug
Comment 3 Mirko Steffen CLA 2021-06-10 10:55:12 EDT
This hack solved the issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=567798

// call private saveToStorageFile() to prevent OleClientSite.saveOffice2007() being called
		Method method;
		try {
			method = OleClientSite.class.getDeclaredMethod("saveToStorageFile", File.class);
			method.setAccessible(true);
			method.invoke(site, fileOut);
		} catch (Exception e) {
			e.printStackTrace();
		}