Back to Devexpress

How to: Modify a Picture

officefileapi-113744-spreadsheet-document-api-examples-pictures-how-to-modify-an-embedded-picture.md

latest2.5 KB
Original Source

How to: Modify a Picture

  • Mar 20, 2024
  • 2 minutes to read

The example below demonstrates how to use various properties and methods of the Picture object to modify a picture inserted in a worksheet.

View Example

csharp
// Set the measurement unit to Millimeter.
workbook.Unit = DevExpress.Office.DocumentUnit.Millimeter;
workbook.BeginUpdate();
try
{
    Worksheet worksheet = workbook.Worksheets[0];
    // Insert pictures from the file.
    Picture pic = worksheet.Pictures.AddPicture("Pictures\\x-docserver.png", worksheet.Cells["A1"]);
    // Specify picture name and draw a border.
    pic.Name = "Logo";
    pic.AlternativeText = "Spreadsheet Logo";
    pic.BorderWidth = 1;
    pic.BorderColor = DevExpress.Utils.DXColor.Black;
    // Move a picture.
    pic.Move(20, 30);
    // Change picture behavior so it will move and size with underlying cells. 
    pic.Placement = Placement.MoveAndSize;
    worksheet.Rows[5].Height += 10;
    worksheet.Columns["D"].Width += 10;
    // Specify rotation angle.
    pic.Rotation = 30;
    // Add a hyperlink.
    pic.InsertHyperlink("https://www.devexpress.com/products/net/office-file-api/", true);
}
finally
{
    workbook.EndUpdate();
}
vb
' Set the measurement unit to Millimeter.
workbook.Unit = DevExpress.Office.DocumentUnit.Millimeter
workbook.BeginUpdate()
Try
    Dim worksheet As Worksheet = workbook.Worksheets(0)
    ' Insert pictures from the file.
    Dim pic As Picture = worksheet.Pictures.AddPicture("Pictures\x-docserver.png", worksheet.Cells("A1"))
    ' Specify picture name and draw a border.
    pic.Name = "Logo"
    pic.AlternativeText = "Spreadsheet Logo"
    pic.BorderWidth = 1
    pic.BorderColor = DevExpress.Utils.DXColor.Black
    ' Move a picture.
    pic.Move(20, 30)
    ' Change picture behavior so it will move and size with underlying cells. 
    pic.Placement = Placement.MoveAndSize
    worksheet.Rows(5).Height += 10
    worksheet.Columns("D").Width += 10
    ' Specify rotation angle.
    pic.Rotation = 30
    ' Add a hyperlink.
    pic.InsertHyperlink("https://www.devexpress.com/products/net/office-file-api/", True)
Finally
    workbook.EndUpdate()
End Try

See Also

How to: Insert and Delete Pictures