Is it possible to output html strings to csv.
Trying to export data from a cms to csv and to Excel. Each piece of html could include commas and anything really.
EG. <p class="myclass">This is an example, of the string</p>
The import is broken in Excel, the wrong data appears in the wrong columns altough the first few rows are correct.
I want to achieve this sort of format
col1,col2,col3
"1","<p class="myclass">This is an example, of the string</p>","and more html here"
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.
foreach (var prop in offer.Properties) //.Where(x=>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);
UPDATE: 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.
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 class="myclass">This is an example, of the string</p>
to what exacly? Give Us some example od output! – Mechanizews.LoadFromDataTable(someTable);
orws.LoadFromCollection(someList);
. Apart from that, trying to put HTML in a CSV is simply asking for trouble. You can't simply replace or encode all quotes, as the HTML snippet may already contain encoded strings. You could try using some really unexpected characters as column and line separators, eg ¤ and ¶ – Teniafuge