title: Write html strings to csv file
body: <p>Is it possible to output html strings to csv.</p>
  
  <p>Trying to export data from a cms to csv and to Excel. Each piece of html could include commas and anything really.</p>
  
  <pre><code>EG. &lt;p class="myclass"&gt;This is an example, of the string&lt;/p&gt;
  </code></pre>
  
  <p>The import is broken in Excel, the wrong data appears in the wrong columns altough the first few rows are correct.</p>
  
  <p>I want to achieve this sort of format</p>
  
  <pre><code>col1,col2,col3
  "1","&lt;p class="myclass"&gt;This is an example, of the string&lt;/p&gt;","and more html here"
  </code></pre>
  
  <p>I have tried this sort of thing - I am iterating a content item in the cms and outputting each property as seperate csv data value enclosed in quotes and separated by commas.</p>
  
  <pre><code>foreach (var prop in offer.Properties) //.Where(x=&gt;x.Alias != "Id"))
  {
  
      var @propValue = prop.Value.ToString().Replace("\"", "'");
  
      // Append comma except last
      sb.Append(prop != offer.Properties.Last()
          ? "\"" + propValue + "\","
          : "\"" + propValue + "\"");
  }
  sb.Append(Environment.NewLine);
  </code></pre>
  
  <p><strong>UPDATE:</strong> 
  In truth this task proved fraught with difficulty.  The original goal was to quickly export a set of nodes and their properties from the Umbraco CMS to an Excel file.  I learned that csv is probably not the right format for this type of data which is all based on data stored in xml and including encoded html snippets.</p>
  
  <p>In our case the best way to achieve what we wanted was to output the exported data as an html table which Excel understands and which maintains an editor friendly format rather than encoded html snippets.</p>