OfficeDev/Office-Add-in-TranslateASPNET

Name: Office-Add-in-TranslateASPNET

Owner: Office Developer

Description: The sample translates the currently selected text in a Word or Excel file into the specified language using the Microsoft Translator service

Created: 2015-08-12 17:00:58.0

Updated: 2017-01-10 21:40:44.0

Pushed: 2018-01-31 20:29:48.0

Homepage: null

Size: 11496

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Office Add-in - Use Bing Translator and ASP.NET in an add-in

Table of contents

Summary

This sample translates the currently selected text in a Word or Excel file into the specified language using the Microsoft Translator service.

This add-in gets the current selection from the Office document and then sends it to the Bing Translator service for a translation into the specified language.

Screenshot of running sample

Prerequisites

This sample requires the following:

Key components

Description of the code

The sample demonstrates two specific techniques: how to add an ASP.NET web service to an Office Add-in and how to use the Microsoft Translator service. The ASP.NET web service in the solution stores the clientID and clientSecret parameters that the Microsoft Translator service requires to obtain an access token (which, in turn, is required for calling the Microsoft Translator service for a translation).

The Translate.asmx file in the code sample handles HTTP requests coming from the add-in, sends the translation request to the Microsoft Translator service, and then returns the results to the add-in. The AdminAccess.cs file in the App_Code folder handles the access tokens returned from the Microsoft Translator service.

Build and debug
  1. To configure the Translator app, get a client ID and client secret from the Azure DataMarket. For more information, see Obtaining an Access Token.
  2. Replace the default values for clientID and clientSecret in the Translate.asmx.cs file with your own values.
  3. Open the CodeSample_TranslateASPNET.sln file in Visual Studio.
  4. Set the Start Document property of the CodeSample_TranslateASPNETWeb project to either New Excel Workbook or New Word Document.
  5. Press F5 to build and deploy the sample add-in Excel or Word.
  6. On the Home ribbon, click Open in the Translator group.
  7. Type text in a cell of the new Excel workbook or in the new Word document. Select the text.
  8. Select your From and To languages, and then press the Translate the selected word button.

Troubleshooting

Questions and comments

Additional resources
Copyright

Copyright (c) 2015 Microsoft. All rights reserved.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.