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

SetFontFamily pattern for every document created #45

Closed
eliseudev opened this issue Oct 14, 2022 · 4 comments
Closed

SetFontFamily pattern for every document created #45

eliseudev opened this issue Oct 14, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@eliseudev
Copy link

Would you have to set a default FontFamily for every document, without having to add to each paragraph you create?

follows the example in the image.

image

@PrzemyslawKlys
Copy link
Member

PrzemyslawKlys commented Oct 14, 2022

It's not exposed now, but I would suggest doing this differently. Just work without setting font family and then once everything is done just loop thru all paragraphs

foreach (var paragraph in document.Paragraphs) {
    paragraph.SetFontFamily(...).SetFontSize(10)
}

You will fix this in 3 lines. I'll keep this open, as it should be possible to define default font/style.

@PrzemyslawKlys PrzemyslawKlys added the enhancement New feature or request label Oct 14, 2022
@eliseudev
Copy link
Author

Não está exposto agora, mas eu sugeriria fazer isso de forma diferente. Basta trabalhar sem definir a família font e, em seguida, uma vez que tudo é feito apenas loop th através de todos os parágrafos

foreach (var paragraph in document.Paragraphs) {
    paragraph.SetFontFamily(...).SetFontSize(10)
}

Você vai consertar isso em 3 linhas. Vou manter isso aberto, pois deve ser possível definir fonte padrão/style.

Thanks, I thought I had a generic method, but so too solves my problem.

@PrzemyslawKlys
Copy link
Member

I will add native way to do it in next release:

@PrzemyslawKlys
Copy link
Member

PR was merged

      public static void Example_BasicWordWithDefaultStyleChange(string folderPath, bool openWord) {
            Console.WriteLine("[*] Creating standard document with different default style");
            string filePath = System.IO.Path.Combine(folderPath, "BasicWordWithDefaultStyleChange.docx");
            using (WordDocument document = WordDocument.Create(filePath)) {
                document.Settings.FontSize = 30;
                document.Settings.FontFamily = "Calibri Light";
                document.Settings.Language = "pl-PL";

                var paragraph1 = document.AddParagraph("To jest po polsku");

                var paragraph2 = document.AddParagraph("Adding paragraph1 with some text and pressing ENTER");
                paragraph2.FontSize = 15;
                paragraph2.FontFamily = "Courier New";

                document.Save(openWord);
            }
        }

Should be available in next version

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