Read the word document conent without using Microsoft office

ε祈祈猫儿з 提交于 2019-12-24 17:05:36

问题


I am using word documents for the population of random mails. But to read the content, we are using MS Word. But the scripts are quite slow because of its auto-recovery feature.

My code is in powershell, is there any other alternative to read word docs? I tried to use wordpad but no success.


回答1:


If they are docx files then they are an OpenXML format. Several solutions exists of reading docx files from code without requiring Office. See here and here. They are in C# but translating that to PowerShell should prove little problems. Or have a go with PowerTools for Open XML if you want to use PowerShell commands. Here is some more documentation on that subject.

If you mean you want to view them in their final format like a normal user would do, but without office, you can use this for example.




回答2:


I have found the solution with the help of PowerTools for Open XML (Select-OpenXmlString -path $file_name).content. To use powerTools on many machines will need Visual Studio to be installed on all machines which is not very feasible. It is available at: https://github.com/OfficeDev/Open-Xml-PowerTools

I have followed this screencast: http://www.youtube.com/watch?v=zU0utt3uga4.

And for other machines there is one small catch:

  1. Copy the dlls by maintaining the folder structure
  2. On the machine where you have built it. Copy the GAC C:\Windows\assembly\gac_msil\DocumentFormat.OpenXml and paste it to other machines where you want to use it.

Thanks Lars Truijens!!



来源:https://stackoverflow.com/questions/20835177/read-the-word-document-conent-without-using-microsoft-office

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!