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

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


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







当然 , 其实是可以迂回实现的,就是使用Mac本来的AppleScript,不过实现效果并不好 , 所以想想也就算了 。毕竟我考虑,可能看我这些系列文章的人都多多少少会一点Python吧,利用Python去处理数据,怎么也比Excel强很多,再说,现在Excel ChatGPT的组合说能实现的功能也都很有限 。
当然,我也可以直接将徐文浩已经实现的东西贴给大家,就像这篇文章这样:https://www.163.com/dy/article/I2K9R9QF05560XXW.html
但是,毕竟人家徐文浩是付费文章 , 这样做先不说是否有法律风险,道德上也没办法实现 。
所以 , 最后这篇文章就算鸽了大家吧,当然 , 作为补偿,我将我自己实现过的代码贴在这里给大家做个参考,请注意 , 这是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"activateopen excelFileset excelWorkbook to workbook 1set excelSheet to sheet 1 of excelWorkbook-- Step 3: Read first column and process each product titleset productTitles to value of column 1 of excelSheetset translatedResults to {}repeat with i from 1 to count of productTitlesset productTitle to item i of productTitlesset 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 translatedResultsend repeat-- Step 5: Write translated results to second columnset column 2 of excelSheet to translatedResults-- Step 6: Save and close Excel filesave excelWorkbookclose excelWorkbookend 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 translatedResultend callOpenAPI
【12. AI帮你写个小插件,轻松处理Excel文件】最后,在和大家说声抱歉 。咱们下期,来尝试用AI帮忙来写测试 。

相关经验推荐