# PSWriteWord – Updated to 0.4.1 (Breaking Change included)

Review the PSWriteWord 0.4.1 release, including the breaking change, document-generation fixes, and practical improvements that make Word automation scripts more reliable.

blog

28 Jun 2018 pl

![PSWriteWord – Updated to 0.4.1 (Breaking Change included)](/wp-content/uploads/2018/06/img_5b352fffde307.png)

[Zobacz obrazy (2)](#pf-content-image-1-0)

While the update may seem small – change from **0.4** to **0.4.1** it actually brought a number of fixes and new features. One of the early adopters found some issues with how **Add-WordTable** worked so I've spent a lot of time fixing different cases on how people may use it. During that time I've created a bunch of different examples covering possible use cases. While with **PSWriteWord** you can build your table by hand… it has quite nice functionality that I think is very useful in your day to day scenario. To add few more features I had to change old **-Table** to **-DataTable** and use **-Table** parameter for something else. So if you've managed to use the old version… you may need to change just one bit.

> Please notice this article **contains parts of information **(still useful) and **may not reflect all functionalities of this module**. For download, source code and so on you should refer to the dedicated **[PSWriteWord](https://evotec.xyz/hub/scripts/pswriteword-powershell-module/)** module page. After reading this one… of course! It contains useful *information*, *examples *and *know-how*.

Let's take a look at few examples… shall we?

### 💡 How can I use it?

Below example is simple use case. Trying to build an invoice table with 2 columns **Description** and **Amount**. Normally you would have to go thru adding **rows** and **columns **looping thru, adding alignments, design and so on. While you can still do that… you don't have to.

```powershell
Import-Module PSWriteWord #-Force

$FilePath = "$Env:USERPROFILE\Desktop\PSWriteWord-Example-Tables3.docx"

#Clear-Host
$WordDocument = New-WordDocument $FilePath

$InvoiceEntry1 = @{}
$InvoiceEntry1.Description = 'IT Services 1'
$InvoiceEntry1.Amount = '$200'

$InvoiceEntry2 = @{}
$InvoiceEntry2.Description = 'IT Services 2'
$InvoiceEntry2.Amount = '$300'

$InvoiceEntry3 = @{}
$InvoiceEntry3.Description = 'IT Services 3'
$InvoiceEntry3.Amount = '$288'

$InvoiceEntry4 = @{}
$InvoiceEntry4.Description = 'IT Services 4'
$InvoiceEntry4.Amount = '$301'

$InvoiceEntry5 = @{}
$InvoiceEntry5.Description = 'IT Services 5'
$InvoiceEntry5.Amount = '$299'

$InvoiceData = @()
$InvoiceData += $InvoiceEntry1
$InvoiceData += $InvoiceEntry2
$InvoiceData += $InvoiceEntry3
$InvoiceData += $InvoiceEntry4
$InvoiceData += $InvoiceEntry5

Add-WordText -WordDocument $WordDocument -Text "Invoice Data" -FontSize 15 -Alignment center
Add-WordParagraph -WordDocument $WordDocument
Add-WordTable -WordDocument $WordDocument -DataTable $InvoiceData -Design LightShading

Save-WordDocument $WordDocument

### Start Word with file
Invoke-Item $FilePath
```

[!\[Visual Studio Code showing a PSWriteWord example script that builds invoice data and adds it as a formatted Word table.\](/wp-content/uploads/2018/06/PSWriteWord-Tables-Example3.gif)](/wp-content/uploads/2018/06/PSWriteWord-Tables-Example3.gif)

### 💡 Got anything more?

Another example shows couple of different **Add-WordTable** examples. It covers 3 cases. **Hash**,** Ordered Hash** and Array of **Sytem.Objects**. All 3 are supported by **Add-WordTable**. Notice how you need to have **[ordered]** for hash to get proper order of values. Also notice how **column names** are given by parameter (or by default **Name/Value**).

```powershell
### prepare data
$hash = [ordered] @{}
$hash.add("HQ-1", "5.54.546")
$hash.add("EUR-1", "6.0.0.1")
$hash.add("HQ-2", "5.6")
$hash.add("EUR-2", "6.1.5")
$hash.add("EUR-3", "6.2")

$hash1 = @{}
$hash1.add("HQ-1", "5.54.546")
$hash1.add("EUR-1", "6.0.0.1")
$hash1.add("HQ-2", "5.6")
$hash1.add("EUR-2", "6.1.5")
$hash1.add("EUR-3", "6.2")

$hash2 = @{}
$hash2.add("HQ-1", "5.54.546")

$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name Name -Value "Ryan_PC"
$obj | Add-Member -type NoteProperty -name Manufacturer -Value "Dell"
$obj | Add-Member -type NoteProperty -name ProcessorSpeed -Value "3 Ghz"
$obj | Add-Member -type NoteProperty -name Memory -Value "6 GB"

$myObject2 = New-Object System.Object
$myObject2 | Add-Member -type NoteProperty -name Name -Value "Doug_PC"
$myObject2 | Add-Member -type NoteProperty -name Manufacturer -Value "HP"
$myObject2 | Add-Member -type NoteProperty -name ProcessorSpeed -Value "2.6 Ghz"
$myObject2 | Add-Member -type NoteProperty -name Memory -Value "4 GB"

$myObject3 = New-Object System.Object
$myObject3 | Add-Member -type NoteProperty -name Name -Value "Julie_PC"
$myObject3 | Add-Member -type NoteProperty -name Manufacturer -Value "Compaq"
$myObject3 | Add-Member -type NoteProperty -name ProcessorSpeed -Value "2.0 Ghz"
$myObject3 | Add-Member -type NoteProperty -name Memory -Value "2.5 GB"

$myArray = @($obj, $myobject2, $myObject3)
### prepare data end

Import-Module PSWriteWord #-Force
$FilePath = "$Env:USERPROFILE\Desktop\PSWriteWord-Example-Tables6.docx"

$WordDocument = New-WordDocument $FilePath
Add-WordTable -WordDocument $WordDocument -DataTable $hash -Design ColorfulList #-Verbose
Add-WordParagraph -WordDocument $WordDocument

Add-WordTable -WordDocument $WordDocument -DataTable $hash -Design ColorfulGrid -Columns 'My Name', 'My Value'
Add-WordParagraph -WordDocument $WordDocument

Add-WordTable -WordDocument $WordDocument -DataTable $hash1 -Design ColorfulGrid -Columns 'My Name', 'My Value' -AutoFit Window
Add-WordParagraph -WordDocument $WordDocument

Add-WordTable -WordDocument $WordDocument -DataTable $hash2 -Design ColorfulGrid -Columns 'My Name', 'My Value'
Add-WordParagraph -WordDocument $WordDocument

Add-WordTable -WordDocument $WordDocument -DataTable $myArray -Design ColorfulList #-Verbose

Save-WordDocument $WordDocument -Language 'en-US'
Invoke-Item $FilePath
```

[!\[PSWriteWord-Tables-Example6\](/wp-content/uploads/2018/06/PSWriteWord-Tables-Example6.gif)](/wp-content/uploads/2018/06/PSWriteWord-Tables-Example6.gif)

> Please notice this article **contains parts of information **(still useful) and **may not reflect all functionalities of this module**. For download, source code and so on you should refer to the dedicated **[PSWriteWord](https://evotec.xyz/hub/scripts/pswriteword-powershell-module/)** module page. After reading this one… of course! It contains useful *information*, *examples *and *know-how*.

There are far more **changes** that has been added with this release but since it's a fast update… well you will have to find them out by yourself for now!

## Powiązane projekty

Projekty powiązane z tagami, kategoriami i treścią tego wpisu.

[Wszystkie projekty](/projekty/)

Trwa dopasowywanie projektów...

[Powrót do bloga](/blog/)

## Powiązane wpisy

- [Check an API write after a PowerShell timeout](/blog/verify-uncertain-api-outcomes-powershell/)
- [Inspect and convert mixed Office archives with PSWriteOffice](/blog/inspect-and-convert-mixed-office-archives-pswriteoffice/)
- [Compose PDF reports and automate page workflows with PSWriteOffice](/blog/automate-pdf-reports-and-page-workflows-pswriteoffice/)

<!-- PowerForge markdown artifact sha256:A76339AF2D7B73E6584E253C083D0DA450CEEAF3F00BC8060695D85CB75F68F0 -->
