com.extentech.ExtenXLS
Class ImageHandle

java.lang.Object
  extended by com.extentech.ExtenXLS.ImageHandle
All Implemented Interfaces:
Serializable

public class ImageHandle
extends Object
implements Serializable

The ImageHandle provides access to an Image embedded in a spreadsheet.

Use the ImageHandle to work with images in spreadsheet.


With an ImageHandle you can:

insert images into your spreadsheet set the position of the image set the width and height of the image write spreadsheet image files to any outputstream


Since:
1.3
Version:
4.1
Author:
John McMahon -- Copyright ©2011Extentech Inc.
See Also:
WorkBookHandle, WorkSheetHandle, Serialized Form

Field Summary
static int HEIGHT
           
static int WIDTH
           
static int X
           
static int Y
           
 
Constructor Summary
ImageHandle(byte[] _imageBytes, com.extentech.formats.XLS.Boundsheet sheet)
          Constructor which takes image file bytes and inserts into specific sheet
ImageHandle(InputStream imagebytestream, com.extentech.formats.XLS.Boundsheet bs)
          Constructor which takes image file bytes and associates it with the specified boundsheet
ImageHandle(InputStream imagebytestream, WorkSheetHandle _sheet)
          Constructor which takes image file bytes and inserts into specific sheet
 
Method Summary
 byte[] convertData(InputStream imagebytestream)
          converts image data into byte array used by Jan 22, 2010
 boolean equals(Object another)
          Override equals so that Sheet cannot contain dupes.
 double getAspectRatio()
          returns width divided by height for the aspect ratio
 short[] getBounds()
          return the image bounds images bounds are as follows: bounds[0]= column # of top left position (0-based) of the shape bounds[1]= x offset within the top-left column (0-1023) bounds[2]= row # for top left corner bounds[3]= y offset within the top-left corner (0-1023) bounds[4]= column # of the bottom right corner of the shape bounds[5]= x offset within the cell for the bottom-right corner (0-1023) bounds[6]= row # for bottom-right corner of the shape bounds[7]= y offset within the cell for the bottom-right corner (0-1023)
 int getCol()
          return the leftmost column of the image
 int getCol1()
          return the rightmost column of the image
 short[] getColAndOffset()
          get the position of the top left corner of the image in the sheet
 short[] getCoords()
          return the image bounds in x, y, width, height format in pixels
 short getHeight()
          return the height of the image in pixels
 byte[] getImageBytes()
           
 String getImageFormat(InputStream imagebytestream)
          returns the format name of the image data Jan 22, 2010
 int getImageIndex()
          Internal method that converts the image bounds appropriate for saving by Excel in the MsofbtOPT record.
 String getImageName()
          return the imageName (= original file name, I believe)
 int getImageType()
           
 org.json.JSONObject getJSON()
          Get a JSON representation of the format
 String getMimeType()
          Returns the image mime type
 com.extentech.formats.XLS.MSODrawing getMsodrawing()
           
 String getName()
           
 String getOOXML(int rId)
          return the (00)XML (or DrawingML) representation of this image
 int getOriginalWidth()
           
 int getRow()
          return the topmost row of the image
 int getRow1()
          return the lower row of the image
 short[] getRowAndOffset()
          get the position of the top left corner of the image in the sheet
 String getShapeName()
          returns the explicitly set shape name (set by entering text in the named range field in Excel)
 com.extentech.formats.XLS.Boundsheet getSheet()
          returns the WorkSheet this image is contained in
 com.extentech.formats.OOXML.SpPr getSpPr()
          return the OOXML shape property for this image
 String getType()
          Returns the image type
 short getWidth()
          return the width of the image in pixels
 short getX()
          return the upper x coordinate of the image in pixels
 String getXML(int rId)
          return the XML representation of this image
 short getY()
          return the upper y coordinate of the image in pixels
 boolean isActive()
          returns true if this drawing is active i.e.
 void position(ImageHandle im)
          set ImageHandle position based on another
 boolean remove()
          removes this Image from the WorkBook.
 void setBounds(short[] bounds)
          sets the image bounds images bounds are as follows: bounds[0]= column # of top left position (0-based) of the shape bounds[1]= x offset within the top-left column (0-1023) bounds[2]= row # for top left corner bounds[3]= y offset within the top-left corner (0-1023) bounds[4]= column # of the bottom right corner of the shape bounds[5]= x offset within the cell for the bottom-right corner (0-1023) bounds[6]= row # for bottom-right corner of the shape bounds[7]= y offset within the cell for the bottom-right corner (0-1023)
 void setCoords(int x, int y, int w, int h)
          set the image x, w, width and height in pixels
 void setEditMovement(String editMovement)
          specify how to resize or move upon edit OOXML specific
 void setHeight(int h)
          set the height of the image in pixels
 void setImageBytes(byte[] imageBytes)
          sets the underlying image bytes to the bytes from a new image essentially swapping the image bytes for another, while retaining all other image properties (borders, etc.)
 void setImageType(int type)
           
 void setMsgdrawing(com.extentech.formats.XLS.MSODrawing rec)
           
 void setName(String name)
           
 void setRow(int row)
          set the topmost row of the image
 void setRow1(int row)
          set the lower row of the image
 void setShapeName(String name)
          allow setting of image name as seen in the Named Range Box
 void setSpPr(com.extentech.formats.OOXML.SpPr sp)
          define the OOXML shape property for this image from an existing spPr element
 void setWidth(int w)
          set the width of the image in pixels
 void setX(int x)
          set the image upper x coordinate in pixels
 void setY(int y)
          set the image upper y coordinate in pixels
 String toString()
          Need to figure out a unique identifier for these -- if there is one in the BIFF8 information, that would be best
 void update()
          update the underlying image record
 void write(OutputStream out)
          write the image bytes to an outputstream such as a file
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

