PSWriteOffice icon indicating copy to clipboard operation
PSWriteOffice copied to clipboard

Header / Footer Support

Open Apoc70 opened this issue 1 year ago • 7 comments

Does the current release support adding headers and footers to a Word document?

Apoc70 avatar Mar 24 '23 11:03 Apoc70

$Document.AddHeadersFooters() is what you look for, but as I see it's not available in current PSWriteOffice which is weird.

I really need to make libraries consistent with current versions of OfficeIMO

PrzemyslawKlys avatar Mar 24 '23 11:03 PrzemyslawKlys

Bumping this one up, It looks like there's still no header/footer support, but appears to be in OfficeIMOI. If I were smarter in C#, I'd try to slam in a PR. It also appears that the Lib folder containing the dll's with the release isn't included. Thanks for everything!

jpedlowCDW avatar Nov 24 '23 22:11 jpedlowCDW

I'm pretty sure the current version on PowerShellGallery has support for AddHeadersFooters. Have you tested it?

As for missing Lib, it's because I decided you need to build it yourself using Build script if you want to play with adding new features. We're not supposed to upload binary files to GIT.

PrzemyslawKlys avatar Nov 25 '23 08:11 PrzemyslawKlys

@PrzemyslawKlys I could be doing something wrong, but I cannot find any evidence there's support in the module other than REMOVING headers currently. I suspect it's a bit behind IMO.

From what I can see between the docs, and checking PS: image It's also appears to not be an exported function in the PSD1 for the module. Happy to accept that I could be wrong, but I can't find any evidence of it.

I'd submit a PR to fix it if I had the C# knowledge, but I'm not quite there yet, unfortunately. Really have high hopes for this module :)

jpedlowCDW avatar Nov 27 '23 22:11 jpedlowCDW

It's maybe not straightforward but everything doable in C#, all the methods are available.

$Document = New-OfficeWord -FilePath $PSScriptRoot\Documents\BasicDocument.docx

$Document.Settings.FontFamily = 'Times New Roman'

$Document.AddHeadersAndFooters()

$MyParagraph = $Document.Header.Default.AddParagraph("This is a header")

New-OfficeWordText -Document $Document -Text 'This is a test, very big test ', 'and this should be bold' -Bold $null, $true -Underline Dash, $null

New-OfficeWordText -Document $Document -Text 'This is a test, very big test', 'ooops' -Color Blue, Gold -Alignment Right

$Paragraph = New-OfficeWordText -Document $Document -Text 'Centered' -Color Blue, Gold -Alignment Center -ReturnObject

New-OfficeWordText -Document $Document -Text ' Attached to existing paragraph', ' continue' -Paragraph $Paragraph -Color Blue

Save-OfficeWord -Document $Document -Show

image

Wrapping it up into easier PowerShell commands takes effort and time and currently I lack time.

Same goes for properties of given Paragraph for example:

image

image

image

$Document | Get-Member

image

image

I will release new version soon, but mostly just with new DLL, not with fully functional PowerShell cmdlets

PrzemyslawKlys avatar Nov 27 '23 22:11 PrzemyslawKlys

THANK YOU @PrzemyslawKlys . :) That solves the case right there.

I'm looking for standalone cmdlets while they're sitting as methods. Thank you for taking the time to explain/demonstrate to a mere mortal like me. I'm off to do some tinkering. :)

I'll try to devote some effort to docs/examples, if that's alright with you? :)

jpedlowCDW avatar Nov 27 '23 22:11 jpedlowCDW

Sure, why not. Just a warning - people who say that - usually end up realizing it's harder than it seems and never come back 😂🤣 You can always write wrapper around those commands and do PRs for that. I guess effectively we should have similar options as PSWriteWord project.

PrzemyslawKlys avatar Nov 28 '23 18:11 PrzemyslawKlys