Return-Path: Delivered-To: apmail-poi-user-archive@www.apache.org Received: (qmail 93552 invoked from network); 9 Oct 2007 04:42:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Oct 2007 04:42:30 -0000 Received: (qmail 90744 invoked by uid 500); 9 Oct 2007 04:42:14 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 90718 invoked by uid 500); 9 Oct 2007 04:42:13 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Received: (qmail 90699 invoked by uid 99); 9 Oct 2007 04:42:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Oct 2007 21:42:13 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [81.13.50.178] (HELO dinom.ru) (81.13.50.178) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Oct 2007 04:42:14 +0000 Received: from [89.208.4.3] by dinom.ru with esmtpa (Exim 4.63) (envelope-from ) id JPMNSK-0001E0-93 for user@poi.apache.org; Tue, 09 Oct 2007 08:43:32 +0400 Date: Tue, 9 Oct 2007 08:41:34 +0400 From: Yegor Kozlov X-Mailer: The Bat! (v3.85.03) Professional Organization: Dinom LLC X-Priority: 3 (Normal) Message-ID: <1011226198.20071009084134@dinom.ru> To: "POI Users List" Subject: Re: Insert EMF pictures in Excel In-Reply-To: <85f9c9830710081208y72e147f2ke24b8c1c2dc49264@mail.gmail.com> References: <85f9c9830710081208y72e147f2ke24b8c1c2dc49264@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Yes, it is a bug. Currently only PNG and JPEG images can be inserted. For other formats you will get "File error: data may have been lost". The problem is that the binary data for WMF and EMF should be "preprocessed" before inserting in a workbook. In case of PNG and JPEG we just copy the exact contents of a file and it works fine but does not for EMF/WMF. We didn't yet figure out what's the difference. Hope the problem will be fixed by POI 3.1. Yegor > Hi, > I'm using poi-bin-3.0.1-FINAL-20070705 and I'm trying to insert an EMF > picture into an Excel sheet without much luck. I've used the example > in the "Busy Developers's Guide" and it works great with a png but > when I change it to an emf Excel tells me: "File error: data may have > been lost" when I open the xls document. > Is this a bug, or am I doing something silly? > Thanks in advance, > Bertil > public class TestEMF { > public static void main(String[] args) throws Exception { > new TestEMF().test(); > } > public void test() throws Exception { > createWorkbook("png", "test_png.png", > HSSFWorkbook.PICTURE_TYPE_PNG); > createWorkbook("emf", "test_emf.emf", > HSSFWorkbook.PICTURE_TYPE_EMF); > } > public void createWorkbook(String name, String image, int imageType) > throws Exception { > HSSFWorkbook workbook = new HSSFWorkbook(); > createSheet(workbook, name, image, imageType); > FileOutputStream out = new FileOutputStream(name + ".xls"); > workbook.write(out); > out.close(); > } > public void createSheet(HSSFWorkbook workbook, String sheetName, > String image, int imageType) throws Exception { > HSSFSheet sheet = workbook.createSheet(sheetName); > HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); > HSSFClientAnchor anchor; > anchor = new > HSSFClientAnchor(0,0,0,255,(short)2,2,(short)4,7); > anchor.setAnchorType( 2 ); > patriarch.createPicture(anchor, > loadPicture(image, workbook, imageType)); > } > private int loadPicture(String image, HSSFWorkbook workbook, int type) > throws IOException { > File file = new File(image); > byte[] bytes = new byte[(int)file.length()]; > InputStream input = new BufferedInputStream(new FileInputStream(file)); > try { > int offset = 0; > int read = -1; > while((read = input.read()) != -1) > bytes[offset++] = (byte)read; > } finally { > input.close(); > } > return workbook.addPicture(bytes, type); > } > } > The example pictures can be found here: > http://bluefire.dnsalias.com/~richard/poi/test_png.png > http://bluefire.dnsalias.com/~richard/poi/test_emf.emf > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org > For additional commands, e-mail: user-help@poi.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional commands, e-mail: user-help@poi.apache.org