You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Microsoft Cognitive Services分析Office文档及Word关键短语分析的技术问询

Using Microsoft Cognitive Services with Microsoft Office Documents

Hey there! Let's tackle your questions one by one:

1. Can Microsoft Cognitive Services analyze Microsoft Office documents directly?

Short answer: Not directly for most text-focused APIs (like Key Phrase Extraction). Most Cognitive Services text analysis APIs expect plain text or structured JSON as input, so you'll need to first extract the text content from your Office documents before sending it to the service. That said, there are straightforward workarounds to make this happen—read on for details!

2. How to do key phrase analysis on a Word document when the API only accepts JSON?

Absolutely feasible! The core idea is to extract the text from your Word document first, then format it into the JSON structure the API expects. Here are three practical approaches:

Option 1: Use Microsoft Office Interop Libraries (.NET environment)

If you're working with .NET and have Microsoft Office installed on your machine, you can use the Interop libraries to programmatically open and extract text from Word documents. Here's a quick code snippet:

using Microsoft.Office.Interop.Word;

// Initialize Word application
Application wordApplication = new Application();
// Open the target document
Document wordDocument = wordApplication.Documents.Open(@"C:\your\document\path\file.docx");
// Extract full text content
string documentText = wordDocument.Content.Text;
// Clean up
wordDocument.Close();
wordApplication.Quit();

Once you have documentText, format it into the required JSON payload and send it to the Key Phrase Extraction API:

{
  "documents": [
    {
      "id": "1",
      "text": "Your extracted document text here"
    }
  ]
}

Option 2: Use Open XML SDK (no Office client required)

For a lighter-weight solution that doesn't require Office to be installed, use the Open XML SDK to parse the underlying XML structure of .docx files. This works great for server-side scenarios:

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;

string documentText = string.Empty;
// Open the document in read-only mode
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(@"C:\your\document\path\file.docx", false))
{
    Body documentBody = wordDoc.MainDocumentPart.Document.Body;
    // Extract all inner text from the document body
    documentText = documentBody.InnerText;
}

Again, wrap the extracted text into the JSON format the API expects and make your request.

Option 3: Power Automate (no-code/low-code)

If you don't want to write code at all, Power Automate has pre-built actions to handle this workflow:

  • Use the "Get text from Word document" action to pull text from your .docx file (supports files stored in OneDrive, SharePoint, etc.)
  • Connect to the "Key Phrase Extraction" connector for Cognitive Services, pass the extracted text, and get your analysis results directly.

Quick note on text limits

Keep in mind that the Key Phrase Extraction API has a maximum text length per document (currently 5,120 characters). If your Word document is longer, you'll need to split the extracted text into smaller chunks, analyze each chunk separately, then combine the results.

内容的提问来源于stack exchange,提问作者Tom Resing

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:29:43