|

|  How to Integrate Microsoft Azure Cognitive Services with Google Sheets

How to Integrate Microsoft Azure Cognitive Services with Google Sheets

January 24, 2025

Learn to seamlessly integrate Microsoft Azure Cognitive Services with Google Sheets, automate workflows, and enhance productivity with our step-by-step guide.

How to Connect Microsoft Azure Cognitive Services to Google Sheets: a Simple Guide

 

Set Up Your Azure Cognitive Services

 

  • Sign in to the Azure Portal.
  •  

  • Navigate to "Create a resource" and select "AI + Machine Learning" and then "Cognitive Services."
  •  

  • Fill in required fields such as subscription, resource group, region, etc., and create the resource.
  •  

  • After deployment, navigate to your newly created resource and retrieve your API key and endpoint URL from the "Keys and Endpoint" section.

 

Set Up Your Google Sheets Environment

 

  • Open Google Sheets and create a new sheet.
  •  

  • Navigate to Extensions > Apps Script to open the Apps Script environment.
  •  

  • In the script editor, you'll be writing code to call the Azure Cognitive Services API.

 

Create an Azure Cognitive Services API Request

 

  • In Apps Script, write a function to make an HTTP POST request to the Azure Cognitive Services API using your endpoint and API key.
  •  

  • Here is an example of a function that sends a request to the Text Analytics API for sentiment analysis:

 

function analyzeSentiment(text) {
    const url = 'YOUR_AZURE_ENDPOINT/text/analytics/v3.1/sentiment';
    const apiKey = 'YOUR_API_KEY';

    const options = {
        method: 'POST',
        headers: {
            'Ocp-Apim-Subscription-Key': apiKey,
            'Content-Type': 'application/json'
        },
        payload: JSON.stringify({
            documents: [{
                id: '1',
                language: 'en',
                text: text
            }]
        }),
        muteHttpExceptions: true
    };

    const response = UrlFetchApp.fetch(url, options);
    const jsonResponse = JSON.parse(response.getContentText());
    return jsonResponse.documents[0].sentiment;
}

 

Integrate API with Google Sheets

 

  • Write another function to call analyzeSentiment() and get the sentiment for text in your Google Sheets.
  •  

  • Here's an example of how to use the API on a specific cell range:

 

function analyzeSheet() {
    const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    const range = sheet.getRange('A1:A10');
    const values = range.getValues();

    for (let i = 0; i < values.length; i++) {
        const sentiment = analyzeSentiment(values[i][0]);
        sheet.getRange(i + 1, 2).setValue(sentiment);
    }
}

 

Test and Deploy Your Script

 

  • Save your script and return to your Google Sheets environment.
  •  

  • Run the analyzeSheet() function from the Apps Script Editor to see the sentiment analysis appear next to your text data.
  •  

  • If you encounter "authorization required" messages, grant the necessary permissions for the script to access your Google Sheets.

 

Use Azure Cognitive Services in Google Sheets

 

  • Once integrated, you can use other Azure Cognitive Services APIs similarly by modifying the request payload and endpoint URL appropriate for the service you want to use.
  •  

  • This integration can be expanded with more functionalities, such as triggering the script automatically with Google Sheets triggers like onEdit or onOpen.

 

Omi Necklace

The #1 Open Source AI necklace: Experiment with how you capture and manage conversations.

Build and test with your own Omi.

How to Use Microsoft Azure Cognitive Services with Google Sheets: Usecases

 

Utilizing Microsoft Azure Cognitive Services with Google Sheets for Sentiment Analysis

 

Overview of the Use Case

 

  • Businesses often manage vast amounts of customer feedback data. Analyzing the sentiment of this feedback is critical to understanding customer opinions and improving services.
  •  

  • Combining Microsoft Azure Cognitive Services with Google Sheets offers a streamlined approach to perform sentiment analysis on customer feedback data without requiring advanced data science skills.

 

Integrating Microsoft Azure Cognitive Services with Google Sheets

 

  • Set up an Azure Cognitive Services account and create a Text Analytics resource for sentiment analysis.
  •  

  • Prepare a Google Sheet with columns for feedback data that needs to be analyzed.
  •  

  • Use Google Apps Script to write a custom function that sends each piece of feedback to Azure's Text Analytics API and retrieves the sentiment score.

 

