can the translator api handle office files?

Claudia Griva 1 Reputation point
2020-08-25T20:09:06.98+00:00

I want to use the api to move files (.docx etc) through the translator api. Is this possible?

Azure Translator
Azure Translator
An Azure service to easily conduct machine translation with a simple REST API call.
222 questions
No comments
{count} votes

2 answers

Sort by: Most helpful
  1. YutongTie-MSFT 24,636 Reputation points Microsoft Employee
    2020-08-26T00:53:37.57+00:00

    Hi,

    Thanks for reaching out to us. The API itself can not take .docx file directly, if you want to do that, you can write a function to read the .docx file first. The code following for your reference.

    Application word = new Application();
    Document doc = new Document();
    
    object fileName = path;
    // Define an object to pass to the API for missing parameters
    object missing = System.Type.Missing;
    doc = word.Documents.Open(ref fileName,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing);
    
    String read = string.Empty;
    List<string> data = new List<string>();
    for (int i = 0; i < doc.Paragraphs.Count; i++)
    {
        string temp = doc.Paragraphs[i + 1].Range.Text.Trim();
        if (temp != string.Empty)
            data.Add(temp);
    }
    ((_Document)doc).Close();
    ((_Application)word).Quit();
    
    GridView1.DataSource = data;
    GridView1.DataBind();
    

    Please let me know if you have more questions. Thanks!

    Regards,
    Yutong

    No comments

  2. Claudia Griva 1 Reputation point
    2020-08-26T20:05:43.17+00:00

    Thank you Yutong - I will test this out.