I need to show an address on DOCX invoice, we generate to our customers using OOXML SDK. Invoice's header has a table with a cell, allocated to the address.
The address has been kept in SQL as a separate column per each line and on the invoice each line shall be presented as a new one, e.g.
Science Museum, London
Exhibition Rd, Kensington
London
SW7 2DD
Sadly, no matter what I try, I always get it all in one line, so the invoice can be seen as
Science Museum, London Exhibition Rd, Kensington
London SW7 2DD
For that purpose I have a StringBuilder (tried a simple string as well to no avail)
StringBuilder headerAddress = new StringBuilder();
which I populate. I have tried many ways to force the break line, e.g. \r\n, Environment.NewLine or + (char)13 + (char)10. None has worked. Below is my code's sample. For ease of reading I have shown all three options I have tried at once, yet in my real code I have tried all three separately.
Can one advise what I am doing wrong, please?
protected override void OnLeaveRow()
{
if (_AccountInvAddress.AddressLine1 != "")
_parent.headerAddress.Append(_AccountInvAddress.AddressLine1.Trim() + "\r\n");
if (_AccountInvAddress.AddressLine2 != "")
_parent.headerAddress.Append(_AccountInvAddress.AddressLine2.Trim() + "\r\n");
if (_AccountInvAddress.AddressLine3 != "")
_parent.headerAddress.Append(_AccountInvAddress.AddressLine3.Trim() + Environment.NewLine);
if (_AccountInvAddress.AddressLine4 != "")
_parent.headerAddress.Append(_AccountInvAddress.AddressLine4.Trim() + Environment.NewLine);
if (_AccountInvAddress.AddressLine5 != "")
_parent.headerAddress.Append(_AccountInvAddress.AddressLine5.Trim() + (char)13 + (char)10);
if (_AccountInvAddress.AddressLine6 != "")
_parent.headerAddress.Append(_AccountInvAddress.AddressLine6.Trim() + (char)13 + (char)10);
if (_AccountInvAddress.AddressLine7 != "")
_parent.headerAddress.Append(_AccountInvAddress.AddressLine7.Trim() + (char)13 + (char)10);
}
` instead of line breaks? http://officeopenxml.com/WPtextSpecialContent-break.php – juharr Mar 06 '18 at 16:22