Giter VIP home page Giter VIP logo

shanehoey / worddoc Goto Github PK

View Code? Open in Web Editor NEW
9.0 6.0 2.0 3.96 MB

Create Documentation directly from PowerShell. Simple Installation from PowerShell Gallery, and as long as you have MS Word Installed you will be creating .docx, .pdf, .html files in minutes!

Home Page: https://shanehoey.github.io/worddoc/

License: MIT License

PowerShell 100.00%
powershell microsoft-word microsoft-office

worddoc's Introduction

worddoc's People

Contributors

shanehoey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

worddoc's Issues

Return Objects switch

Investigate using a returnobject switch on all functions so that advanced formatting is easier after the object created. also will make it easier for people to script more advanced functions.

$myobject = add-wordshape {snip} -returnobject
$myobject.dosomething()
$myobject.setsomething = 1

save-worddoc does not save file, if file does not exist

WARNING: Save-WordDocument - This is not a valid file name.
Try one or more of the following:

  • Check the path to make sure it was typed correctly.* Select a file from the list of files and folders.

Probably fix
(Test-Path ([System.IO.Path]::GetDirectoryName($)) -pathtype container ) -and ([System.IO.Path]::GetExtension($) -eq ".docx")

Close-WordDoc does not always execute cleanly

When experiencing issue regarding Close-WordDocument function prompting to save the file again, even though the file has been saved, when you click cancel to not save again, and just close the open window, it causes the module to incorrectly assume that the $script:WordDocument and $script:WordInstance variables still hold valid values. Recommend either adding a "-Force" switch to Close-WordDocument and Close-WordInstance that causes the variable to be removed without throwing an error or allow New-... to have a "-Force" switch to allow overwriting current instance

try 
{
    $WordDocument.Close()
    if (test-path variable:script:Worddocument) 
    { 
        remove-variable WordDocument -Scope Script 
    }

}
catch 
{
    if ([bool]$force -and (test-path variable:script:Worddocument))
    {
        remove-variable WordDocument -Scope Script
    }
    else
    {
        Write-Warning -Message "$($MyInvocation.InvocationName) - $($_.exception.message)"
    }
}

this way a new instance can be created. A similar "-Force" switch may also be needed in the Close-WordInstance function

Close-WordInstance does not clear associated WordDocument variable

When using Close-WordDocument, the script also closes the word instance, but when using Close-WordInstance, it does not attempt to first close the associated word document. It seems like it should be the other way around.
When closing the Instance, the Document window is also closed, but the script as written is not able to handle this action.
When using "Test-WordInstance" and "Test-WordDocument" it only checks to see if the variable is of a specific type, but not to see if it is an actual valid instance/document. Instead of only checking if variable is [type...] it should then check to ensure there is something there... $script:WordDocument.Name is a read only property and is always populated if there is indeed a valid word document connected to $script:WordDocument.
On a side note, I would recommend having the test- functions only Write-Output $true or Write-Output $false instead of throwing an error for false and return $true for true. Using 'return' causes it to terminate the function with the specified return value, using write-output allows for additional things to happen while still sending the intended value to the calling function. In the functions using the tests, you could use something like:

$ValidWordInstance = test-wordinstance -WordInstance $wordinstance 
if ([bool]$ValidWordInstance)
{
    If([bool]$Wordinstance.name)
    {
        <#action if valid#>
    } 
    Else
    {
        <#action if valid type, but no values#>
    }
}
Else
{
    <#action if invalid type#>
}

Add Article to pages on creating advanced documents

using get-worddocument and get-wordinstance its possible to edit any property word has.

  1. write a page on how to use these by recording a macro on a document then implementing it

for example

$selection = (Get-WordDocument).application.selection
$selection.range.ListFormat.ApplyBulletDefault()
foreach ($o in $objects) {
    $selection.typetext($o)
    $Selection.TypeParagraph()
}
$selection.range.ListFormat.ApplyBulletDefault()

add-wordshape nees relative and absolute parameter

when adding shape via add-wordshape it is relative to the current position on the document, it needs to default to absolute, and make relative options.

investigate this for relative
(Get-WordDocument).Shapes(1).RelativeVerticalPosition = 1
(Get-WordDocument).Shapes(1).RelativeHorizontalPosition = 1

investigate this for absolute
(Get-WordDocument).Shapes(1).LockAnchor = -1

close-worddocument

when close-worddocument is run, if you hit cancel it throws an error.

User should be able to click cancel and file not saved

Cannot save the word document I create programmatically

Hi Shane,
maybe I'm missing something obvious, but I cannot create and save a new word file even using this simple script:

New-WordInstance
New-WordDocument 
Add-WordText -text "Lorem Ipsum" -WDBuiltinStyle wdStyleHeading1
Add-WordText -text "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc volutpat non lorem non viverra." -WDBuiltinStyle wdStyleNormal
Save-WordDocument -Filename "test.docx" -Folder "D:\temp\"

Word opens and the content is added to the new document, but the Save-WordDocument cmdlet fails:

PS> .\test.ps1
WARNING: *** MS Word may be behind this window! ***
WARNING: Save-WordDocument - Exception setting "SaveAs": Cannot convert the "D:\temp\test.docx" value of type "psobject" to type "Object".

I expect to be able to create and save the file directly from the powershell script (I need to create a bunch of about a thousand files for testing purposes).
Can you please clarify what I'm doing wrong?
Thanks a lot,
Massimo
PS
I'm running windows 10 Pro 64 bit, Version 1709.
D:\temp\ is an empty, writeable folder on my PC.

PS> Get-InstalledModule WordDoc
Version    Name                                Repository           Description
-------    ----                                ----------           -----------
1.2.1      WordDoc                             PSGallery            Generate Word Documents directly from PowerShell..

PS> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.16299.251
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.251
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.