Bug 52300

Summary: Corrupted File after cloneSheet()
Product: POI Reporter: Stefan Helfert <stefan.helfert>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: anton_bastynets, void.at
Priority: P2    
Version: 3.8-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Bug Depends on:    
Bug Blocks: 53010    
Attachments: Template File
Created corrupted File
Testprogram
Xls-file with 20 images and 3 shapes

Description Stefan Helfert 2011-12-07 12:33:54 UTC
Created attachment 28048 [details]
Template File

Hi, 

Iam using templateFiles (*.xlt) and want to copy some sheets to reuse them.
The template files contains a image.

But during the copy progress I got the following error:
WARNING: 8 bytes remaining but no space left

When I want to open the new file afterwards I got a Errormessage and Excel repairs it.

After that the file is open and still looks good (Image is on both sheets).

I attached the template file and a litte Testprogram.

public class POITemplateCopyTest {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
	InputStream is = new FileInputStream(new File("D:\\BugReport\\SourceTemplate.xlt"));
	POIFSFileSystem poifs = new POIFSFileSystem(is);
	HSSFWorkbook wb = new HSSFWorkbook(poifs);
	is.close();
	
	wb.cloneSheet(1);
	
	wb.write(new FileOutputStream(new File("D:\\BugReport\\TemplateTestCopy.xls")));
	System.out.println("Done");
	
	}

}
Comment 1 Stefan Helfert 2011-12-07 12:34:16 UTC
Created attachment 28049 [details]
Created corrupted File
Comment 2 Stefan Helfert 2011-12-07 12:34:30 UTC
Created attachment 28050 [details]
Testprogram
Comment 3 Ant0xA 2011-12-12 12:51:09 UTC
*** Bug 52312 has been marked as a duplicate of this bug. ***
Comment 4 Ant0xA 2011-12-12 13:12:49 UTC
Hi. I had even bug. More often it becomes apparent for cloning sheets with shapes. 
And when I clone sheet with 20 images and 3 shapes, I have exception:
WARNING: 32 bytes remaining but no space left
WARNING: 136 bytes remaining but no space left
WARNING: 32 bytes remaining but no space left
WARNING: 136 bytes remaining but no space left
WARNING: 32 bytes remaining but no space left
WARNING: 136 bytes remaining but no space left
WARNING: 32 bytes remaining but no space left
WARNING: 136 bytes remaining but no space left
Exception in thread "main" org.apache.poi.hssf.record.RecordFormatException: 9192 bytes written but getRecordSize() reports 9296
	at org.apache.poi.hssf.record.EscherAggregate.serialize(EscherAggregate.java:488)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook$SheetRecordCollector.serialize(HSSFWorkbook.java:1263)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:1309)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1209)
	at TestWorkbookCreating.main(TestWorkbookCreating.java:44)

I added this file to attachments.
Comment 5 Ant0xA 2011-12-12 13:25:16 UTC
Created attachment 28067 [details]
Xls-file with 20 images and 3 shapes

During cloning the shape with name "cb_en" of this file occurs an exception.
Comment 6 Evgeniy Berlog 2012-08-12 11:41:19 UTC
This problem should be fixed in trunk.

Please try with a nightly build - see download links on http://poi.apache.org/
or build yourself from SVN trunk, see http://poi.apache.org/subversion.html