Ticket T1285478
Visible to All Users

Get title or tag from MS dotx file from a property assigned using MS Word

created 11 days ago

Hello,

We are using Version 24.1.4.
We are opening a MS dotx file and accessing tables in the dotx file using your rich edit library. The syntax looks like

RichEditDocumentServer server = new RichEditDocumentServer();
bool status = server.LoadDocument(fopenpath);
var doc = server.Document;
DevExpress.XtraRichEdit.API.Native.TableCollection tbls = doc.Tables;
foreach (DevExpress.XtraRichEdit.API.Native.Table t in tbls)
{
var title = t.Title;

}

That last line is giving an error. It says there is no definition for 'Title'. I tried Description and got the same error. Please see the first screen capture.

Clipboard-File-1.png

Your documentation talks about Title and Description fields, but they give the above error. It talks about them version 24.2. We are on version 24.1.4 don't want to upgrade now. That would be a significant impact. If the Title and Description were just added in 24.2 and are not present in 24.1.4, we could consider upgrading, But, if they were already in 24.1.4, we don't want to upgrade.

We have many tables in our dotx file. We would like to name them or tag them in MS Word. Then read that name in our C# code with DevExpress statements like above. That will tell us which table we have.

One way to name them in MS Word would be the Alt Text field for the table, like shown below in screen capture 2.

Clipboard-File-2.png

We would like to read that text value in the C# code. If there is another way to name them in MS Word that is available in C# using the DevExpress library, we can do that also.

Thank you.

David

Answers approved by DevExpress Support

created 11 days ago

Hello David,

We added Table Title and Description properties in v24.2 (See What's New in v24.2 → Alt Text for Tables). We encourage you to upgrade to the latest available version as it includes performance enhancements, bug fixes, and new features. To get started, refer to the following help topic: Upgrade Your Application to a New DevExpress Version

If upgrading is not an option, you can use bookmarks to tag tables as a workaround. The idea is to use bookmark names to identify tables and create a mapping. For example:

We first mark each table with its own corresponding bookmark, with names like Table1, Table2, and Table3.

Clipboard-File-2.png

Then, we iterate through the document's bookmarks and tables, checking if their DocumentRange values overlap with one another. If they do, we create a mapping between the table tag (bookmark name) and its corresponding table.

C#
Dictionary<string, Table> tableMap = new Dictionary<string, Table>(); List<Table> tables = document.Tables.ToList(); List<Table> tablesToRemove = new List<Table>(); foreach (Bookmark b in document.Bookmarks) { string name = b.Name; // Bookmark Name DocumentRange range = b.Range; // Bookmark Range (Table Range) // Map Bookmark Name to Table if their DocumentRange Overlap foreach (Table t in tables) { if (range.Start.ToInt() < t.Range.End.ToInt() && t.Range.Start.ToInt() < range.End.ToInt()) { tableMap.Add(name, t); tablesToRemove.Add(t); break; } } // Remove Mapped Tables foreach (var tableToRemove in tablesToRemove) tables.Remove(tableToRemove); tablesToRemove.Clear(); } tableMap["Table1"].Cell(0, 1).BackgroundColor = Color.Green; tableMap["Table2"].Cell(0, 1).BackgroundColor = Color.Red;

Clipboard-File-1.png

Please let me know if this helps.

I attached a sample project for you reference.

Regards,
Steven

    Comments (2)

      Hello Steven,

      That solved the problem.
      Thanks a lot!

      David

        Hello Steven,
        This work great.
        Thank you.
        David

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.