none
Word table and hidden information RRS feed

  • Question

  • Greetings,

    I currently deal with an issue regarding a way to hide information into a Word.Table object.

    Basically, I would like to add a table into a word document and find a way to know that I've already insert the table. That's the reason why I'd like to store hidden persistent information as a comparative value.

    Do you think there is a solution to solve my problem (by using fields for instance or anything else) ?

    Thanks in advance.

    Roms.

    --------------------------------------
    Language : c#
    Project      : Word AddIn


    • Edited by Rom.S Monday, August 6, 2012 1:52 PM
    Monday, August 6, 2012 12:02 PM

Answers

  • Hi Rom.S,

    Based on your issue, I would suggest a solution to you by following steps.

    1. Set the Table.ID property to identify a table while you add it into word document, and refer to this

    Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument as Word.Document;
    Word.Table hiddenTable = doc.Tables.Add(doc.Range(ref missing,ref missing), 1, 1, ref missing, ref missing);
    hiddenTable.ID = "HiddenTable";

    2. Iterate tables of the document, and hide the content of the table whose Table.ID equals the "HiddenTable" .

    foreach (Word.Table table in doc.Tables)
    {
         if (table.ID == "HiddenTable")
         {
              //hide the content of table
              table.Range.Font.Hidden = 1;
         }
    }

    Also, you can hide the text of one cell of the added table by using this

    table.Cell(i,j).Range.Font.Hidden = 1
    

    Hope this can help you.

    If anything is unclear, please feel free to let me know.

    Best Regards,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Rom.S Tuesday, August 7, 2012 8:01 AM
    Tuesday, August 7, 2012 5:27 AM
    Moderator

All replies

  • Hi Rom.S,

    Based on your issue, I would suggest a solution to you by following steps.

    1. Set the Table.ID property to identify a table while you add it into word document, and refer to this

    Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument as Word.Document;
    Word.Table hiddenTable = doc.Tables.Add(doc.Range(ref missing,ref missing), 1, 1, ref missing, ref missing);
    hiddenTable.ID = "HiddenTable";

    2. Iterate tables of the document, and hide the content of the table whose Table.ID equals the "HiddenTable" .

    foreach (Word.Table table in doc.Tables)
    {
         if (table.ID == "HiddenTable")
         {
              //hide the content of table
              table.Range.Font.Hidden = 1;
         }
    }

    Also, you can hide the text of one cell of the added table by using this

    table.Cell(i,j).Range.Font.Hidden = 1
    

    Hope this can help you.

    If anything is unclear, please feel free to let me know.

    Best Regards,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Rom.S Tuesday, August 7, 2012 8:01 AM
    Tuesday, August 7, 2012 5:27 AM
    Moderator
  • Hi Leo_Gao

    Thank you for your answer.

    Is the table ID attribute persitent ?
    I have already try to use it for storing information, but when I close and reopen the document, this attribute is consistently empty.

    However, using hidden font to hide text suits me well.

    Thanks a lot.

    Best Regards,

    Rom.S

    Tuesday, August 7, 2012 8:10 AM
  • Hi Rom.S,

    No. The Table.ID property is not persistent. The value of this object will disappear after you close the document. However, you can use the Table.Title property instead of Table.ID as an identifier. It will remain the inherent value while you reopen the document.

    Have a good day.


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 7, 2012 8:34 AM
    Moderator
  • Also, you can hide the text of one cell of the added table by using this

    table.Cell(i,j).Range.Font.Hidden = 1

    Unfortunately, this instruction don't work for me.

    My code is the following:

    [...]
    table.Cell(1, 1).Range.Font.Hidden = 1;
    table.Cell(1, 1).Range.Text = "Blabla";
    [...]

    ... and "Blabla" still visible in the table.

    Any idea please ?

    Thanks.


    • Edited by Rom.S Tuesday, August 7, 2012 9:04 AM
    Tuesday, August 7, 2012 9:04 AM
  • Hi Rom.S,

    When you add the text into a cell, the defalut value of the Font.Hidden property is false. Obviously, "Blabla" is visible in the table. You should change the code to this

    table.Cell(1, 1).Range.Text = "Blabla";
    table.Cell(1, 1).Range.Font.Hidden = 1;
    Regards,

    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 7, 2012 9:16 AM
    Moderator
  • Hi,

    Even though I've inverted the lines in the code, the text was still visible in the cell.
    The reason was simple. I've the box "display hidden text" checked in the Word options :)

    Thanks a lot Leo_Gao.

    Tuesday, August 7, 2012 9:57 AM