//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.getWorksheets().get(0);
//Define a string variable to store the image path.
String ImageUrl = "school.jpg";
//Get the picture into the streams.
FileInputStream fs = new FileInputStream(ImageUrl);
//Define a byte array.
byte[] imageData = new byte[fs.available()];
//Obtain the picture into the array of bytes from streams.
fs.read(imageData, 0, imageData.length);
//Close the stream.
fs.close();
//Get an excel file path in a variable.
String path = "Book1.xls";
//Get the file into the streams.
fs = new FileInputStream(path);
//Define an array of bytes.
byte[] objectData = new byte[fs.available()];
//Store the file from streams.
fs.read(objectData, 0, objectData.length);
//Close the stream.
fs.close();
//Add an Ole object into the worksheet with the image
//shown in MS Excel.
sheet.getOleObjects().add(14, 3, 200, 220, imageData);
//Set embedded ole object data.
sheet.getOleObjects().get(0).setObjectData(objectData);
//Save the excel file
workbook.save("C:\\oleobjects.xls");
Specifies whether the host application for the embedded object shall be called to load
the object data automatically when the parent workbook is opened.
Gets and sets the height scale,in unit of percent of the original picture height.
If the shape is not picture ,the HeightScale property only returns 100;
Represents the way the drawing object is attached to the cells below it.
The property controls the placement of an object on a worksheet.
The value of the property is PlacementType integer constant.
Returns a TextEffectFormat object that contains text-effect formatting properties for the specified shape.
Applies to Shape objects that represent WordArt.
Gets and sets the width scale, in unit of percent of the original picture width.
If the shape is not picture ,the WidthScale property only returns 100;
Update the selected value by the value of the linked cell.
Property Getters/Setters Detail
isAutoSize/setAutoSize
public boolean isAutoSize() / public void setAutoSize(boolean value)
True indicates that the size of the ole object will be auto changed as the size of snapshot of the embedded content
when the ole object is activated.
isLink/setLink
public boolean isLink() / public void setLink(boolean value)
Returns true if the OleObject links to the file.
getDisplayAsIcon/setDisplayAsIcon
public boolean getDisplayAsIcon() / public void setDisplayAsIcon(boolean value)
True if the specified object is displayed as an icon
and the image will not be auto changed.
getImageData/setImageData
public byte[] getImageData() / public void setImageData(byte[] value)
Represents image of ole object as byte array.
getObjectData/setObjectData
public byte[] getObjectData() / public void setObjectData(byte[] value)
Represents embedded ole object data as byte array.
getFullObjectBin
public byte[] getFullObjectBin()
Gets the full embedded ole object binary data in the template file.
getImageSourceFullName/setImageSourceFullName
public java.lang.String getImageSourceFullName() / public void setImageSourceFullName(java.lang.String value)
Gets or sets the path and name of the source file for the linked image.
The default value is an empty string.
If SourceFullName is not an empty string, the image is linked.
If SourceFullName is not an empty string, but Data is null, then the image is linked and not stored in the file.
getProgID/setProgID
public java.lang.String getProgID() / public void setProgID(java.lang.String value)
Gets or sets the ProgID of the OLE object.
getFileFormatType/setFileFormatType
public int getFileFormatType() / public void setFileFormatType(int value)
Gets and sets the file type of the embedded ole object data
The value of the property is FileFormatType integer constant.
getObjectSourceFullName/setObjectSourceFullName
public java.lang.String getObjectSourceFullName() / public void setObjectSourceFullName(java.lang.String value)
Returns the source full name of the source file for the linked OLE object.
Only supports setting the source full name when the file type is OleFileType.Unknown.
Such as wav file ,avi file..etc..
getLabel/setLabel
public java.lang.String getLabel() / public void setLabel(java.lang.String value)
Gets and sets the display label of the linked ole object.
getSourceFullName/setSourceFullName
public java.lang.String getSourceFullName() / public void setSourceFullName(java.lang.String value)
Returns the source full name of the source file for the linked OLE object.
NOTE: This member is now obsolete. Instead,
please use OleObject.ObjectSourceFullName property.
This property will be removed 12 months later since November 2013.
Aspose apologizes for any inconvenience you may have experienced.
getAutoUpdate/setAutoUpdate
public boolean getAutoUpdate() / public void setAutoUpdate(boolean value)
Specifies whether the link to the OleObject is automatically updated or not.
getAutoLoad/setAutoLoad
public boolean getAutoLoad() / public void setAutoLoad(boolean value)
Specifies whether the host application for the embedded object shall be called to load
the object data automatically when the parent workbook is opened.
getClassIdentifier/setClassIdentifier
public byte[] getClassIdentifier() / public void setClassIdentifier(byte[] value)
Gets and sets the class identifier of the embedded object.
It means which application opens the embedded file.
getImageType
public int getImageType()
Gets the image format of the ole object.
The value of the property is ImageType integer constant.
Returns a MsoLineFormat object that contains line formatting properties for the specified shape.
NOTE: This member is now obsolete. Instead,
please use Shape.Line property.
This property will be removed 12 months later since July 2016.
Aspose apologizes for any inconvenience you may have experienced.
Returns a MsoFillFormat object that contains fill formatting properties for the specified shape.
NOTE: This member is now obsolete. Instead,
please use Shape.Fill property.
This property will be removed 12 months later since July 2016.
Aspose apologizes for any inconvenience you may have experienced.
Represents the setting of the shape's formatting.
NOTE: This member is now obsolete. Instead,
please use Shape.Fill and Shape.Line properties.
This property will be removed 6 months later since August 2016.
Aspose apologizes for any inconvenience you may have experienced.
Returns a TextFrame object that contains the alignment and anchoring properties for the specified shape.
NOTE: This member is now obsolete. Instead,
please use Shape.TextBody.TextAlignment property.
This property will be removed 12 months later since May 2016.
Aspose apologizes for any inconvenience you may have experienced.
Returns a TextEffectFormat object that contains text-effect formatting properties for the specified shape.
Applies to Shape objects that represent WordArt.
public int getPlacement() / public void setPlacement(int value)
Represents the way the drawing object is attached to the cells below it.
The property controls the placement of an object on a worksheet.
The value of the property is PlacementType integer constant.
Example:
if (shape.getPlacement() == PlacementType.MOVE)
shape.setPlacement(PlacementType.MOVE_AND_SIZE);
public int getTop() / public void setTop(int value)
Represents the vertical offset of shape from its top row, in unit of pixels.
If the shape is in the chart, represents the vertical offset of shape from its top border.
public int getWidthScale() / public void setWidthScale(int value)
Gets and sets the width scale, in unit of percent of the original picture width.
If the shape is not picture ,the WidthScale property only returns 100;
Example:
if (shape.getWidthScale() == 3)
shape.setWidthScale(1);
public int getHeightScale() / public void setHeightScale(int value)
Gets and sets the height scale,in unit of percent of the original picture height.
If the shape is not picture ,the HeightScale property only returns 100;
Example:
if (shape.getHeightScale() == 3)
shape.setHeightScale(1);
public int getTopInShape() / public void setTopInShape(int value)
Represents the vertical offset of shape from the top border of the parent shape,
in unit of 1/4000 of height of the parent shape.
Only Applies when this shape in the group or chart.
Example:
if (shape.getTopInShape() == 8000)
shape.setTopInShape(4000);
public int getLeftInShape() / public void setLeftInShape(int value)
Represents the horizontal offset of shape from the left border of the parent shape,
in unit of 1/4000 of width of the parent shape.
Only Applies when this shape in the group or chart.
Example:
if (shape.getUpperDeltaY() == 2000)
shape.setUpperDeltaY(4000);
public int getHeightInShape() / public void setHeightInShape(int value)
Represents the vertical offset of shape from the top border of the parent shape, in unit of 1/4000 of height of the parent shape..
Only Applies when this shape in the group or chart.
Example:
if (shape.getUpperDeltaY() == 4000)
shape.setUpperDeltaY(2000);
public int getHeightInChart() / public void setHeightInChart(int value)
Represents the vertical offset of shape from the top border of the parent shape, in unit of 1/4000 of height of the parent shape..
NOTE: This member is now obsolete. Instead,
please use Aspose.Cells.Drawing.Shape.HeightInShape property.
This property will be removed 12 months later since JANUARY 2012.
Aspose apologizes for any inconvenience you may have experienced.
public int getLeftInChart() / public void setLeftInChart(int value)
Represents the vertical offset of shape from the left border of the parent shape, in unit of 1/4000 of width of the parent shape.
NOTE: This member is now obsolete. Instead,
please use Aspose.Cells.Drawing.Shape.LeftInShape property.
This property will be removed 12 months later since JANUARY 2012.
Aspose apologizes for any inconvenience you may have experienced.
public int getTopInChart() / public void setTopInChart(int value)
Represents the vertical offset of shape from the top border of the parent shape, in unit of 1/4000 of height of the parent shape.
NOTE: This member is now obsolete. Instead,
please use Aspose.Cells.Drawing.Shape.TopInShape property.
This property will be removed 12 months later since JANUARY 2012.
Aspose apologizes for any inconvenience you may have experienced.
public int getWidthInChart() / public void setWidthInChart(int value)
Represents the width of the shape, in unit of 1/4000 of the parent shape.
NOTE: This member is now obsolete. Instead,
please use Aspose.Cells.Drawing.Shape.WidthInShape property.
This property will be removed 12 months later since JANUARY 2012.
Aspose apologizes for any inconvenience you may have experienced.
public int getPositionX() / public void setPositionX(int value)
Gets and sets the horizonal offset of shape from worksheet left border,in unit of pixels.
NOTE: This member is now obsolete. Instead,
please use Aspose.Cells.Drawing.Shape.X property.
This property will be removed 12 months later since JANUARY 2012.
Aspose apologizes for any inconvenience you may have experienced.
public int getPositionY() / public void setPositionY(int value)
Gets and sets the vertical offset of shape from worksheet top border,in unit of pixels.
NOTE: This member is now obsolete. Instead,
please use Aspose.Cells.Drawing.Shape.Y property.
This property will be removed 12 months later since JANUARY 2012.
Aspose apologizes for any inconvenience you may have experienced.
public java.awt.geom.Point2D.Float[] getConnectionPoints()
Get the connection points
NOTE: This member is now obsolete. Instead,
please use GetConnectionPoints() method.
This method will be removed 12 months later since April 2022.
Aspose apologizes for any inconvenience you may have experienced.
public int getTextVerticalOverflow() / public void setTextVerticalOverflow(int value)
Gets and sets the text vertical overflow type of the shape which contains text.
The value of the property is TextOverflowType integer constant.
Example:
if (shape.getTextVerticalOverflow() == com.aspose.cells.TextOverflowType.CLIP)
shape.setTextVerticalOverflow(com.aspose.cells.TextOverflowType.OVERFLOW);
public int getTextHorizontalOverflow() / public void setTextHorizontalOverflow(int value)
Gets and sets the text horizontal overflow type of the shape which contains text.
The value of the property is TextOverflowType integer constant.
Example:
if (shape.getTextHorizontalOverflow() == com.aspose.cells.TextOverflowType.CLIP)
shape.setTextHorizontalOverflow(com.aspose.cells.TextOverflowType.OVERFLOW);
public int getTextOrientationType() / public void setTextOrientationType(int value)
Gets and sets the text orientation type of the shape.
The value of the property is TextOrientationType integer constant.
Example:
if (shape.getTextOrientationType() == com.aspose.cells.TextOrientationType.NO_ROTATION)
shape.setTextOrientationType(com.aspose.cells.TextOrientationType.TOP_TO_BOTTOM);
public int getTextHorizontalAlignment() / public void setTextHorizontalAlignment(int value)
Gets and sets the text horizontal alignment type of the shape.
The value of the property is TextAlignmentType integer constant.
Example:
if (shape.getTextHorizontalAlignment() == com.aspose.cells.TextAlignmentType.BOTTOM)
shape.setTextHorizontalAlignment(com.aspose.cells.TextAlignmentType.CENTER);
public int getTextVerticalAlignment() / public void setTextVerticalAlignment(int value)
Gets and sets the text vertical alignment type of the shape.
The value of the property is TextAlignmentType integer constant.
Example:
if (shape.getTextVerticalAlignment() == com.aspose.cells.TextAlignmentType.BOTTOM)
shape.setTextVerticalAlignment(com.aspose.cells.TextAlignmentType.CENTER);
CheckBoxActiveXControl checkBox1 = (CheckBoxActiveXControl)shape.getActiveXControl();
//The font name of CheckBox
String fontName = checkBox1.getFont().getName();
public void setLinkedCell(java.lang.String formula, boolean isR1C1, boolean isLocal)
Sets the range linked to the control's value.
Parameters:
formula - The range linked to the control's value.
isR1C1 - Whether the formula needs to be formatted as R1C1.
isLocal - Whether the formula needs to be formatted by locale.
Example:
//After executing the code below, a ScrollBar object is created in the generated file. As you drag the slider, the value is displayed in cell A12.
//ActiveX Controls
//Aspose.Cells.Drawing.Shape scrollBar = book.Worksheets[0].Shapes.AddActiveXControl( Aspose.Cells.Drawing.ActiveXControls.ControlType.ScrollBar,2, 0, 2, 0, 30, 130);
//Form Controls
Shape scrollBar = book.getWorksheets().get(0).getShapes().addScrollBar(2, 0, 2, 0, 130, 30);
//Sets the range linked to the control's value.
scrollBar.setLinkedCell("$A$12", false, true);
public void setInputRange(java.lang.String formula, boolean isR1C1, boolean isLocal)
Sets the range used to fill the control.
Parameters:
formula - The range used to fill the control.
isR1C1 - Whether the formula needs to be formatted as R1C1.
isLocal - Whether the formula needs to be formatted by locale.
Example:
//After executing the code below, a ListBox object is created in the generated file. When the selected option is clicked, the selected value is displayed in cell A12.
//Initialize a new workbook.
//Workbook book = new Workbook();
for (int i = 0; i< 10; ++i)
{
Cell cell = book.getWorksheets().get(0).getCells().get(i, 0);
cell.setValue(i + 1);
}
//Create a ListBox object
//ActiveX Controls
//Aspose.Cells.Drawing.Shape listBox = book.Worksheets[0].Shapes.AddActiveXControl( Aspose.Cells.Drawing.ActiveXControls.ControlType.ListBox,2, 0, 2, 0, 130, 130);
//Form Controls
Shape listBox = book.getWorksheets().get(0).getShapes().addListBox(2, 0, 2, 0, 130, 130);
//Sets the range used to fill the control.
listBox.setInputRange("$A$1:$A$6", false, false);
//Sets the range linked to the control's value.
listBox.setLinkedCell("$A$12", false, true);
public void updateSelectedValue()
throws java.lang.Exception
Update the selected value by the value of the linked cell.
Example:
//Initialize a new workbook.
//Workbook book = new Workbook();
Cell cell = null;
for (int i = 0; i< 10; ++i)
{
cell = book.getWorksheets().get(0).getCells().get(i, 0);
cell.setValue(i + 1);
}
//Create a ListBox object
//ActiveX Controls
//Aspose.Cells.Drawing.Shape listBox = book.Worksheets[0].Shapes.AddActiveXControl( Aspose.Cells.Drawing.ActiveXControls.ControlType.ListBox,2, 0, 2, 0, 130, 130);
//Form Controls
Shape listBox = book.getWorksheets().get(0).getShapes().addListBox(2, 0, 2, 0, 130, 130);
//Sets the range used to fill the control.
listBox.setInputRange("$A$1:$A$6", false, false);
//Sets the range linked to the control's value.
listBox.setLinkedCell("$A$12", false, true);
ListBox listbx = (ListBox)listBox;
//Set the value of cell A12
cell = book.getWorksheets().get(0).getCells().get(11, 0);
cell.setValue(3);
//Update the selected value by the value of the linked cell.
listBox.updateSelectedValue();
//-1 default, no option selected
if(listbx.isSelected(2))
{
//Option 3 of the ListBox is selected
}
//Change the value of a linked cell
cell.setValue(4);
//Update the selected value by the value of the linked cell.
listBox.updateSelectedValue();
if(listbx.isSelected(3))
{
//Option 4 of the ListBox is selected
}
public void formatCharacters(int startIndex, int length, Font font)
Formats some characters with the font setting.
NOTE: This member is now obsolete. Instead,
please use Shape.FormatCharacters(int startIndex, int length, Font font, StyleFlag flag) method.
This property will be removed 12 months later since March 2016.
Aspose apologizes for any inconvenience you may have experienced.