开头我就要跟各位先说对不起,本来我是很想为大家把这部分实现并完成的。但是很抱歉,因为我用的Mac,而这部分代码实现起来的时候一直会如下报错:
当然,其实是可以迂回实现的,就是使用Mac本来的AppleScript,不过实现效果并不好,所以想想也就算了。毕竟我考虑,可能看我这些系列文章的人都多多少少会一点Python吧,利用Python去处理数据,怎么也比Excel强很多,再说,现在Excel+ChatGPT的组合说能实现的功能也都很有限。
当然,我也可以直接将徐文浩已经实现的东西贴给大家,就像这篇文章这样:https://www.163.com/dy/article/I2K9R9QF05560XXW.html
但是,毕竟人家徐文浩是付费文章,这样做先不说是否有法律风险,道德上也没办法实现。
所以,最后这篇文章就算鸽了大家吧,当然,作为补偿,我将我自己实现过的代码贴在这里给大家做个参考,请注意,这是AppleScript的代码,请谨慎使用:
-- Step 1: Prompt to choose Excel file
set excelFile to choose file with prompt "Select Excel File"
-- Step 2: Open Excel file and get worksheet
tell 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 title
set 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 result
set translatedResult to my callOpenAPI(promptText)
copy translatedResult to the end of translatedResults
end repeat
-- Step 5: Write translated results to second column
set column 2 of excelSheet to translatedResults
-- Step 6: Save and close Excel file
save excelWorkbook
close excelWorkbook
end tell
on callOpenAPI(promptText)
-- Call OpenAI API and return translated result
-- Replace this code with actual API call
set translatedResult to "Translated Result" -- Replace with actual translated result
return translatedResult
end callOpenAPI
最后,在和大家说声抱歉。咱们下期,来尝试用AI帮忙来写测试。