Skip to content
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

Open
v-bulynkin opened this issue Mar 10, 2023 · 12 comments
Open

Underline spaces/tabs #12

v-bulynkin opened this issue Mar 10, 2023 · 12 comments

Comments

@v-bulynkin
Copy link

How to underline spaces or tabs? When I set

$p2 = New-OfficeWordText -Document $doc -Bold 1,0 -Underline 0,1 -Text `
"We are ","`t`tJohn Doe and Jane Doe`t`t" -ReturnObject

The result is
изображение

But I'd like to have
изображение

@PrzemyslawKlys
Copy link
Member

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.

@v-bulynkin
Copy link
Author

Expected doc.docx

@PrzemyslawKlys
Copy link
Member

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.

image

So I need to add support for it in OfficeIMO.

Seeing how it's built

image

You can try doing:

$document.Paragraphs[1].UnderLine = ...

While when you use ReturnObject it will return a WordParagraph, it actually just returns the "last" one. So a complicated sentence like you have created probably 7 WordParagraph. Each on their own...

I only wonder if OfficeIMO will see this..., it should be it will not be aware that it's TabChar

@v-bulynkin
Copy link
Author

v-bulynkin commented Mar 10, 2023

Hmm, it means that I can underline only the whole paragraph, not a part of a string?
"We are" shouldn't be underlined.

Maybe, I can use something like non-breaking space? But how to type it in Powershell?

@v-bulynkin
Copy link
Author

v-bulynkin commented Mar 10, 2023

I found the workaround! It works when I use

$p2.Underline = 'Single'

Initially, the value of $p2.Underline was Words.

@PrzemyslawKlys
Copy link
Member

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.

@v-bulynkin
Copy link
Author

Right before Save-OfficeWord cmdlet:

# Set to underline spaces
$doc.Paragraphs |? underline |% {$_.underline = 'Single'}

@PrzemyslawKlys
Copy link
Member

I would not go and set it on all tho unless you want to underline everything.

@v-bulynkin
Copy link
Author

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.

@PrzemyslawKlys
Copy link
Member

Maybe I don't understand what you're doing. Anyways - you do you ;) If it works, it works.

@PrzemyslawKlys
Copy link
Member

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

image

I have not noticed that you used 0 and 1 instead one of many other possible values.

image

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"

image

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.

@v-bulynkin
Copy link
Author

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.
Dashed underline works, but I need Single, which doesn't.

$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

изображение

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants