none
how to get alt text of a table in word document RRS feed

  • Question

  • HI,

            How can i get alternate text (Alt text) of a table in word document. i tried it accessing by

                   1.  string app = currenttable.Range.InlineShapes[1].AlternativeText; and

                    2.   string temp = currenttable.Range.ShapeRange.AlternativeText;

    but it did not work.

    In interactive mode, you can find it by right click on any table in word document and select table properties.

    thanks

    shashank


    • Edited by shashank Saturday, June 16, 2012 8:45 PM
    • Changed type 许阳(无锡)Moderator Monday, June 18, 2012 4:45 AM This is a question with obviously goal
    Saturday, June 16, 2012 8:40 PM

Answers

  • Hi shashank,

    According to your description and screen shooting, I think your want to get table's title property and Descr property. The following snippet is come from a document-level application, the prompt will alert the properties which your want.

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml.Linq;
    using Microsoft.Office.Tools.Word;
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    using Office = Microsoft.Office.Core;
    using Word = Microsoft.Office.Interop.Word;
    using MyLog4Net;
    
    namespace WordDocument17
    {
        public partial class ThisDocument
        {
            ////private MyLogger mlog = new MyLogger(typeof(ThisDocument), "Debug.log");
    
            private void ThisDocument_Startup(object sender, System.EventArgs e)
            {
                try
                {
                    Word.Application wdApp = Application;
                    Word.Document wdDoc = wdApp.ActiveDocument;
                    Word.Table wdTable = wdDoc.Tables[1];
                    MessageBox.Show(wdTable.Title + "\n" + wdTable.Descr);
                }
                catch (Exception ex)
                {
                    //mlog.ERROR(ex.Message + "\n" + ex.StackTrace);
                }
            }
    
            private void ThisDocument_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO Designer generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisDocument_Startup);
                this.Shutdown += new System.EventHandler(ThisDocument_Shutdown);
            }
    
            #endregion
        }
    }

    Have a good day,

    Tom

     

    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by shashank Wednesday, June 20, 2012 8:03 AM
    Wednesday, June 20, 2012 6:51 AM
    Moderator

All replies

  • Hi shashank,

    Thanks for posting in the MSDN Forum.

    It's based on my experience that you will get exception in your snippet due to no Inlineshape you have declear in the table's range. And AlternativeText will not be visiable until the document has been saved as html file and images can't be load for some reason.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 4:44 AM
    Moderator
  • Hi Tom,

               thanks for the prompt reply. But when i insert any picture at some table's cell and access its alternate text using

    string text= currenttable.Cell(1, 3).Range.InlineShapes[1].AlternativeText;

    then it is easily done and return appropriate value. it does not require document to be saved as html file.

    than why in case of getting table's Alternate Text , it should be saved as html file? 

    thanks


    shashank

    Monday, June 18, 2012 11:33 AM
  • Hi shashank,

    I think you missed my idea, I just say when the alternative text will visible. And it's based on my experience that alternative text only valid in image. And in you snippet I can't see any InlineShapes have been defined. It will throw exception.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 19, 2012 5:04 AM
    Moderator
  • 

    Hi Tom,

                thanks. my code snippet is raising exceptions. Someone told me that whatever you do in interactive mode of word , you can do it via program too by using VSTO. so in that regard , i want to confirm that is it possible to access Alt text of a table by VSTO c# code ?

    please refer for details. 



    shashank

    Tuesday, June 19, 2012 7:06 AM
  • Hi shashank,

    According to your description and screen shooting, I think your want to get table's title property and Descr property. The following snippet is come from a document-level application, the prompt will alert the properties which your want.

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml.Linq;
    using Microsoft.Office.Tools.Word;
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    using Office = Microsoft.Office.Core;
    using Word = Microsoft.Office.Interop.Word;
    using MyLog4Net;
    
    namespace WordDocument17
    {
        public partial class ThisDocument
        {
            ////private MyLogger mlog = new MyLogger(typeof(ThisDocument), "Debug.log");
    
            private void ThisDocument_Startup(object sender, System.EventArgs e)
            {
                try
                {
                    Word.Application wdApp = Application;
                    Word.Document wdDoc = wdApp.ActiveDocument;
                    Word.Table wdTable = wdDoc.Tables[1];
                    MessageBox.Show(wdTable.Title + "\n" + wdTable.Descr);
                }
                catch (Exception ex)
                {
                    //mlog.ERROR(ex.Message + "\n" + ex.StackTrace);
                }
            }
    
            private void ThisDocument_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO Designer generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisDocument_Startup);
                this.Shutdown += new System.EventHandler(ThisDocument_Shutdown);
            }
    
            #endregion
        }
    }

    Have a good day,

    Tom

     

    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by shashank Wednesday, June 20, 2012 8:03 AM
    Wednesday, June 20, 2012 6:51 AM
    Moderator
  • Thanks Tom,

                           This is exactly what i wanted. one more question-> is it possible in application level addin too?

    thanks a lot for taking pain


    shashank

    Wednesday, June 20, 2012 8:05 AM