swxben / docx-template-engine

A template engine for the .NET platform which takes a DOCX file and applies a data object to generate reports, do mail merges, etc.
35 stars 17 forks source link

Method to convert line breaks into markup #7

Open becdetat opened 11 years ago

becdetat commented 11 years ago

So "line 1\r\nline 2\r\nline 3" is converted to Word-compatible markup. This would be used like:

_engine.Process("in.docx", "out.docx", new {
    Address = _engine.ConvertLineBreaks("line 1\r\nline 2\r\nline 3")
});

It looks like

public string ConvertLineBreaks(string in) { return in.Replace(Environment.NewLine, "</w:t></w:r><w:r><w:br/><w:t>"); }

will work.