Writing the Google Apps Script

 

  • Navigate to Extensions > Apps Script in Google Sheets to open the script editor.
  •  

  • Write a function in Apps Script to call the Azure Text Analytics API. Use the UrlFetchApp service in Apps Script to handle HTTP requests and specify the endpoint for sentiment analysis.
  •  

  • Parse the response from the API to extract the sentiment score or label, and return it to the appropriate cell in Google Sheets.

 

Example Code for Apps Script

 

function analyzeSentiment(feedback) {
  const apiKey = '<Your_Azure_API_Key>';
  const endpoint = 'https://<Your_Resource_Region>.api.cognitive.microsoft.com/text/analytics/v3.0/sentiment';
  const headers = {
    'Ocp-Apim-Subscription-Key': apiKey,
    'Content-Type': 'application/json'
  };
  const payload = JSON.stringify({
    "documents": [
      {
        "language": "en",
        "id": "1",
        "text": feedback
      }
    ]
  });
  
  const options = {
    'method': 'POST',
    'headers': headers,
    'payload': payload
  };
  
  const response = UrlFetchApp.fetch(endpoint, options);
  const json = JSON.parse(response.getContentText());
  
  return json.documents[0].sentiment;
}

 

Benefits of Using Azure Cognitive Services with Google Sheets

 

  • Automates the process of sentiment analysis, allowing businesses to focus on interpreting and acting on analysis results.
  •  

  • No need for manual data processing; the integration allows real-time updates and analysis, directly mapping outcomes in the Google Sheet.
  •  

  • Provides a cost-effective and scalable solution for businesses of all sizes needing reliable sentiment analysis.

 

Conclusion

 

  • This integration empowers non-technical users to leverage sophisticated AI capabilities directly within a familiar interface like Google Sheets.
  •  

  • The simplicity of Google Sheets combined with the powerful AI models from Azure makes this a highly practical solution for sentiment analysis tasks.

 

 

Transforming Document Translation with Microsoft Azure Cognitive Services and Google Sheets

 

Overview of the Use Case

 

  • Organizations often work with diverse language documents that need consistent and accurate translation to meet global audience needs.
  •  

  • Using Microsoft Azure Cognitive Services for translation directly within Google Sheets facilitates seamless document translation, ensuring quick access and consistency without investing significant resources in translation services.

 

Setting Up the Integration

 

  • Start by creating an account with Microsoft Azure and subscribing to the Translator Text API service available under Cognitive Services.
  •  

  • Prepare a Google Sheet with columns designated for original text, target language, and translated text.
  •  

  • Implement a Google Apps Script to interface with the Azure Translator API, enabling automated translation of the specified text into a selected language.

 

Developing the Google Apps Script

 

  • Open the Apps Script editor by navigating to Extensions > Apps Script in the Google Sheets menu.
  •  

  • Create a function using the Apps Script environment to communicate with the Azure Translator API. Employ the UrlFetchApp to craft HTTP requests for translation tasks.
  •  

  • Extract the translated text from the API response and place the result into the identified cell in the Google Sheet.

 

Example Script for Translation Automation

 

function translateText(text, targetLanguage) {
  const apiKey = '<Your_Azure_API_Key>';
  const endpoint = 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=' + targetLanguage;
  const headers = {
    'Ocp-Apim-Subscription-Key': apiKey,
    'Content-Type': 'application/json'
  };
  const payload = JSON.stringify([{'Text': text}]);
  
  const options = {
    'method': 'POST',
    'headers': headers,
    'payload': payload
  };
  
  const response = UrlFetchApp.fetch(endpoint, options);
  const json = JSON.parse(response.getContentText());
  
  return json[0].translations[0].text;
}

 

Advantages of the Integration

 

  • Provides instant translation of text, reducing the waiting time associated with conventional translation services and supporting real-time decision-making processes.
  •  

  • Ensures consistency across translated texts, which is critical for maintaining brand tone and messaging in multilingual environments.
  •  

  • Offers a budget-friendly solution by eliminating the need for external translation resources, while still utilizing powerful AI technologies.

 

Conclusion

 

  • This integration streamlines document translation workflows directly in Google Sheets, making it accessible instantly to business teams and stakeholders.
  •  

  • The harmonious blend of Google Sheets and Azure Translation services provides an effective pathway for multilingual communication and documentation.

 

Omi App

Fully Open-Source AI wearable app: build and use reminders, meeting summaries, task suggestions and more. All in one simple app.

Github →

OMI NECKLACE + OMI APP
First & only open-source AI wearable platform

a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded