复选框动态加载图片减少文件大小

function 加载图片(){		
console.clear()	
//let sheet = Application.Workbooks.Item(1).Sheets.Item(1)	
let shapes = ActiveSheet.Shapes;	
for(let shape of shapes){		
console.log(shape.Name);		
if(String(shape.Name).indexOf("Check") == 0){			
 if(shape.ControlFormat.Value == 1){			 	
//选中			    
shape.TopLeftCell.Offset(0,1).GetRangeEx().InsertCellPicture(shape.Hyperlink.Address);				 				 }else{			 	
// value == 0 取消选中			 				 	
shape.TopLeftCell.Offset(0,1).Value2 = '';			 }					}	}	}
function test(){	
let sheet = Application.Workbooks.Item(1).Sheets.Item(1);	
let shapes = sheet.Shapes; 	
let row = 5;	
let col = 3;	
let cell = sheet.Cells.Rows.Item(row).Columns.Item(col);	
let shape = shapes.AddFormControl(xlCheckBox, cell.Left+2,cell.Top+1, sheet.Cells.Columns.Item(col).Width-2, sheet.Cells.Rows.Item(row).RowHeight)-2;	
shape.ControlFormat.Enabled = true;	
shape.ControlFormat.LinkedCell = "";	
shape.ControlFormat.LockedText = false;	
//shape.ControlFormat.Value = 1 //;    
shape.TextFrame2.TextRange.Text = "展示图片";    
shape.OnAction = "加载图片";    
sheet.Hyperlinks.Add(shape,"C:/Users/Computer/Pictures/屏幕截图 2026-02-09 092728.bmp");}

提示,文件属性,安全选项卡,复制对象全路径名称时注意,容易有空字符,触发Jsa路径解析错误。

黑龙江省
浏览 94
收藏
5
分享
5 +1
2
+1
全部评论 2
 
√Max
确实加入几张图片后文件变大,压缩图片又要钱钱,且会牺牲分辨率
· 四川省
回复
 
恰同学少年
恰同学少年 let shape = shapes.AddFormControl(xlCheckBox, cell.Left+2,cell.Top+1, sheet.Cells.Columns.Item(col).Width-2, sheet.Cells.Rows.Item(row).RowHeight)-2; +2 +1 -2 -2 影响 TopLeftCell取单元格对象的准确程度。+2 +1后,让shape图形的左上角确保在当前单元格内。实际使用,可按需调整。
· 黑龙江省
回复