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

How to add paragraph without pagebreak? #216

Closed
charliestel opened this issue Mar 13, 2024 · 4 comments
Closed

How to add paragraph without pagebreak? #216

charliestel opened this issue Mar 13, 2024 · 4 comments

Comments

@charliestel
Copy link

charliestel commented Mar 13, 2024

Hi, can anyone tell me how to insert multiple paragraphs into a document without a new line break?
Why I need this: to format parts of lines.

For example:

p1 = new WordParagraph()
p1.Text = "Some"

p2 = p1.AddParagraphAfterSelf(); // Maybe I chose the wrong way?
p2.Text = "Text"
p2.Bold = true;

p3 = p2.AddParagraphAfterSelf()
p3.Text = "on the same line."
p3.Italic = true;
p3.ColorHex = "#f3f3f3f3";
@PrzemyslawKlys
Copy link
Member

p1.AddText(xxx).AddText(xxx) as far as i know

@charliestel
Copy link
Author

p1.AddText(xxx).AddText(xxx) as far as i know

AddText method is just concating text in current paragraph. But i wanna split text areas and having separated styles for them

@PrzemyslawKlys
Copy link
Member

So in OfficeIMO the paragraph is actually a Run. That means when you do AddText it creates a run, but this is a WordParagraph. Using AddParagraph forces it to do one Paragraph, with one Run kinda.

So if you want you can do

p1 = p1.AddText("xxx")
p1.Italic = true;
p1 = p1.AddText("xxx2)
p1.Italic = false;

and it will give you what you want. You can also save them to seaprate variables. OfficeIMO has only a single concept of WordParagraph trying to simplify the OpenXML model. 

@PrzemyslawKlys
Copy link
Member

For example

 var paragraph = document.AddParagraph("Adding paragraph with some text with special chars to check if FontFamily works correctly for those");

                paragraph.Color = SixLabors.ImageSharp.Color.Red;

                // this is only a test of setting FontFamily per paragraph. Please use document.Settings.FontFamily to set it per document.
                paragraph = document.AddParagraph("Wszedł kot do domu, gdzie były różne buty. ");
                paragraph.FontFamily = "Courier New";
                paragraph = paragraph.AddText("Chodził tak sobie i chodził, i się nachodził. ");
                paragraph.FontFamily = "Courier New";
                paragraph = paragraph.AddText("A potem jeszcze pochodził, i wąchał. A wszystko to nagrało życie. ");
                paragraph.FontFamily = "Courier New";

Look at the examples project - there are plenty of examples showing things

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