X

public static final int X
See Also:
Constant Field Values

Y

public static final int Y
See Also:
Constant Field Values

WIDTH

public static final int WIDTH
See Also:
Constant Field Values

HEIGHT

public static final int HEIGHT
See Also:
Constant Field Values
Constructor Detail

ImageHandle

public ImageHandle(InputStream imagebytestream,
                   WorkSheetHandle _sheet)
Constructor which takes image file bytes and inserts into specific sheet

Parameters:
imageBytes -
sheet -

ImageHandle

public ImageHandle(InputStream imagebytestream,
                   com.extentech.formats.XLS.Boundsheet bs)
Constructor which takes image file bytes and associates it with the specified boundsheet

Parameters:
imagebytestream -
bs -

ImageHandle

public ImageHandle(byte[] _imageBytes,
                   com.extentech.formats.XLS.Boundsheet sheet)
Constructor which takes image file bytes and inserts into specific sheet

Parameters:
imageBytes -
sheet -
Method Detail

getAspectRatio

public double getAspectRatio()
returns width divided by height for the aspect ratio

Returns:
the aspect ratio for the image

setMsgdrawing

public void setMsgdrawing(com.extentech.formats.XLS.MSODrawing rec)

getMsodrawing

public com.extentech.formats.XLS.MSODrawing getMsodrawing()

getType

public String getType()
Returns the image type

Returns:

getMimeType

public String getMimeType()
Returns the image mime type

Returns:

equals

public boolean equals(Object another)
Override equals so that Sheet cannot contain dupes.

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

update

public void update()
            throws Exception
update the underlying image record

Throws:
Exception

isActive

public boolean isActive()
returns true if this drawing is active i.e. not deleted
Note this is experimental

Returns:

convertData

public byte[] convertData(InputStream imagebytestream)
converts image data into byte array used by Jan 22, 2010

Parameters:
imagebytestream -
Returns:

getImageFormat

public String getImageFormat(InputStream imagebytestream)
returns the format name of the image data Jan 22, 2010

Parameters:
imagebytestream -
Returns:

getBounds

public short[] getBounds()
return the image bounds images bounds are as follows: bounds[0]= column # of top left position (0-based) of the shape bounds[1]= x offset within the top-left column (0-1023) bounds[2]= row # for top left corner bounds[3]= y offset within the top-left corner (0-1023) bounds[4]= column # of the bottom right corner of the shape bounds[5]= x offset within the cell for the bottom-right corner (0-1023) bounds[6]= row # for bottom-right corner of the shape bounds[7]= y offset within the cell for the bottom-right corner (0-1023)


setBounds

public void setBounds(short[] bounds)
sets the image bounds images bounds are as follows: bounds[0]= column # of top left position (0-based) of the shape bounds[1]= x offset within the top-left column (0-1023) bounds[2]= row # for top left corner bounds[3]= y offset within the top-left corner (0-1023) bounds[4]= column # of the bottom right corner of the shape bounds[5]= x offset within the cell for the bottom-right corner (0-1023) bounds[6]= row # for bottom-right corner of the shape bounds[7]= y offset within the cell for the bottom-right corner (0-1023)


