Hi, Support:
I want to extract all the inserted pictures with (w,h) and (x,y) at a given row, and get the (x,y) of the Cells(Row,Column), how to reach them?
By using following code:
Dim Shapes = SrcExcel.Worksheets(0).Shapes
If Shape.GetType.FullName.ToLower.Contains(“aspose.cells.drawing.picture”) Then
x= Shape.X
y= Shape.X
w= Shape.Width
h= Shape.Height
End If
However, I do not find the method to get the (w,h) and (x,y) of Cells(2,1).
I need your help!
Thanks!
@ducaisoft
To get the dimensions (width, height) and coordinates (x, y) of a cell or pictures using Aspose.Cells for .NET, you can use the following code in VB.NET. This example will loop through all pictures on a specific row and get their dimensions and coordinates. Moreover, it will also retrieve cell’s position for a given row and column for your reference.
e.g.,
Sample code:
' Load an Excel workbook
Dim workbook As New Workbook("e:\\test2\\Bk_shapes1.xlsx")
Dim worksheet As Worksheet = workbook.Worksheets(0)
' Loop through shapes in the worksheet to find pictures at the specified row
For Each shape As Shape In worksheet.Shapes
' Check if the shape is a picture
If TypeOf shape Is Picture Then
' Get picture dimensions and coordinates
Dim pic As Picture = CType(shape, Picture)
Dim x As Integer = pic.X
Dim y As Integer = pic.Y
Dim width As Integer = pic.Width
Dim height As Integer = pic.Height
' Print or use the values
Console.WriteLine($"Picture - X: {x}, Y: {y}, Width: {width}, Height: {height}")
End If
Next
Dim row As Integer = 2 ' Replace with your desired row
Dim column As Integer = 1 ' Replace with your desired column
' Get the cell dimensions and coordinates
Dim cell As Cell = worksheet.Cells(row, column)
Dim cellWidth As Double = worksheet.Cells.GetColumnWidthPixel(column)
Dim cellHeight As Double = worksheet.Cells.GetRowHeightPixel(row)
Dim cellX As Integer = worksheet.Cells.GetColumnWidthPixel(0) * column
Dim cellY As Integer = worksheet.Cells.GetRowHeightPixel(0) * row
' You might need to sum all the leading column widths and row heights to your desired cell.
' Print or use the cell values
Console.WriteLine($"Cell - X: {cellX}, Y: {cellY}, Width: {cellWidth}, Height: {cellHeight}")
Bk_shapes1.zip (69.6 KB)
Hope, this helps a bit.