Sign in to follow this  
Followers 0
Lodda

PowerPoint table cells are "empty"

13 posts in this topic

#1 ·  Posted (edited)

Hi,

the task is to extract all text from all shapes from a powerpoint slide.

I create the PowerPoint COM Object, iterate all slides, that works fine.

But regarding tables, all cell objects are empty

There is a Shape property at the Cell object: http://msdn.microsoft.com/en-us/library/office/ff745662(v=office.14).aspx

I did a cross test with VBA and that worked.

; extract text from a table

Func getTextFromTable($table)

Local $text = ""

For $row In $table.Rows

For $cell In $row.Cells

; $cell.Shape is not set

$cell.Shape.Id

Next

Next

return $text

EndFunc

any ideas why $cell.Shape is not set?

autoit gives this error message: "The requested action with this object has failed.:"

Thanks for advice!

lodda

Edited by Lodda

Share this post


Link to post
Share on other sites



Here is the to a PowerPoint UDF. Maybe you can find the function you need.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks, that is what I used to get the application object - however it is just a thin layer.

Share this post


Link to post
Share on other sites

Does function _PPT_SlideTextFrameGetText do what you need?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

no - there is no TextFrame for the table shape.

C:\devenv\src\AutoITPPT\PowerPoint.au3 (445) : ==> The requested action with this object has failed.:

Local $text = $obj.Slides.Item($intSlide).Shapes.Range($intTextFrame).TextFrame.TextRange.Text

Local $text = $obj.Slides.Item($intSlide).Shapes.Range($intTextFrame)^ ERROR

the whole thing: Entry is getTextFromShape($shape)

;http://www.pptfaq.com/FAQ00008_Show_the_-Type_of_each_shape_-including_shapes_in_groups-.htm

const $MSO_AUTOSHAPE = 1

const $MSO_CALLOUT = 2

const $MSO_COMMENT = 4

const $MSO_GROUP = 6

const $MSO_PLACEHOLDER = 14

const $MSO_TEXTBOX = 17

const $MSO_TABLE = 19

Func getTextFromSlide($slide)

Local $shapes = $slide.Shapes

Local $shapeCount = $shapes.Count

Local $text = ""

For $i = 1 To $shapeCount

Local $shape = $shapes.Item($i)

$text &= getTextFromShape($shape) & @LF

Next

return $text

EndFunc

; extract text from a single shape

; recurses into groups

; TODO: check for cycles

Func getTextFromShape($shape)

Local $text = ""

ConsoleWriteError("shape id=" & $shape.Id & @CRLF)

If $shape.Type Then

ConsoleWriteError("shape type=" & $shape.Type & @CRLF)

Else

ConsoleWriteError("shape no type" & @CRLF)

EndIf

If $shape.HasTextFrame Then

$text &= getTextFromTextFrame($shape.TextFrame) & @LF

; TextFrame2 ignored

EndIf

If $shape.Type Then

If $shape.Type == $MSO_GROUP Then

$text &= getTextFromGroup($shape) & @LF

EndIf

EndIf

If $shape.HasTable Then

$text &= getTextFromTable($shape.Table)

EndIf

ConsoleWriteError("shape text=" & $text & @CRLF)

return $text

EndFunc

; extract text from single text frame

Func getTextFromTextFrame($textFrame)

Local $text = ""

If $textFrame.HasText Then

$text = $textFrame.TextRange.Text & @LF

EndIf

return $text

EndFunc

; extract text from a group of shapes

Func getTextFromGroup($group)

Local $text = ""

Local $items = $group.GroupItems

For $i = 1 To $items.Count

Local $shape = $items.Item($i)

$text &= getTextFromShape($shape)

Next

return $text

EndFunc

; extract text from a table

Func getTextFromTable($table)

Local $text = ""

For $row In $table.Rows

For $cell In $row.Cells

ConsoleWriteError("cell " & $cell.shape.Id)

Next

Next

return $text

EndFunc

Share this post


Link to post
Share on other sites

As far as I understand the PowerPoint COM it should be:

$cell.shape.Textframe.Textrange.Text
Unfortunately I can't test at the moment.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Great! This works

$text &= $cell.shape.Textframe.Textrange.Text & @LF

Thank you very much to figure this out.

Where did you look that up and why is it different to

$cell.shape.Type <- does not work

I assume there could be any other shape contained in table cell, but Im maybe wrong.

Thanks again!

Share this post


Link to post
Share on other sites

Glad it works now!

I checked the PowerPoint Object Model Reference. Searched for "table", in the Table Object Members I found the Rows collection, this led me to the Row property and the Cells collection. The example posted there then made the rest quite easy.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Okay, but it looks like there is different behaviour:

works: $cell.shape.Textframe.Textrange.Text

error with unset object if called with a function

doTextExtract($cell.shape)

Func doTextExtract($shape)

$shape.Id

or

$shape.Type

or

$shape.HasText

or

$shape.Textframe

...all props are not accesible

EndFunc

I dont get it why its differnt - I doubt its a bug, so maybe some behaviour with OLE and function arguments?

Share this post


Link to post
Share on other sites

Could you try:

$oShape = $cell.shape
doTextExtract($oShape)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

magic - this is slightly better:

$oShape.HasTextFrame works and

$oShape.Type or $oShape.type results in a "not implemented" error

Can you give me a pointer were I can learn to understand this?

Share this post


Link to post
Share on other sites

Which version of PowerPoint do we talk about?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It is Powerpoint 2010.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0