下面是代码:
$objWord = New-Object -Com Word.Application
$filename = 'C:\Chicago_NewUser.doc'
$objDocument = $objWord.Documents.Open($filename)
$LETable = $objDocument.Tables.Item(1)
$LETableCols = $LETable.Columns.Count
$LETableRows = $LETable.Rows.Count
Write-output "Starting to write... "
for($r=0; $r -le $LETableRows; $r++) {
for($c=0; $c -le $LETableCols; $c++) {
Write-host $r "x" $c
$content = $LETable.Cell($r,$c).Range.Text
Write-host $content
}
}
$objDocument.Close()
$objWord.Quit()
该文档是 2003 Word 文档,带有一个表格 - 2 列和 3 行。但是打印的输出以第 3 行和第 1 列中的文本开始。
Word 文档可在此处获得:
https://docs.google.com/document/d/1W0usG4ASsvd3PqQ20l7P8rq0hWBsYlrI0iM1S5ZcumU/edit