powershell - 将字头表导出到excel powershell
问题描述
请你能帮我从一个单词中获取标题表并导出到excel文档吗?
目标点是让每个字段都有他的值来知道所有的字段和他的值。
这是标题的示例:
这是目标:
这是使用的代码,但返回给我一个文本,而不是一个表格:
$docPath = "C:\Users\Dummy\Desktop\"
$outputfile = "C:\Users\Dummy\Desktop\header_out.csv"
if(Test-Path -path $outputfile) { Remove-Item -path $outputfile }
$all_docs = Get-ChildItem $docPath -filter "n.docx"
$word = New-Object -comobject "Word.Application"
$word.Visible = $False
$all_items = @()
foreach ( $document in $all_docs)
{
$item = New-Object System.Object
$doc = $word.Documents.Open($document.FullName);
$header = $doc.Sections.Item(1).Headers.Item(1).Range.Text
$item | Add-Member -type NoteProperty -name Name -value $document.FullName
$item | Add-Member -type NoteProperty -name Header -value $doc.Sections.Item(1).Headers.Item(1).Range.Text
$all_items += $item
$doc.Close()
}
$word.Quit()
Remove-Variable doc
Remove-Variable word
$all_items | Export-CSV $outputfile
这是结果:
感谢您的帮助和BR!
解决方案
推荐阅读
- github-actions - Github 节点操作 http 错误总是导致作业失败
- python - 如何使用 python 访问和保存 Outlook 邮件正文中的链接
- java - 如何查看使用 Runtime.getRuntime().exec 执行的 curl 命令的历史记录?
- python - 具有 OR 条件的 Pandas Grouby
- docker - Dockerfile 权限未生效
- asp.net-core - 如何在不停止 .NET5 中的 IIS 应用程序和池的情况下更新 ASP.NET Core 文件?
- sql-server - 开放查询中的开放查询
- prolog - 我是 Prolog 的新手,我不知道我哪里出错了
- apache-kafka - Kafka 消费者作为一种服务,它不断地从 Kafka 主题中轮询消息
- api - .NET Core 问题:托管在 IIS 中时的 System.OperationCanceledException