'OpenXML C# Excel SharedStringItem Inserting new line
I'm using OpenXML to create a formatted block of text with Excel. The requirement is to use predefined styles (set by an admin) to format a block of text. I've managed to accomplish everything by using the SharedStringItem and the Run class. However I'm having trouble figuring out how to preserving the carriage returns "\r\n".
The following code is not producing the run on a new line
private static void NewRun(SharedStringItem sharedString, bool isBullet = false)
{
var newRun = new Run();
newRun.Text = new Text { Text = Environment.NewLine };
sharedString.Append(newRun);
}
private static void NewRun(SharedStringItem sharedString, bool isBullet = false)
{
var newRun = new Run();
newRun.Text = new Text { Text = "\r\n" };
sharedString.Append(newRun);
}
When the above methods are used I can see the SharedStringItem.InnerText is using the new lines however appear to be lost in the markup.
<x:t>Our corporate and commercial litigation
Have I just stumbled upon a limitation of the SharedStringItem or am I missing something?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

