gpt4 book ai didi

powershell - 从没有项目符号的 MS Word 表格中提取文本 [Powershell 4.0]

转载 作者:行者123 更新时间:2023-12-01 04:53:33 25 4
gpt4 key购买 nike

我想从某个特定表中的 ms word 中提取一些文本:
table and text

但是,当我执行代码时:

$objWord = New-Object -ComObject Word.Application
$objWord.Visible = $true
$filename = 'D:\test.docx'
$objDocument = $objWord.Documents.Open($filename)
$LETable = $objDocument.Tables.Item(1)
$LETableCols = $LETable.Columns.Count
$LETableRows = $LETable.Rows.Count

Write-output "Starting to write... "

$content2 = $LETable.Cell(6,2).Range.Text
$content3 = $LETable.Cell(7,1).Range.Text
$content4 = $LETable.Cell(7,2).Range.Text
#Write-host $content2
$doc2 = $objWord.Documents.Add()
$objWord.Selection.typetext("$content2")
$objWord.Selection.typetext("$content3")
$objWord.Selection.typetext("$content4")
#$objDocument.Close()
#$objWord.Quit()
# Stop Winword Process
#$rc = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($objWord)

bullets - question marks

如何删除那些项目符号-问号?我只想要纯文本。

最佳答案

您将需要为该字符找到 unicode 表达式。一旦找到,则使用正则表达式可以帮助将其替换为空字符、空格或制表符。
我什至尝试“直接”复制和粘贴“✀”,它也能正常工作。

删除字符:
$String -replace '✀'

替换它:

 $String = "Just ✀ and another ✀"
#replace ✀ with cat
$String -replace '✀','cat'

Ant 的结果是:
Just cat and another cat

关于powershell - 从没有项目符号的 MS Word 表格中提取文本 [Powershell 4.0],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38992086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com