Bug 49658 - [PATCH] HSSFSHeet after insert EMF,DIB,VMF format Image,Can't open xls for Excel 2007
Summary: [PATCH] HSSFSHeet after insert EMF,DIB,VMF format Image,Can't open xls for Ex...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.6-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-28 04:27 UTC by longxibo
Modified: 2013-10-13 07:21 UTC (History)
0 users



Attachments
test insert image xls file (17.50 KB, application/vnd.ms-excel)
2010-07-28 04:27 UTC, longxibo
Details
It is dib image (643.22 KB, image/bmp)
2010-07-28 04:29 UTC, longxibo
Details
It is wmf image (2.29 KB, image/x-wmf)
2010-07-28 04:56 UTC, longxibo
Details
It is emf image (160 bytes, image/x-emf)
2010-07-28 04:57 UTC, longxibo
Details
Patch for embedding EMF files (7.31 KB, patch)
2013-09-15 12:26 UTC, Andreas Beeker
Details | Diff
Patch for embedding EMF files (II) (9.74 KB, patch)
2013-10-12 12:35 UTC, Andreas Beeker
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description longxibo 2010-07-28 04:27:28 UTC
Created attachment 25807 [details]
test insert image xls file

@Test
    public void testInsertImageForHSSF() {
	HSSFWorkbook wb;
	HSSFSheet sheet;
	FileOutputStream foutput = null;
	FileInputStream finput = null;
	String xlsSourceFile = "testfile\\testinsertimage.xls";
	try {
	    finput = new FileInputStream(xlsSourceFile);
	    wb = new HSSFWorkbook(finput);
	    finput.close();
	    HSSFRow row;
	    sheet = wb.getSheetAt(1);
	    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();

	    HSSFClientAnchor anchor;
	    anchor = new HSSFClientAnchor(0, 0, 0, 255, (short) 2, 2, (short) 4, 7);
	    anchor.setAnchorType(HSSFWorkbook.PICTURE_TYPE_EMF);
	    HSSFPicture picture = patriarch.createPicture(anchor, loadPicture("testfile\\test.emf", wb, HSSFWorkbook.PICTURE_TYPE_EMF));
	    // Reset the image to the original size.
	    picture.resize();
	    picture.setLineStyle(picture.LINESTYLE_DASHDOTGEL);
	    foutput = new FileOutputStream(xlsSourceFile);
	    wb.write(foutput);
	} catch (FileNotFoundException e) {
	    e.printStackTrace();
	} catch (IOException e) {
	    e.printStackTrace();
	} finally {
	    try {
		if (foutput != null)
		    foutput.close();
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	}
    }
Comment 1 longxibo 2010-07-28 04:29:40 UTC
Created attachment 25808 [details]
It is dib image
Comment 2 longxibo 2010-07-28 04:56:20 UTC
Created attachment 25809 [details]
It is wmf image
Comment 3 longxibo 2010-07-28 04:57:59 UTC
Created attachment 25810 [details]
It is emf image
Comment 4 Nick Burch 2010-07-28 07:03:20 UTC
Can POI still make sense of the image after a save/load?

If you add the same image into the file in excel, how do the BiffViewer outputs differ? Any obvious differences between what POI did and what Excel does?
Comment 5 Egor 2013-05-23 20:17:09 UTC
http://mail-archives.apache.org/mod_mbox/poi-user/200710.mbox/%3C1011226198.20071009084134@dinom.ru%3E

here said that emf/wmf pictures need special preprocessing before inserting in hssf. Is any info about preprocessing? Where i can read about it?
Comment 6 Andreas Beeker 2013-09-15 12:26:08 UTC
Created attachment 30844 [details]
Patch for embedding EMF files

at least for EMF files, there's no preprocessing of the content required ...

(originally posted here: http://stackoverflow.com/questions/16722044/javapoiinsert-emf-image-into-hssfworkbook/16755335#16755335)
Comment 7 Andreas Beeker 2013-10-12 12:35:05 UTC
Created attachment 30926 [details]
Patch for embedding EMF files (II)

new version which supports EMF/WMF
Comment 8 Yegor Kozlov 2013-10-13 07:21:05 UTC
Patch applied in r 1531622