And I try the code like this: error occur : cant get the PasteSpecial property. So any other way to make it?
Code: Select all
FileSelectFile, Path
Xl := ComObjCreate("Excel.Application")
Xl.Workbooks.Open(Path) ;open an existing file
Xl.Visible := True
Xl.Range("A:A").PasteSpecial(-4163)
here is my final code, don't the unit in the excel of height and width of cell and shape is not pixel. The ratio should be 431/1607 and 269/137, not very precise, cuz I measure it by manual but works fine on me.
Any one who know the better way to calculate the ratio can amend my code and post your code ~
Code: Select all
SetTitleMatchMode, regex
;~ FileSelectFile, Path
Path := "C:\Users\HG_LiZhe\Desktop\test.xlsx"
xlApp := ComObjCreate("Excel.Application")
xlApp.Workbooks.Open(Path) ;open an existing file
xlApp.Visible := True
WinWaitActive, - Excel
WinMinimize
FileName := A_Desktop "\1.png"
xlRng := xlApp.Range("C2")
xlApp.ScreenUpdating := false
xlShape := xlApp.ActiveSheet.Shapes.AddPicture(FileName, false, true, xlRng.Left, xlRng.Top, -1, -1)
xlShape.LockAspectRatio := true
xlShape.Width := 100 ; 431
xlShape.Height := 200 ; 269
xlRng.ColumnWidth := 200 * 431/1607 ; 1607
xlRng.RowHeight := 100 * 269/137 ; 137
xlApp.ScreenUpdating := true
ExitApp