Skip to main content

Insert-Image

Command Description

Insert an image in the worksheet. If the specified image name already exists, replace the existing image

Command Prototype

Excel.InsertImage(objExcelWorkBook,sheet,sFilePath,sName,fLeft,fTop,fWidth,fHeight)

Parameter Description

ParameterRequiredTypeDefaultDescription
objExcelWorkBookTrueexpressionobjExcelWorkBookExcel workbook object (workbook opened with "Open Excel" command (Excel.OpenExcel) or the workbook object returned by the command "Bind Excel" (Excel.BindBook))
sheetTruestring"Sheet1"The string means sheet name. The number means sheet order(starting from 0)
sFilePathTruepath'''C:\Users'''Path to the image file to insert
sNameTruestring""Default value is empty string, which is automatically arranged by Excel. If you need to delete or update the corresponding picture, it is recommended to modify the name
fLeftTrueexpression0The margin to the left of the image
fTopTrueexpression0The margin to the top of the image
fWidthTrueexpression100The width of the image, calculated as percentage of the original image
fHeightTrueexpression100The height of the image, calculated as percentage of the original image

Demo

/************************INSERT PICTURE************************ ******** 
**Input 1:
** objExcelWorkBook--Excel workbook object (a workbook opened using the "Open Excel" command (Excel.OpenExcel) or a job bound using the "Bind Excel" command (Excel.BindBook) book object).
**Entry 2:
** sheet--If a string is used, it means the name of the specified worksheet; if a number is used, it means the order of the specified worksheet (starting from 0).
**Entry 3:
** sFilePath--The path of the image file to be inserted.
**Entry 4:
** sName--The default value is an empty string, which is automatically arranged by Excel. If you want to delete or update the corresponding picture, it is recommended to modify the name.
**Entry 5:
** fLeft--The left margin of the image.
**Entry 6:
** fTop--The margin of the image from the top.
**Into reference 7:
** fWidth--the width of the image, calculated as a percentage of the original image.
** Entry 8:
** fHeight--The height of the image, calculated as a percentage of the original image.
**
*********************************************************************/

objExcelWorkBook = Excel.OpenExcel(@res"Test.xlsx",True,"Excel","","")
Excel.InsertImage(objExcelWorkBook,"Sheet1",@res"example image.png","example",0,0,100,100)
TracePrint "Insert a picture: Insert a picture named 'Example' in the Excel object Sheet1 worksheet
Excel.CloseExcel(objExcelWorkBook,True)