vba 如何使用 Google Translate API 翻译 Microsoft Excel 中的文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41671778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use Google Translate API to Translate text in Microsoft Excel
提问by NoobDeveloper
I am hoping someone here can help me with the google translator API. I have an excel file with about 80k rows, and I am trying to build a macro where it translates everything in a column except for the first row. As an example I have six columns in Microsoft Excel such as the below
我希望这里有人可以帮助我使用谷歌翻译 API。我有一个大约有 80k 行的 excel 文件,我正在尝试构建一个宏,它可以翻译除第一行之外的列中的所有内容。例如,我在 Microsoft Excel 中有六列,如下所示
Excel Column Headers
Excel 列标题
- Column A = Name
- Column B = Address
- Column C = Phone Number
- Column D = Request
- Column E = Google Translated Request
- Column F = Notes
- A 列 = 名称
- B 列 = 地址
- C列 = 电话号码
- D 列 = 请求
- E 列 = 谷歌翻译请求
- F 栏 = 注释
and I want to use the google translator API to take what is in column D and translate it to column E without translating what is in the first row as those are my column titles. Is this possible to do within an Excel Macro using the google translate API, and if so how would one do this?
我想使用谷歌翻译 API 将 D 列中的内容翻译成 E 列,而不翻译第一行中的内容,因为这些是我的列标题。是否可以使用谷歌翻译 API 在 Excel 宏中执行此操作,如果可以,如何执行此操作?
回答by Nicholas
In order to translate content from your Excel spreadsheets, your options would be one of the following:
为了翻译 Excel 电子表格中的内容,您可以选择以下选项之一:
- Use built-in Microsoft text translation
- Write a VBA script that communicates with the Microsoft Text Translator API
- Write a VBA script that communicates with the Google Translation API
- 使用内置的Microsoft 文本翻译
- 编写与Microsoft Text Translator API通信的 VBA 脚本
- 编写与Google Translation API通信的 VBA 脚本
Depending on the use case and how confident you are with Microsoft's translation feature, I'd probably use the built in solution as it would likely be the simplest route. Depending on the version of Excel you have, it could even be built into the menus.
根据用例以及您对 Microsoft 翻译功能的信心程度,我可能会使用内置解决方案,因为它可能是最简单的途径。根据您拥有的 Excel 版本,它甚至可以内置到菜单中。
If not, you could use VBA script to use the Microsoft Text Translator REST APIas suggested by @sysmod in a previous answer. As I'm not entirely familiar with that API, I'd strongly recommend reading the linked documentation.
如果没有,您可以使用 VBA 脚本来使用Microsoft Text Translator REST API,如@sysmod 在之前的答案中所建议的那样。由于我不完全熟悉该 API,我强烈建议您阅读链接的文档。
If you prefer to use the Google Translation API, there is a REST API that you can use as linked above. You'd essentially need to use VBA script to issue a GETor POSTrequest to https://translation.googleapis.com/language/translate/v2.
如果您更喜欢使用 Google Translation API,则可以使用上面链接的 REST API。你基本上需要使用VBA脚本发出GET或POST请求https://translation.googleapis.com/language/translate/v2。
Keep in mind that in the case of both REST APIs (Microsoft and Google alike), you would need very specific query parameters as shown in their respective linked documentation and you'd also need to authentication your project/application using a subscription keyor API key. This is the only way for Microsoft of Google to keep track of how much free quota your application has used.
请记住,对于 REST API(Microsoft 和 Google 等),您需要非常具体的查询参数,如各自链接的文档中所示,您还需要使用订阅密钥或API来验证您的项目/应用程序关键。这是 Google 的 Microsoft 跟踪您的应用程序使用了多少免费配额的唯一方法。
回答by sysmod
Built into Excel 2016: https://www.microsoft.com/en-us/translator/excel.aspx
内置于 Excel 2016:https: //www.microsoft.com/en-us/translator/excel.aspx
Not Google, but using the free Microsoft Azure API:
不是 Google,而是使用免费的 Microsoft Azure API:
https://sysmod.wordpress.com/2017/01/20/vba-code-for-microsoft-text-translator-api/
https://sysmod.wordpress.com/2017/01/20/vba-code-for-microsoft-text-translator-api/

