WPS JS宏批量导入导出图片
/**
* CommandButton1_Click Macro
清除图片
*/
function CommandButton1_Click()
{
for(var pic of ActiveSheet.Shapes)
{
if(pic.Type=="13")//13等效msoPicture,通过Debug获得的值
{
pic.Delete()
}
}
}
/**
* CommandButton2_Click Macro
加载图片
*/
function CommandButton2_Click()
{
//SelectPath();
var rowmax=Worksheets(1).Range("A65536").End(xlUp).Row //获取工作表1,A列的最后一行有内容的行数
for(var range of Range("a2:a"+rowmax))
{
var picname=ThisWorkbook.Path+"\\图库\\"+range.Value2+".jpg"
var picrange=range.Offset(0,1)
try{
ActiveSheet.Shapes.AddPicture(picname,false,msoTrue,picrange.Left,picrange.Top,100,100)
}
catch{}
}
}
/**
* CommandButton3_Click Macro
保存图片
*/
function CommandButton3_Click()
{
for (let pic of Worksheets(1).Shapes)
{
if (pic.Type==msoPicture)
{
var picName=pic.TopLeftCell.Offset(1,-1).Value2 //获取图片上方单元格地址,Offset(行下移为正,列右移为正)
var picFileName=ThisWorkbook.Path+"\\存图\\"+picName+".jpg"
pic.Copy()
pic.SaveAsPicture(picFileName)
}
}
}