12 AI帮你写个小插件,轻松处理Excel文件

2023/07/31閱讀時間約 4 分鐘

开头我就要跟各位先说对不起,本来我是很想为大家把这部分实现并完成的。但是很抱歉,因为我用的Mac,而这部分代码实现起来的时候一直会如下报错:

raw-image

当然,其实是可以迂回实现的,就是使用Mac本来的AppleScript,不过实现效果并不好,所以想想也就算了。毕竟我考虑,可能看我这些系列文章的人都多多少少会一点Python吧,利用Python去处理数据,怎么也比Excel强很多,再说,现在Excel+ChatGPT的组合说能实现的功能也都很有限。

这篇文章就算鸽了大家吧,当然,作为补偿,我将我自己实现过的代码贴在这里给大家做个参考,请注意,这是AppleScript的代码,请谨慎使用:

- Step 1: Prompt to choose Excel fileset excelFile to choose file with prompt "Select Excel File"
- Step 2: Open Excel file and get worksheettell application "Microsoft Excel" activate open excelFile set excelWorkbook to workbook 1 set excelSheet to sheet 1 of excelWorkbook - Step 3: Read first column and process each product titleset productTitles to value of column 1 of excelSheet set translatedResults to {} repeat with i from 1 to count of productTitles set productTitle to item i of productTitles set promptText to "Consideration product: " & productTitle & return & ¬ "1. Compose human readable product title used on Amazon in English within 20 words." & return & ¬ "2. Write 5 selling points for the products on Amazon." & return & ¬ "3. Evaluate a price range for this product in the U.S." - Step 4: Call OpenAI API and get translated resultset translatedResult to my callOpenAPI(promptText) copy translatedResult to the end of translatedResults end repeat - Step 5: Write translated results to second columnset column 2 of excelSheet to translatedResults - Step 6: Save and close Excel filesave excelWorkbook close excelWorkbook
end tellon callOpenAPI(promptText) - Call OpenAI API and return translated result- Replace this code with actual API callset translatedResult to "Translated Result" - Replace with actual translated resultreturn translatedResult
end callOpenAPI

最后,在和大家说声抱歉。咱们下期,来尝试用AI帮忙来写测试。

茶桁
茶桁
80后,先后在多家大厂担任数据产品经理,中台产品。
留言0
查看全部
發表第一個留言支持創作者!