1

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.

Amit Shakya
  • 1,396
  • 12
  • 27
  • 2
    If you don't want to use Microsoft Office Word, then change the format of the source document for "population of your random mails." –  Dec 30 '13 at 13:02
  • No, source document format can not be changed as per my requirement. – Amit Shakya Jan 06 '14 at 08:58

2 Answers2

3

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775
Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
1

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!!

mklement0
  • 382,024
  • 64
  • 607
  • 775
Amit Shakya
  • 1,396
  • 12
  • 27