[]
Creates a picture from an existing file and returns the IShape object that represents the new picture.
Use this method to place a picture at a specific position on the current sheet.
The left and top values are measured in points
relative to the upper-left corner of the document.
IShape AddPicture(string filename, double left, double top, double width, double height)
Function AddPicture(filename As String, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| string | filename | The file from which the object is to be created. null is not supported. |
| double | left | The position, in points, of the upper-left corner of the picture relative to the upper-left corner of the document. |
| double | top | The position, in points, of the upper-left corner of the picture relative to the top of the document. |
| double | width | The width of the picture, in points. |
| double | height | The height of the picture, in points. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
try
{
string imagePath = System.IO.Path.Combine("Users", "DefaultApps", "Documents", "logo.png");
IShape picture = worksheet.Shapes.AddPicture(imagePath, 20, 20, 120, 80);
picture.Name = "Logo";
}
catch (IOException ex)
{
throw new InvalidOperationException("Unable to add picture from file", ex);
}
| Type | Condition |
|---|---|
| IOException | Thrown if the specified file cannot be read. |
Creates a picture from an existing file at the specified range on the current sheet.
The worksheet of targetRange and the worksheet that receives the new shape must be the same.
IShape AddPicture(string filename, IRange targetRange)
Function AddPicture(filename As String, targetRange As IRange) As IShape
| Type | Name | Description |
|---|---|---|
| string | filename | The file from which the picture is created. |
| IRange | targetRange | The target range on the current sheet. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
IRange targetRange = worksheet.Range["B2:D8"];
string imagePath = System.IO.Path.Combine("Users", "DefaultApps", "Documents", "logo.png");
IShape picture = worksheet.Shapes.AddPicture(imagePath, targetRange);
picture.AlternativeText = "Product image";
| Type | Condition |
|---|---|
| IOException | Thrown if the specified file cannot be read. |
Creates a picture from an existing file and adds it to the worksheet at the specified position and size.
The picture is positioned in points relative to the upper-left corner of the document.
IShape AddPicture(string name, string filename, double left, double top, double width, double height)
Function AddPicture(name As String, filename As String, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The picture name. |
| string | filename | The file from which the object is to be created. |
| double | left | The position (in points) of the upper-left corner of the picture relative to the upper-left corner of the document. |
| double | top | The position (in points) of the upper-left corner of the picture relative to the top of the document. |
| double | width | The width of the picture, in points. |
| double | height | The height of the picture, in points. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
try
{
string imagePath = System.IO.Path.Combine("Users", "DefaultApps", "Documents", "logo.png");
IShape picture = worksheet.Shapes.AddPicture("CompanyLogo", imagePath, 20, 20, 120, 80);
picture.Name = "CompanyLogo";
}
catch (IOException ex)
{
throw new InvalidOperationException("Unable to add picture by name from file", ex);
}
| Type | Condition |
|---|---|
| IOException | Thrown if the picture file cannot be read. |
Creates a picture from an existing file at the specified range on the current sheet.
The worksheet of targetRange and the worksheet that receives the new shape must be the same.
IShape AddPicture(string name, string filename, IRange targetRange)
Function AddPicture(name As String, filename As String, targetRange As IRange) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The picture name. |
| string | filename | The file from which the picture is created. |
| IRange | targetRange | The target range on the current sheet. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
IRange targetRange = worksheet.Range["B2:D8"];
string imagePath = System.IO.Path.Combine("Users", "DefaultApps", "Documents", "logo.png");
IShape picture = worksheet.Shapes.AddPicture("ProductImage", imagePath, targetRange);
picture.AlternativeText = "Product image";
| Type | Condition |
|---|---|
| IOException | Thrown if the picture file cannot be read. |
Creates a picture from an existing stream.
Returns the IShape object that represents the new picture.
IShape AddPicture(Stream stream, ImageType type, double left, double top, double width, double height)
Function AddPicture(stream As Stream, type As ImageType, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream from which the object is to be created. |
| ImageType | type | Specifies the type of picture to create. |
| double | left | The position (in points) of the upper-left corner of the picture relative to the upper-left corner of the document. |
| double | top | The position (in points) of the upper-left corner of the picture relative to the top of the document. |
| double | width | The width of the picture, in points. |
| double | height | The height of the picture, in points. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
using (MemoryStream stream = CreateSampleImageStream())
{
IShape picture = worksheet.Shapes.AddPicture(stream, ImageType.PNG, 20, 20, 80, 60);
picture.Name = "Logo";
}
| Type | Condition |
|---|---|
| IOException | Thrown if an I/O error occurs while reading the stream. |
Creates a picture from an existing stream at the specified range on the current sheet.
The sheet of targetRange and the sheet of the shape being added must be the same sheet.
Returns the IShape object that represents the new picture.
IShape AddPicture(Stream stream, ImageType type, IRange targetRange)
Function AddPicture(stream As Stream, type As ImageType, targetRange As IRange) As IShape
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream from which the object is to be created. |
| ImageType | type | Specifies the type of picture to create. |
| IRange | targetRange | The target range on the current sheet. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
IRange targetRange = worksheet.Range["B2:D6"];
using (MemoryStream stream = CreateSampleImageStream())
{
IShape picture = worksheet.Shapes.AddPicture(stream, ImageType.PNG, targetRange);
picture.AlternativeText = "Company logo";
}
| Type | Condition |
|---|---|
| IOException | Thrown if an I/O error occurs while reading the stream. |
Creates a picture from an existing stream.
Returns the IShape object that represents the new picture.
IShape AddPicture(string name, Stream stream, ImageType type, double left, double top, double width, double height)
Function AddPicture(name As String, stream As Stream, type As ImageType, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The picture name. |
| Stream | stream | The stream from which the object is to be created. |
| ImageType | type | Specifies the type of picture to create. |
| double | left | The position (in points) of the upper-left corner of the picture relative to the upper-left corner of the document. |
| double | top | The position (in points) of the upper-left corner of the picture relative to the top of the document. |
| double | width | The width of the picture, in points. |
| double | height | The height of the picture, in points. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
using (MemoryStream stream = CreateSampleImageStream())
{
IShape picture = worksheet.Shapes.AddPicture("CompanyLogo", stream, ImageType.PNG, 20, 20, 120, 80);
picture.AlternativeText = "Company logo";
}
| Type | Condition |
|---|---|
| IOException | Thrown if an I/O error occurs while reading the stream. |
Creates a picture from an existing stream at the specified range on the current sheet.
The worksheet of targetRange and the worksheet to which the shape is added must be the same.
Returns the IShape object that represents the new picture.
IShape AddPicture(string name, Stream stream, ImageType type, IRange targetRange)
Function AddPicture(name As String, stream As Stream, type As ImageType, targetRange As IRange) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The picture name. |
| Stream | stream | The stream from which the picture is created. |
| ImageType | type | Specifies the type of picture to create. |
| IRange | targetRange | The target range on the current sheet. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
IRange targetRange = worksheet.Range["B2:D6"];
using (MemoryStream stream = CreateSampleImageStream())
{
IShape picture = worksheet.Shapes.AddPicture("CompanyLogo", stream, ImageType.PNG, targetRange);
picture.AlternativeText = "Company logo";
}
| Type | Condition |
|---|---|
| IOException | Thrown if an I/O error occurs while reading the stream. |