PPT: TextRange -> Cell

D

David Thielen

Hi;

I think there must be a way to do this, but I can't find anything.

If I have a TextRange, and this TextRange is in a table (and is NOT
the selected text) - how can I find what cell it is in the table? I
can use Parent to get the table - but then walking the rows/columns in
the table I see no way to get the cell it comes from.

How can I do this?

thanks - dave


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
C

Cindy M.

Hi David,
If I have a TextRange, and this TextRange is in a table (and is NOT
the selected text) - how can I find what cell it is in the table? I
can use Parent to get the table - but then walking the rows/columns in
the table I see no way to get the cell it comes from.
Again, it would probably be better to ask this in a PowerPoint
newsgroup, as the folks there will know best how to work with their
object model.

However, the only possibility I can see is to "walk" each cell, SELECT
it, the compare the two TextRange objects (or their Text properties).

FWIW, a PPT colleague of mine once told me that he always used Word or
Excel tables in his PowerPoint solutions because PowerPoint's were so
poor. These discussions were pre-2007 and he's unfortunately no longer
with us, so I can't ask him for you...<sad>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
J

\Ji Zhou [MSFT]\

Hello Dave,

I have a quick test in my side, but the result is that I did not get the
table from the textRange.Parent. I stored the textRange by accessing the
Table.Cell(i,j).Shape.TextFrame.TextRange. So would you mind letting me
know how you get the textRange.

In my side, I can get the a textFrame from the textRange.Parent, and then
get a shape from the textFrame.Parent. Iterating through all of the cells
in the table, I can find one cell whose Shape property matchs the
textRange.Parent.Parent. The codes in my side looks like,

PowerPoint.TextRange textRange;

private void button2_Click(object sender, RibbonControlEventArgs e)
{
Random r = new Random();
//get a random textRange of a cell in the table and store it
textRange =
Globals.ThisAddIn.Application.ActivePresentation.Slides[1].Shapes[1].Table.C
ell(r.Next(1,5),r.Next(1,5)).Shape.TextFrame.TextRange;
}

private void button1_Click(object sender, RibbonControlEventArgs e)
{
//From the stored textRange, get the row and column index of
the cell
PowerPoint.TextFrame tFrame = textRange.Parent as
PowerPoint.TextFrame;
PowerPoint.Shape shape = tFrame.Parent as PowerPoint.Shape;

PowerPoint.Table table =
Globals.ThisAddIn.Application.ActivePresentation.Slides[1].Shapes[1].Table
as PowerPoint.Table;
for (int i = 1; i <= table.Rows.Count; i++)
{
for (int j = 1; j <= table.Columns.Count; j++ )
{
if (table.Cell(i, j).Shape == shape)
{
MessageBox.Show(i.ToString() + " " + j.ToString());
}
}
}
}

Please let me know if this addresses your issue. If you have any questions
or concerns on this, please let me know.

Have a nice day Dave!


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
[email protected].

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Top