Jump to content

PowerPoint table cells are "empty"


 Share

Recommended Posts

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Does function _PPT_SlideTextFrameGetText do what you need?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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!

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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?

Link to comment
Share on other sites

Could you try:

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Which version of PowerPoint do we talk about?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...