You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Risken <jo...@risken.se> on 2010/12/10 21:45:55 UTC

Images and XSSF unexpected results...

Why is it that the generated xlsx file containing 2 images and one textbox
gives such strange result when I try dragging the images/textbox around in
xl?

The same file works perfectly well in OpenOffice. 
I also tried changing to HSSF and .xls and the file worked perfect then, but
I would much rather generate .xlsx files...

Is it faulty coding by me or is XL having hickups?

In XL when draggin one image and releasing it the two images change places.
And if I stretch the textbox it becomes an Image!

Please help me out here!!?

/Johan

import java.io.*;
import org.apache.poi.xssf.usermodel.*;


public class ImageTest {

    public static void main(String[] args) throws Exception{
        FileInputStream is;
        File file;
        byte[] bytes;
        int idx;

        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sh = wb.createSheet();
        XSSFDrawing p = sh.createDrawingPatriarch();

        file = new File("c:\\img.jpg");
        bytes = new byte[(int)file.length()];
        is = new FileInputStream(file); 
        is.read(bytes);
        is.close();

        idx = wb.addPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG);
        p.createPicture(new XSSFClientAnchor(0, 0, 0, 0, (short)1, 1,
(short)4, 10),idx);

        file = new File("c:\\img2.jpg");
        bytes = new byte[(int)file.length()];
        is = new FileInputStream(file);
        is.read(bytes);
        is.close();

        idx = wb.addPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG);
        p.createPicture(new XSSFClientAnchor(0, 0, 0, 0, (short)1, 12,
(short)4, 30),idx);


        XSSFTextBox textbox1 = p.createTextbox(
        new XSSFClientAnchor(0,0,0,0,(short)9,1,(short)11,2));

        textbox1.setLineStyleColor(255, 0, 0);
        textbox1.setText(new XSSFRichTextString("Testing") );


        FileOutputStream out = new FileOutputStream("c:\\workbook.xlsx");
        wb.write(out);
        out.close();
    }

}


-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-and-XSSF-unexpected-results-tp3300963p3300963.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Images and XSSF unexpected results...

Posted by Risken <jo...@risken.se>.
Ok
I hope i filed it ok - I really don't understand the bugzilla gui...

Bug 50458
	
/Johan

-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-and-XSSF-unexpected-results-tp3300963p3301691.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Images and XSSF unexpected results...

Posted by Risken <jo...@risken.se>.
http://apache-poi.1045710.n5.nabble.com/file/n3301501/ImageTestHSSF.java
ImageTestHSSF.java 
http://apache-poi.1045710.n5.nabble.com/file/n3301501/ImageTestXSSF.java
ImageTestXSSF.java 

Here you have something to test with this is definitely very strange...

/Johan
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-and-XSSF-unexpected-results-tp3300963p3301501.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Images and XSSF unexpected results...

Posted by Risken <jo...@risken.se>.
I forgot to write that the problem is in Excel 2007.

-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-and-XSSF-unexpected-results-tp3300963p3301415.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Images and XSSF unexpected results...

Posted by David Fisher <df...@jmlafferty.com>.
Johan,

> Ok
> My code (which generated the files) is correct isn't it?

I think so.

> I'm using excel 2007 and OpenOffice 3.2

Do you have Excel 2010?

Whether this is an Apache POI or a Microsoft Excel bug I think you should create a bugzilla report.

https://issues.apache.org/bugzilla/enter_bug.cgi?product=POI

Please attach your code and the images. 

Regards,
Dave

> 
> /Johan
> -- 
> View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-and-XSSF-unexpected-results-tp3300963p3301654.html
> Sent from the POI - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> 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


Re: Images and XSSF unexpected results...

Posted by Risken <jo...@risken.se>.
Forgot to write that I use Windows 7, if that matters...
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-and-XSSF-unexpected-results-tp3300963p3301656.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Images and XSSF unexpected results...

Posted by Risken <jo...@risken.se>.
Ok
My code (which generated the files) is correct isn't it?

I'm using excel 2007 and OpenOffice 3.2

/Johan
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-and-XSSF-unexpected-results-tp3300963p3301654.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Images and XSSF unexpected results...

