-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Underline spaces/tabs #12
Comments
I believe Tabs are TabStops and require different approach.
The way I think it would work one would have to change tab stops per paragraph and change TabStopLeaderCharValue to match underline - i think. Alternatively you could just add empty spaces and those will be treated as normal text. If you can please attach example DOCX with the expectation (minimal example) and I'll check how the XML looks like and whether this is really the case. |
Ok, it's not a TabStop. So it seems TabStops just control behavior of a TabStop, but when you use "\t" it's actually creating a separate run with TabChar. So I need to add support for it in OfficeIMO. Seeing how it's built You can try doing: $document.Paragraphs[1].UnderLine = ... While when you use I only wonder if OfficeIMO will see this..., it should be it will not be aware that it's |
Hmm, it means that I can underline only the whole paragraph, not a part of a string? Maybe, I can use something like non-breaking space? But how to type it in Powershell? |
I found the workaround! It works when I use $p2.Underline = 'Single' Initially, the value of |
It's not like that. OpenXML has Paragraph that can contain multiple Runs. However, in OfficeIMO I've simplified this idea and basically every Run is WordParagraph (different class). That means from a XML level you still have 1 Paragraph that contains 7 Runs, but from OfficeIMO/PSWriteOffice you are dealing with 7 WordParagraphs (not carrying or knowing about Paragraph/Runs). So what you just did with New-OfficeWordText is created 7 WordParagraphs, but we only return the "last" one to you when you use ReturnObject. This is because, the use case is - you can use it to attach other things to it if needed. But if you want to see what is already there you can just go back and see $Document.Paragraphs[0] to $Document.Paragraphs[7] and modify every single one of them. And again $Document.Paragraphs is actually WordParagraph and not Paragraph. |
Right before # Set to underline spaces
$doc.Paragraphs |? underline |% {$_.underline = 'Single'} |
I would not go and set it on all tho unless you want to underline everything. |
Why everything? It simply set the underline mode I need only in the paragraphs have underline set. Perhaps I can't figure out the whole thing. |
Maybe I don't understand what you're doing. Anyways - you do you ;) If it works, it works. |
So after some initial testing, it seems that the behavior is not as you described it. $Document = New-OfficeWord -FilePath $PSScriptRoot\Documents\BasicDocument.docx
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, \t\t very big test ', 'and this should be bold' -Bold $null, $true -Underline Dash, $null
New-OfficeWordText -Document $Document -Text "This is a test, `t`t very big test ", 'and this should be bold' -Bold $null, $true -Underline Dash, $null
$p2 = New-OfficeWordText -Document $Document -Bold 1, 0 -Underline 0, 1 -Text "We are ", "`t`tJohn Doe and Jane Doe`t`t" -ReturnObject
$p3 = New-OfficeWordText -Document $Document -Bold 1, 0 -Underline $null, Dash -Text "We are ", "`t`tJohn Doe and Jane Doe`t`t" -ReturnObject
Save-OfficeWord -Document $Document -Show I have not noticed that you used 0 and 1 instead one of many other possible values. And it seems that if you use proper values, it will act as required. I've also noticed in the document it doesn't have TabChar, but "\t" which is consistent with what you did. So the example you sent me looks like created with Word, where it actually adds TabChar as opposed to \t. |
Of course it was created with Word, because I hadn't been able to do it without Word and I needed to illustrate what I wanted. $Document = New-OfficeWord -FilePath c:\temp\doc.docx
New-OfficeWordText -Document $Document -Text 'This is a test, very big test ', 'and this should be bold' -Bold $null, $true -Underline Single, $null
New-OfficeWordText -Document $Document -Text 'This is a test, \t\t very big test ', 'and this should be bold' -Bold $null, $true -Underline Single, $null
New-OfficeWordText -Document $Document -Text "This is a test, `t`t very big test ", 'and this should be bold' -Bold $null, $true -Underline Single, $null
$p2 = New-OfficeWordText -Document $Document -Bold 1, 0 -Underline 0, 1 -Text "We are ", "`t`tJohn Doe and Jane Doe`t`t" -ReturnObject
$p3 = New-OfficeWordText -Document $Document -Bold 1, 0 -Underline $null, Single -Text "We are ", "`t`tJohn Doe and Jane Doe`t`t" -ReturnObject
Save-OfficeWord -Document $Document -Show |
How to underline spaces or tabs? When I set
The result is
But I'd like to have
The text was updated successfully, but these errors were encountered: