如何解析Word模板中的所有选定数据 [英] How to parse all the selected data from a Word Template

查看:104
本文介绍了如何解析Word模板中的所有选定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何使用PowerShell解析所有选定数据,无论是文本还是下拉项目,还是从单词模板文档中复选框。我尝试使用下面的代码,但它只是打印数据,因为它与所选数据无关,我的意思是它打印所有数据。任何帮助将不胜感激。我正在寻找解析逻辑或从单词模板中将所选数据导出到另一个文件(XML或Excel)的解决方案。





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.


$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()



提前谢谢。





好​​的,让我澄清一下,我有一个具有多个表的Word模板文档,每个表都有自己的数据,如文本,下拉数据,复选框,单选按钮等。上面的代码打印所有数据,而不考虑文本控件选择的数据。我的期望是只打印选定的数据,请看下面的例子:



个人详细信息:(这是模板中的table1)

名称:XYZ

性别:男性( - 这是下拉列表)

Residenace :(。)US()非美国

Lang Speak: [x]英语[]西班牙语[x]法语[]德语





个人详细信息:(这是模板中的table2)

学习:MS(下拉菜单)

你单身吗? :是





如果您需要更多信息,请告诉我。


thanks in advance.


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.

推荐答案

Log = C:\ Users \Desktop\Test.txt
Log = "C:\Users\Desktop\Test.txt"


filename = C:\ Users\Desktop\WordDocTest.docx
filename = "C:\Users\Desktop\WordDocTest.docx"


objWord = New-Object -Com Word.Application
objWord = New-Object -Com Word.Application


这篇关于如何解析Word模板中的所有选定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