- (defun excel-inspic (xlapp sh-n ID path
- xlapprelease LST /
- H H1 L Mergerange
- P Pic Picname sc
- ShapeRange W W1
- xlrange xlsheet
- )
- ;插入图片
- ;xlapp excel对象
- ;sh-n sheet表名
- ;id 单元格
- ;path 图片路径
- ;xlapprelease 程序结束后是否需要释放excel?
- ;lst 预留参数
- (setq xlsheet sh-n);(vlax-get-property (vlax-get-property (vlax-get-property xlapp 'activeworkbook) 'Sheets) 'Item sh-n))
- (setq Pic (vlax-invoke-method (vlax-invoke-method xlsheet 'Pictures) 'Insert path))
- (setq Picname (vlax-get-property Pic 'Name))
- (setq W1 (vlax-get-property Pic 'Width))
- (setq H1 (vlax-get-property Pic 'Height))
- (setq xlrange (vlax-get-property (vlax-get (vlax-get-property xlapp "ActiveWorkbook") 'ActiveSheet) 'range id))
- (setq L (vlax-variant-value (vlax-get-property xlrange 'Left)))
- (SETQ P (vlax-variant-value (vlax-get-property xlrange 'Top)))
- (SETQ W (vlax-variant-value (vlax-get-property xlrange 'Width)))
- (SETQ H (vlax-variant-value (vlax-get-property xlrange 'Height)))
- (vlax-put-property Pic 'Left L)
- (vlax-put-property Pic 'Top P)
- (setq ShapeRange (vlax-get-property (vlax-get-property xlsheet 'Shapes) 'Range Picname))
- (vlax-put-property ShapeRange 'LockAspectRatio)
- (if (AND W
- (NOT (VL-CATCH-ALL-ERROR-P W))
- W1
- (NOT (VL-CATCH-ALL-ERROR-P W1))
- H1
- (NOT (VL-CATCH-ALL-ERROR-P H1))
- H
- (NOT (VL-CATCH-ALL-ERROR-P H))
- )
- (if (>= (/ W H) (/ W1 H1))
- (progn
- (SETQ SC (/ (- W (* (/ W1 H1) H)) 2))
- (vlax-put-property ShapeRange 'Height H)
- (vlax-invoke-method ShapeRange 'IncrementLeft SC)
- )
- (progn
- (SETQ SC (/ (- H (* (/ H1 W1) W)) 2))
- (vlax-put-property ShapeRange 'Width W)
- (vlax-invoke-method ShapeRange 'IncrementTop SC)
- )
- )
- (vlax-put-property Pic 'Placement (vlax-make-variant 1 2))
- )
- (princ)
- )
代码是在论坛找的 ,相关ActiveX方法实在是找不到说明 帮助文件里没有,求大神答疑解惑
|