getCoords

public short[] getCoords()
return the image bounds in x, y, width, height format in pixels

Returns:

setCoords

public void setCoords(int x,
                      int y,
                      int w,
                      int h)
set the image x, w, width and height in pixels

Parameters:
x -
y -
w -
h -

setX

public void setX(int x)
set the image upper x coordinate in pixels

Parameters:
x -

setY

public void setY(int y)
set the image upper y coordinate in pixels

Parameters:
y -

getRow

public int getRow()
return the topmost row of the image

Returns:

getRow1

public int getRow1()
return the lower row of the image

Returns:

setRow

public void setRow(int row)
set the topmost row of the image

Parameters:
row -

setRow1

public void setRow1(int row)
set the lower row of the image

Parameters:
row -

getCol

public int getCol()
return the leftmost column of the image


getCol1

public int getCol1()
return the rightmost column of the image


getOriginalWidth

public int getOriginalWidth()

getWidth

public short getWidth()
return the width of the image in pixels

Returns:

setWidth

public void setWidth(int w)
set the width of the image in pixels

Parameters:
w -

getHeight

public short getHeight()
return the height of the image in pixels

Returns:

setHeight

public void setHeight(int h)
set the height of the image in pixels

Parameters:
h -

getX

public short getX()
return the upper x coordinate of the image in pixels

Returns:

getY

public short getY()
return the upper y coordinate of the image in pixels

Returns:

getRowAndOffset

public short[] getRowAndOffset()
get the position of the top left corner of the image in the sheet


getColAndOffset

public short[] getColAndOffset()
get the position of the top left corner of the image in the sheet


getImageIndex

public int getImageIndex()
Internal method that converts the image bounds appropriate for saving by Excel in the MsofbtOPT record.


write

public void write(OutputStream out)
           throws IOException
write the image bytes to an outputstream such as a file

Parameters:
out -
Throws:
IOException

toString

public String toString()
Need to figure out a unique identifier for these -- if there is one in the BIFF8 information, that would be best

Overrides:
toString in class Object
See Also:
Object.toString()

remove

public boolean remove()
removes this Image from the WorkBook.

Returns:
whether the removal was a success

getImageType

public int getImageType()
Returns:
Returns the image type.

setImageType

public void setImageType(int type)
Parameters:
image_type - The image type to set.

getSheet

public com.extentech.formats.XLS.Boundsheet getSheet()
returns the WorkSheet this image is contained in

Returns:
Returns the sheet.

getName

public String getName()
Returns:
Returns the name (either explicitly set name or image name).

getImageName

public String getImageName()
return the imageName (= original file name, I believe)

Returns:

getShapeName

public String getShapeName()
returns the explicitly set shape name (set by entering text in the named range field in Excel)

Returns:
the shape name

setName

public void setName(String name)
Parameters:
name - The name to set.

setShapeName

public void setShapeName(String name)
allow setting of image name as seen in the Named Range Box

Parameters:
name -

getImageBytes

public byte[] getImageBytes()
Returns:
Returns the imageBytes.

setImageBytes

public void setImageBytes(byte[] imageBytes)
sets the underlying image bytes to the bytes from a new image essentially swapping the image bytes for another, while retaining all other image properties (borders, etc.)

Parameters:
imageBytes - The imageBytes to set.

getJSON

public org.json.JSONObject getJSON()
Get a JSON representation of the format

Parameters:
cr -
Returns:

position

public void position(ImageHandle im)
set ImageHandle position based on another

Parameters:
im - source ImageHandle

getXML

public String getXML(int rId)
return the XML representation of this image

Returns:
String

getOOXML

public String getOOXML(int rId)
return the (00)XML (or DrawingML) representation of this image

Parameters:
rId - relationship id for image file
Returns:
String

getSpPr

public com.extentech.formats.OOXML.SpPr getSpPr()
return the OOXML shape property for this image

Returns:

setSpPr

public void setSpPr(com.extentech.formats.OOXML.SpPr sp)
define the OOXML shape property for this image from an existing spPr element


setEditMovement

public void setEditMovement(String editMovement)
specify how to resize or move upon edit OOXML specific

Parameters:
editMovement -


Copyright © 2011 Extentech Inc. All Rights Reserved.