Posted by David Fisher <df...@jmlafferty.com>.
Johan,

> Don't know what you mean - it's a textbox and 2 images in each file.
> Have a look at the resulting files instead then...
> 
> XLS is ok:
> http://apache-poi.1045710.n5.nabble.com/file/n3301618/workbook.xls
> workbook.xls 
> XLSX is not ok:
> http://apache-poi.1045710.n5.nabble.com/file/n3301618/workbook.xlsx
> workbook.xlsx 
> 
> Try drag/resize the objects...

Using Excel 2011 on MacOSX and the objects in workbook.xlsx drag and resize correctly. However, using Excel 2008 on MacOSX the trouble occurs as  described. Could it be a bug in Microsoft's implementation of the OOXML spec that has been fixed? It's not the first instance. BTW - Excel 2008 is version 12 and Excel 2011 is version 14.

What version of Excel are you using? Anyone have any results with Excel 2010?

Regards,
Dave

> 
> /Johan
> -- 
> View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-and-XSSF-unexpected-results-tp3300963p3301618.html
> Sent from the POI - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> 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


Re: Images and XSSF unexpected results...

Posted by Risken <jo...@risken.se>.
Don't know what you mean - it's a textbox and 2 images in each file.
Have a look at the resulting files instead then...

XLS is ok:
http://apache-poi.1045710.n5.nabble.com/file/n3301618/workbook.xls
workbook.xls 
XLSX is not ok:
http://apache-poi.1045710.n5.nabble.com/file/n3301618/workbook.xlsx
workbook.xlsx 

Try drag/resize the objects...

/Johan
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-and-XSSF-unexpected-results-tp3300963p3301618.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Images and XSSF unexpected results...

Posted by Aram Mirzadeh <aw...@mbcli.com>.
It isn't a graphic it's a text box but the content is still editable as 
text.

If not, can you post the workbook.xls file.

On 12/10/2010 3:45 PM, Risken wrote:
> Why is it that the generated xlsx file containing 2 images and one textbox
> gives such strange result when I try dragging the images/textbox around in
> xl?
>
> The same file works perfectly well in OpenOffice.
> I also tried changing to HSSF and .xls and the file worked perfect then, but
> I would much rather generate .xlsx files...
>
> Is it faulty coding by me or is XL having hickups?
>
> In XL when draggin one image and releasing it the two images change places.
> And if I stretch the textbox it becomes an Image!
>
> Please help me out here!!?
>
> /Johan
>
> import java.io.*;
> import org.apache.poi.xssf.usermodel.*;
>
>
> public class ImageTest {
>
>      public static void main(String[] args) throws Exception{
>          FileInputStream is;
>          File file;
>          byte[] bytes;
>          int idx;
>
>          XSSFWorkbook wb = new XSSFWorkbook();
>          XSSFSheet sh = wb.createSheet();
>          XSSFDrawing p = sh.createDrawingPatriarch();
>
>          file = new File("c:\\img.jpg");
>          bytes = new byte[(int)file.length()];
>          is = new FileInputStream(file);
>          is.read(bytes);
>          is.close();
>
>          idx = wb.addPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG);
>          p.createPicture(new XSSFClientAnchor(0, 0, 0, 0, (short)1, 1,
> (short)4, 10),idx);
>
>          file = new File("c:\\img2.jpg");
>          bytes = new byte[(int)file.length()];
>          is = new FileInputStream(file);
>          is.read(bytes);
>          is.close();
>
>          idx = wb.addPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG);
>          p.createPicture(new XSSFClientAnchor(0, 0, 0, 0, (short)1, 12,
> (short)4, 30),idx);
>
>
>          XSSFTextBox textbox1 = p.createTextbox(
>          new XSSFClientAnchor(0,0,0,0,(short)9,1,(short)11,2));
>
>          textbox1.setLineStyleColor(255, 0, 0);
>          textbox1.setText(new XSSFRichTextString("Testing") );
>
>
>          FileOutputStream out = new FileOutputStream("c:\\workbook.xlsx");
>          wb.write(out);
>          out.close();
>      }
>
> }
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org