Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How do I parse all the selected data either it is text or drop down item or check box from a word template document using PowerShell. I have tried using the below code but it just prints the data as it is irrespective of selected data, I mean it prints all the data. Any help would be greatly appreciated. I am looking for a solution either in parsing logic or exporting just the selected data to another file(XML or Excel) from a word template.


PERL
$Log = "C:\Users\Desktop\Test.txt"
$filename = "C:\Users\Desktop\WordDocTest.docx"
$objWord = New-Object -Com Word.Application
$objWord.Visible = $false
$objDocument = $objWord.Documents.Open($filename)

$paras = $objDocument.Paragraphs
foreach ($para in $paras) 
{ 
    Write-Output $para.Range.Text
} 
$objWord.ActiveDocument.Close()
$objWord.Quit()

thanks in advance.
[EDIT - CHill60 .. post OP info from solution]

ok, let me clarify, I have a Word Template document which has multiple tables, and each table has its own data like text, dropdown data, check boxes, radio buttons..etc, Above code prints all the data irrespective of data selected against the text controls. My expectation is to print only selected data for suppose see the below example:

Personal Details: (This is table1 in Template)
Name: XYZ
Gender : Male (- this is drop down)
Residenace : (.)US ()Non-US
Lang Speak: [x]English []Spanish [x]French []German


Personal Details: (This is table2 in Template)
Study: MS (dropdown)
Are you single? : Yes


Please let me know if you need more info.
Posted
Updated 30-Jun-14 13:08pm
v5
Comments
[no name] 30-Jun-14 17:20pm    
This does not make any sense to me. You are opening a document and writing the output. There would be no "selected" text to output. For that to happen you would have to let the user select some text first....
priypavan 3-Jul-14 15:13pm    
Any update on this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900