AppleScript – 将图像插入Excel时保留图像尺寸

目前,我正在创build一个工作stream程的最后阶段,这个工作stream程涉及到使用Excel中的数据插入图像的每周stream程。

我已经设法制定了Automator和Applescript的组合,以实现一个工作stream程,在Excel中获取图像,在他们的适当位置,但与我目前的苹果,他们进来一个设定的大小,100×100

这是问题:

我需要所有的图像来在100px的高度,但我需要的宽度是灵活的。 我似乎无法弄清楚这一点,我认为这将是一个苹果命令Excel的locking纵横比。

这是我用于实际图像导入的当前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

任何帮助在这里将不胜感激!

谢谢!

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

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

 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 

我testing了这个脚本(当然还有我自己的图片文件夹!),它和El Capitain和Excel 2011一起工作。

正如你所看到的,我也改变了你的代码的第一行:

要设置imageFolder,您不需要在“Finder”块中进行操作,但必须将其设置为“别名”。

要获取所有文件,您可以单独告诉“Finder”,而不告诉/结束告诉块。 (更简单)