Applescript-将图像插入Excel时保留图像尺寸

Applescript-将图像插入Excel时保留图像尺寸,excel,applescript,automator,Excel,Applescript,Automator,我目前正处于为一个非常冗长的每周流程创建工作流的最后阶段,该流程涉及使用excel中的数据插入图像 我已经成功地将Automator和Applescript结合起来,实现了一个工作流,可以在excel中的适当位置获取图像,但是使用我当前的Applescript,图像的大小是100 x 100 问题是: 我需要所有的图像来在一个100像素的高度,但我需要的宽度是灵活的。我似乎想不出这其中的最后一个部分,我假设它是excel的Applescript命令,用于锁定纵横比 以下是我用于实际图像导入的当前

我目前正处于为一个非常冗长的每周流程创建工作流的最后阶段,该流程涉及使用excel中的数据插入图像

我已经成功地将Automator和Applescript结合起来,实现了一个工作流,可以在excel中的适当位置获取图像,但是使用我当前的Applescript,图像的大小是100 x 100

问题是:

我需要所有的图像来在一个100像素的高度,但我需要的宽度是灵活的。我似乎想不出这其中的最后一个部分,我假设它是excel的Applescript命令,用于锁定纵横比

以下是我用于实际图像导入的当前applescript:

tell application "Finder"  
    set imageFolder to "Macintosh HD:Users:adlife:Desktop:Temporary_Image_Hold - Copyright Filings"  
end tell

tell application "Finder" 
    set imageList to files of folder imageFolder
end tell

tell application "Microsoft Excel"  
    set imageHeight to 100  
    set imageWidth to 100  
    set imageCount to count of imageList  
    set theRange to active cell of worksheet 1 of workbook 1  
    set thisStep to 0  
    set theLeft to left position of active cell  

repeat with imageFile in imageList

    set theTop to (top of active cell)

    set newPic to make new picture at beginning of worksheet 1 of workbook 1 with properties {file name:(imageFile as text), height:imageHeight, width:imageWidth, top:theTop, left position:theLeft, placement:placement move}


    set thisStep to thisStep + 1
end repeat  
end tell
我正在El Capitan上运行Microsoft Excel 2011

任何帮助都将不胜感激


谢谢

没有图像属性强制纵横比。用户界面中的复选框用于在用户移动或调整图像大小时锁定定量

解决方案是获取图像尺寸,并将比率(宽度/高度)应用于定义的图像高度(=100)。使用“图像事件”说明提供尺寸。然后,您可以使用新宽度作为“生成新图片”中的“宽度”属性

我测试了这个脚本(当然是用我自己的图像文件夹!),它可以与El Capitain和Excel 2011一起使用

如您所见,我还更改了代码的第一行:

要设置imageFolder,您不需要在告诉“Finder”块中进行设置。但是,必须将其设置为“alias”


要获取所有文件,您可以在单行中告诉“Finder”,而无需告诉/结束告诉块。(更简单)

没有图像属性强制高宽比。用户界面中的复选框用于在用户移动或调整图像大小时锁定定量

解决方案是获取图像尺寸,并将比率(宽度/高度)应用于定义的图像高度(=100)。使用“图像事件”说明提供尺寸。然后,您可以使用新宽度作为“生成新图片”中的“宽度”属性

我测试了这个脚本(当然是用我自己的图像文件夹!),它可以与El Capitain和Excel 2011一起使用

如您所见,我还更改了代码的第一行:

要设置imageFolder,您不需要在告诉“Finder”块中进行设置。但是,必须将其设置为“alias”


要获取所有文件,您可以在单行中告诉“Finder”,而无需告诉/结束告诉块。(更简单)

所以,我刚刚想出了一个解决方法。。。在将图像插入excel之前,我设置了一个apple脚本来运行Photoshop操作,打开图像,调整大小,然后在图像的侧面添加统一的填充。这样,所有插入excel的JPEG都是相同大小的-只是其中一些在侧面有空白,而另一些没有空白,这不会干扰excel数据,所以我们可以开始了!不过,如果你们知道怎么做的话,我仍然有兴趣纯粹用Applescript来学习这个!所以,我刚刚想出了一个解决办法。。。在将图像插入excel之前,我设置了一个apple脚本来运行Photoshop操作,打开图像,调整大小,然后在图像的侧面添加统一的填充。这样,所有插入excel的JPEG都是相同大小的-只是其中一些在侧面有空白,而另一些没有空白,这不会干扰excel数据,所以我们可以开始了!不过,如果你们知道怎么做的话,我仍然有兴趣纯粹用Applescript来学习这个!
set imageFolder to "Macintosh HD:Users:adlife:Desktop:Temporary_Image_Hold - Copyright Filings"as alias

tell application "Finder" to set imageList to files of folder imageFolder

tell application "Microsoft Excel"
set imageHeight to 100
set imageWidth to 100 -- just a default value, not really needed
set imageCount to count of imageList
set theRange to active cell of worksheet 1 of workbook 1
set thisStep to 0
set theLeft to left position of active cell

repeat with imageFile in imageList

    set theTop to (top of active cell)
    tell application "Image Events" -- open the image and get dimensions
        set theFile to imageFile as alias
        set myImage to open theFile -- don't worry, it will not open the fiel for user, only for the script !
        set {W, H} to dimensions of myImage
        set imageWidth to imageHeight * W / H -- set width using the proportion of image = W/H
    end tell
    set newPic to make new picture at beginning of worksheet 1 of workbook 1 with properties {file name:(imageFile as text), height:imageHeight, width:imageWidth, top:theTop, left position:theLeft, placement:placement move}

    set thisStep to thisStep + 1
end repeat --next image to place
end tell