huangning
2026-07-18 c8c5a62d62b9ad05cfa0b5e026496b56a735a18f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$desktop = [Environment]::GetFolderPath("Desktop")
$doc = Get-ChildItem -LiteralPath $desktop -Filter "*.docx" |
  Where-Object { $_.Name -like "*docx" -and $_.Name.Length -gt 10 } |
  Sort-Object LastWriteTime -Descending |
  Select-Object -First 1 -ExpandProperty FullName
if (-not $doc) {
  throw "No docx file found on Desktop."
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zip = [IO.Compression.ZipFile]::OpenRead($doc)
try {
  $entry = $zip.GetEntry("word/document.xml")
  $reader = [IO.StreamReader]::new($entry.Open())
  try {
    $xml = $reader.ReadToEnd()
  } finally {
    $reader.Close()
  }
} finally {
  $zip.Dispose()
}
$xml = $xml -replace '</w:p>', "`n"
$xml = $xml -replace '<[^>]+>', ''
[System.Net.WebUtility]::HtmlDecode($xml)