I have created a template in word, basically, a word document with some [Something] to be replaced in a C# console application, and i'm trying to set a spécific character as a line feed.
Indeed, in word, according of the line feed character you are using, it will allow or not the page break into a table cell.
To be very clear, when you have clicked the display all char button, you can see all the special characters.
The one i want to add is this one : good linefeed but, i tried all unicode character i found on wikipedia and i always have this kind of linefeed bad return
I use this librairy to manipulate the docx document : github.com/WordDocX/DocX
And this is the code i have used in the "Examples" project of the DocX github librairy :
private static void ModifyTemplate()
{
// Loading the template
using (DocX document = DocX.Load("D:\\DocX-master\\Examples\\docs\\Template.docx"))
{
var sb = new StringBuilder("");
sb.Clear();
sb.AppendLine("bla bla bla bla bla bla bla bla.");
//Testing all the unicode codes i found here : https://en.wikipedia.org/wiki/Newline
sb.Append("u000D\u000D").Append("u000A\u000A").Append("u0085\u0085").Append("u000B\u000B").Append("u000C\u000C").Append("u2028\u2028").Append("u2029\u2029");
sb.AppendLine("AppendLine");
document.ReplaceText("[test]", sb.ToString());
//Testing with a different encoding
String test = Encoding.UTF8.GetString(Encoding.ASCII.GetBytes(sb.ToString()));
document.ReplaceText("[test]", test);
#region Saving the modified template on the disk
// Save all changes to this document.
document.SaveAs(@"docs\Result.docx");
#endregion
}// Release this document from memory.
}
My word template is basically a new docx with the texte [Test] and [Test2] inside
The result with this code :
Sorry i can't post images... so i can't show you the final result... but trust me, none of this unicode seems to produce the right result
To conclude, no matter what unicode code i use, it is impossible to have the good return char
What unicode code i should use? Or what encoding trick should i use to have the linefeed char i seek ?
Seems like you need to use "InsertParagraph
"
Paragraph p1 = document.InsertParagraph();
p1.Append("New Para 1");
Paragraph p2 = document.InsertParagraph();
p2.Append("New Para 2");
Paragraph p3 = document.InsertParagraph();
p3.Append("New Para 3");