Skip to content

Commit

Permalink
Merge pull request Dijji#12 from halueda/patch-2
Browse files Browse the repository at this point in the history
Fix for Dijji#8
  • Loading branch information
Dijji authored May 21, 2020
2 parents 43400d1 + fa0cd28 commit 98598d8
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions XstFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ public void ExportMessageProperties(IEnumerable<Message> messages, string fileNa
var columns = dict.Keys.OrderBy(x => x).ToArray();

// And finally output the CSV file line by line
using (var sw = new System.IO.StreamWriter(fileName, false))
using (var sw = new System.IO.StreamWriter(fileName, false, /* Encoding.Default */ System.Text.Encoding.GetEncoding("utf-8") ))

{
StringBuilder sb = new StringBuilder();
bool hasValue = false;
Expand Down Expand Up @@ -501,20 +502,18 @@ private void AddCsvValue(StringBuilder sb, string value, ref bool hasValue)

if (value != null)
{
value = value.Replace("\r\n", "; ").Replace("\r", "; ").Replace("\n", "; ");
if (value.Contains(','))
// multilingual character should be quoted, so almost always quotation is necessary
// if (value.Contains(',') || value.Contains('"') || value.Contains("\n") || value.Contains("\n") )
{
// We need to quote the value, and therefore get rid of quotes in it
// Excel is also fooled by spaces after embedded commas
var val = value.Replace("\"", "'");
while (val.Contains(", "))
val = val.Replace(", ", ",");
var val = value.Replace("\"", "\"\"");
sb.Append("\"");
sb.Append(EnforceCsvValueLengthLimit(val));
sb.Append("\"");
}
else
sb.Append(EnforceCsvValueLengthLimit(value));
// else
// sb.Append(EnforceCsvValueLengthLimit(value));
}

hasValue = true;
Expand Down

0 comments on commit 98598d8

Please sign in to comment.