Lodda Posted April 23, 2013 Posted April 23, 2013 (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 emptyThere is a Shape property at the Cell object: http://msdn.microsoft.com/en-us/library/office/ff745662(v=office.14).aspxI did a cross test with VBA and that worked.; extract text from a tableFunc 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 $textEndFuncany 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 April 23, 2013 by Lodda
water Posted April 23, 2013 Posted April 23, 2013 Here is the to a PowerPoint UDF. Maybe you can find the function you need. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Lodda Posted April 23, 2013 Author Posted April 23, 2013 Thanks, that is what I used to get the application object - however it is just a thin layer.
water Posted April 23, 2013 Posted April 23, 2013 Does function _PPT_SlideTextFrameGetText do what you need? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Lodda Posted April 23, 2013 Author Posted April 23, 2013 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.TextLocal $text = $obj.Slides.Item($intSlide).Shapes.Range($intTextFrame)^ ERRORthe whole thing: Entry is getTextFromShape($shape);http://www.pptfaq.com/FAQ00008_Show_the_-Type_of_each_shape_-including_shapes_in_groups-.htmconst $MSO_AUTOSHAPE = 1const $MSO_CALLOUT = 2const $MSO_COMMENT = 4const $MSO_GROUP = 6const $MSO_PLACEHOLDER = 14const $MSO_TEXTBOX = 17const $MSO_TABLE = 19Func getTextFromSlide($slide)Local $shapes = $slide.ShapesLocal $shapeCount = $shapes.CountLocal $text = ""For $i = 1 To $shapeCountLocal $shape = $shapes.Item($i)$text &= getTextFromShape($shape) & @LFNextreturn $textEndFunc; extract text from a single shape; recurses into groups; TODO: check for cyclesFunc getTextFromShape($shape)Local $text = ""ConsoleWriteError("shape id=" & $shape.Id & @CRLF)If $shape.Type ThenConsoleWriteError("shape type=" & $shape.Type & @CRLF)ElseConsoleWriteError("shape no type" & @CRLF)EndIfIf $shape.HasTextFrame Then$text &= getTextFromTextFrame($shape.TextFrame) & @LF; TextFrame2 ignoredEndIfIf $shape.Type ThenIf $shape.Type == $MSO_GROUP Then$text &= getTextFromGroup($shape) & @LFEndIfEndIfIf $shape.HasTable Then$text &= getTextFromTable($shape.Table)EndIfConsoleWriteError("shape text=" & $text & @CRLF)return $textEndFunc; extract text from single text frameFunc getTextFromTextFrame($textFrame)Local $text = ""If $textFrame.HasText Then$text = $textFrame.TextRange.Text & @LFEndIfreturn $textEndFunc; extract text from a group of shapesFunc getTextFromGroup($group)Local $text = ""Local $items = $group.GroupItemsFor $i = 1 To $items.CountLocal $shape = $items.Item($i) $text &= getTextFromShape($shape)Nextreturn $textEndFunc; extract text from a tableFunc getTextFromTable($table)Local $text = ""For $row In $table.RowsFor $cell In $row.CellsConsoleWriteError("cell " & $cell.shape.Id)NextNextreturn $textEndFunc
water Posted April 23, 2013 Posted April 23, 2013 As far as I understand the PowerPoint COM it should be: $cell.shape.Textframe.Textrange.TextUnfortunately I can't test at the moment. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Lodda Posted April 23, 2013 Author Posted April 23, 2013 Great! This works$text &= $cell.shape.Textframe.Textrange.Text & @LFThank you very much to figure this out.Where did you look that up and why is it different to$cell.shape.Type <- does not workI assume there could be any other shape contained in table cell, but Im maybe wrong.Thanks again!
water Posted April 23, 2013 Posted April 23, 2013 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 2024-07-28 - Version 1.6.3.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 (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
Lodda Posted April 23, 2013 Author Posted April 23, 2013 Okay, but it looks like there is different behaviour:works: $cell.shape.Textframe.Textrange.Texterror with unset object if called with a functiondoTextExtract($cell.shape)Func doTextExtract($shape) $shape.Idor $shape.Typeor $shape.HasTextor $shape.Textframe...all props are not accesibleEndFuncI dont get it why its differnt - I doubt its a bug, so maybe some behaviour with OLE and function arguments?
water Posted April 23, 2013 Posted April 23, 2013 Could you try:$oShape = $cell.shape doTextExtract($oShape) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Lodda Posted April 24, 2013 Author Posted April 24, 2013 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?
water Posted April 24, 2013 Posted April 24, 2013 Which version of PowerPoint do we talk about? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now