Note that there are some explanatory texts on larger screens.

plurals
  1. POExporting data to excel in C# with comma delimited issue
    primarykey
    data
    text
    <p>The problem is not the exporting itself but how it separates the fields with comma's and I have commas in the fields. All works fine until it gets to the last field where the string contains a comma, it delimits it</p> <p>My code:</p> <pre><code> foreach (var item in jobSortedReportData) { sb.Append("\"").Append(item.Title).Append("\",\"").Append(item.Total).Append("\",\"").Append(item.Week6).Append("\",\"").Append(item.Week5).Append("\",\"").Append(item.Week4).Append("\",\"").Append(item.Week3).Append("\",\"").Append(item.Week2).Append("\",").Append(item.Week1).Append(Environment.NewLine); } byte[] textBytes2 = Encoding.UTF8.GetBytes(sb.ToString()); </code></pre> <p>the output this generates:</p> <pre><code> Number 1 Job Search 0 **Bathroom Fitter, Plumbing: 100** Carpenter, Joinery: 99 Carpenter, Joinery: 81 Carpenter, Joinery: 209 Electrician, Domestic Electrical: 495 **Bathroom Fitter Plumbing: 112** Number 2 Job Search 0 Carpenter, Joinery: 97 Bathroom Fitter, Plumbing: 99 Bathroom Fitter, Plumbing: 79 Bathroom Fitter, Plumbing: 150 Bathroom Fitter, Plumbing: 453 Builder Window Installation: 75 Number 3 Job Search 0 Builder, Window Installation: 85 Building Contractor, Kitchen Fitting: 97 Plumber, Bathroom Fitting: 51 Builder, Window Installation: 134 Heating Engineer, Gas Installation: 451 Bathroom Fitter Bathroom Fitting: 74 </code></pre> <p>raw view:</p> <pre><code>"Number 3 Job Search","0","Builder, Window Installation: 85","Building Contractor, Kitchen Fitting: 97","Plumber, Bathroom Fitting: 51","Builder, Window Installation: 134","Heating Engineer, Gas Installation: 451",Bathroom Fitter, Bathroom Fitting: 74 "Number 1 Tradesmen Search","0","Painter &amp; Decorator: 316","Painter &amp; Decorator: 229","Painter &amp; Decorator: 146","Builder: 324","TV Aerials &amp; In-home Entertainment Installer: 1378",Electrician: 247 "Number 2 Tradesmen Search","0","Builder: 171","Builder: 191","Plumber: 114","Plumber: 295","Builder: 551",Builder: 205 "Number 3 Tradesmen Search","0","Plumber: 123","Plumber: 160","Builder: 108","Painter &amp; Decorator: 231","Domestic Electrical: 495",Painter &amp; Decorator: 160 </code></pre> <p>In the above, <code>"Bathroom Fitter, Plumbing: 100"</code> in the 3rd column contains a <code>,</code> but it keeps the whole string in one excel field. When it comes to the last column <code>"Bathroom Fitter Plumbing: 112"</code> there is a <code>,</code> in the string between <em>Fitter</em> and <em>Plumbing</em>, so what happens now is this , is seen as a separator so when in excel it split this in <strong>TWO</strong> cells, thus I have <code>Bathroom Fitter</code> in one cell and <code>Plumbing:112</code> in the next. The whole string should be in ONE cell. It does this only on the last column?? please help me correct this.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload