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

Set font name #10

Open
v-bulynkin opened this issue Mar 8, 2023 · 5 comments
Open

Set font name #10

v-bulynkin opened this issue Mar 8, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@v-bulynkin
Copy link

How to set font of document or paragraph?

I could change font size:

$doc.Settings.FontSize = 15
# or
$paragraph.FontSize = 15

However, I can't set the font itself. The settings below don't work:

$doc.Settings.FontFamily = 'Times New Roman'
# or
$paragraph.FontFamily = 'Times New Roman'
@PrzemyslawKlys
Copy link
Member

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

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

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

$Paragraph.FontFamily = 'Arial'

Save-OfficeWord -Document $Document -Show

Works for me?

@v-bulynkin
Copy link
Author

It works only with English characters

$docFile = "C:\temp\doc.docx"
rm $docFile
$doc = New-OfficeWord -FilePath $docFile
$doc.Settings.FontFamily = 'Times New Roman'
$doc.Settings.FontSize = 11

$p1 = New-OfficeWordText -Document $doc -Bold $true -Alignment Center -Text `
'Абвг' -ReturnObject
$p1.AddBreak()
New-OfficeWordText -Document $doc -Bold $true -Paragraph $p1 -Text `
"Abcd"

Save-OfficeWord -Document $doc -Show

@PrzemyslawKlys
Copy link
Member

Then use FontFamilyHighAnsi

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

I think we don't set HighAnsi for paragraph directly which may need fixing in OfficeIMO.

@v-bulynkin
Copy link
Author

v-bulynkin commented Mar 8, 2023

FontFamilyHighAnsi works, thank you. But there is an interesting thing - spaces, numbers and everything except letters are resistant to font changing.

Default font is Arial, so I have
<Word (Times New Roman)><Space (Arial)><Word (Times New Roman)><Space (Arial)><Word (Times New Roman)> etc.

Upd: sorry, the options FontFamilyHighAnsi and FontFamily must be used simultaneously.

@PrzemyslawKlys
Copy link
Member

I will change the logic in OfficeIMO and PSWriteOffice and change the logic:

  • If you use Settings.FontFamily it will also set HighAnsi
  • If you use Settings.FontFamilyHighAnsi it will set it for HighAnsi and read HighAnsi separately

Same for Paragraph FontFamily will set both, and FontFamilyHighAnsi will just set HighAnsi. I believe this is the most common use case where both entries are the same for majority of the people and only in certain languages it will be different so they will have to ensure they run things in proper order.

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

No branches or pull requests

2 participants